diff --git a/ensiie-project/data/db.sql b/ensiie-project/data/db.sql index 0b1781ee6cebc62d379282bae3f413dc0bada7ed..2ebd10bf048a8b4e142d38881facc196cdb2a37e 100644 --- a/ensiie-project/data/db.sql +++ b/ensiie-project/data/db.sql @@ -1,4 +1,4 @@ -CREATE TABLE "user" ( +/*CREATE TABLE "user" ( id SERIAL PRIMARY KEY , firstname VARCHAR NOT NULL , lastname VARCHAR NOT NULL , @@ -16,4 +16,13 @@ INSERT INTO "user"(firstname, lastname, birthday) VALUES ('Vicky', 'Pearson', '1 INSERT INTO "user"(firstname, lastname, birthday) VALUES ('Silvia', 'Mcguire', '1971-03-02'); INSERT INTO "user"(firstname, lastname, birthday) VALUES ('Brendan', 'Pena', '1950-02-17'); INSERT INTO "user"(firstname, lastname, birthday) VALUES ('Jackie', 'Cohen', '1967-01-27'); -INSERT INTO "user"(firstname, lastname, birthday) VALUES ('Delores', 'Williamson', '1961-07-19'); \ No newline at end of file +INSERT INTO "user"(firstname, lastname, birthday) VALUES ('Delores', 'Williamson', '1961-07-19');*/ + +CREATE TABLE "user" +( + ariseID VARCHAR PRIMARY KEY, + pseudo VARCHAR, + prenom VARCHAR, + nom VARCHAR +); + diff --git a/ensiie-project/src/Model/arise_data.php b/ensiie-project/src/Model/arise_data.php index ed941ad6f9123b9f6a34ccec883dbdc06654852c..e5410d2d4946232b91777d0340051cde0c79ec4c 100644 --- a/ensiie-project/src/Model/arise_data.php +++ b/ensiie-project/src/Model/arise_data.php @@ -14,13 +14,10 @@ require_once('db_data.php'); * @return * Une variable qui ne contient que les informations qui nous intéressent */ -function getUser($ariseUser){ - $user['prenom'] = $ariseUser['...']; - $user['nom'] = $ariseUser['...']; - $user['pseudo'] = $ariseUser['...']; - $user['id'] = $ariseUser['...']; - $user['commandes'] = getCurrentCommands($user['id']); - return $user; +function getUtilisateur($utilisateurArise){ + $utilisateur = new Utilisateur($utilisateurArise['ariseID'],$utilisateurArise['prenom'],$utilisateurArise['nom'],$utilisateurArise['pseudo'],$utilisateurArise['isAdmin']); + $utilisateur->commandes = getCurrentCommands($utilisateur->ariseID); + return $utilisateur; } /** @@ -31,8 +28,7 @@ function getUser($ariseUser){ */ function getInvite(){ //TODO : Mettres ces infos dans des variables de config - $user['pseudo'] = "Invité.e"; - $user['id'] = "invite"; - $user['commandes'] = getCurrentCommands($user['id']); - return $user; + $utilisateur = new Utilisateur("invite","","","Intvité.e",FALSE); + $utilisateur->commandes = getCurrentCommands($utilisateur->ariseID); + return $utilisateur; } \ No newline at end of file diff --git a/ensiie-project/src/Model/db_connect.php b/ensiie-project/src/Model/db_connect.php index 3cf3a1d1140f2990f9b7dcd963df0fc2dde53429..b0f734e6d155ecf13ddff3f8b7df4aba09b728a0 100644 --- a/ensiie-project/src/Model/db_connect.php +++ b/ensiie-project/src/Model/db_connect.php @@ -6,4 +6,6 @@ * Time: 08:35 */ + function connect(). + ?> \ No newline at end of file diff --git a/ensiie-project/src/Model/db_data.php b/ensiie-project/src/Model/db_data.php index a276caac298017063136124f3fcefc38a353cf77..de8d23d415e5996984be2062097b9e19e990bbe1 100644 --- a/ensiie-project/src/Model/db_data.php +++ b/ensiie-project/src/Model/db_data.php @@ -27,7 +27,7 @@ function getDefaultFins{ return $heures; } -function getCurrentCommands($id){ +function getCurrentCommands($idUser){ //Get numero de l'event courrant //SI pas d'event courant : throw exception //Sinon, appel SQL, get commande with USERID=$id AND EVENTID=$eventID diff --git a/ensiie-project/src/User/User.php b/ensiie-project/src/User/User.php deleted file mode 100644 index c6fdba666cc991872c8883a4bd1239a155210039..0000000000000000000000000000000000000000 --- a/ensiie-project/src/User/User.php +++ /dev/null @@ -1,114 +0,0 @@ -<?php -namespace User; - -class User -{ - /** - * @var int - */ - private $id; - - /** - * @var string - */ - private $firstname; - - /** - * @var string - */ - private $lastname; - - /** - * @var \DateTimeInterface - */ - private $birthday; - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param int $id - * @return User - */ - public function setId($id) - { - $this->id = $id; - return $this; - } - - /** - * @return string - */ - public function getFirstname() - { - return $this->firstname; - } - - /** - * @param string $firstname - * @return User - */ - public function setFirstname($firstname) - { - $this->firstname = $firstname; - return $this; - } - - /** - * @return string - */ - public function getLastname() - { - return $this->lastname; - } - - /** - * @param string $lastname - * @return User - */ - public function setLastname($lastname) - { - $this->lastname = $lastname; - return $this; - } - - /** - * @return \DateTimeInterface - */ - public function getBirthday(): \DateTimeInterface - { - return $this->birthday; - } - - /** - * @param \DateTimeInterface $birthday - * @return User - */ - public function setBirthday(\DateTimeInterface $birthday) - { - $this->birthday = $birthday; - return $this; - } - - - /** - * @return int - * @throws \OutOfRangeException - */ - public function getAge(): int - { - $now = new \DateTime(); - - if ($now < $this->getBirthday()) { - throw new \OutOfRangeException('Birthday in the future'); - } - - return $now->diff($this->getBirthday())->y; - } -} - diff --git a/ensiie-project/src/User/UserRepository.php b/ensiie-project/src/User/UserRepository.php deleted file mode 100644 index 2d2e1dad2f3c909319263d1e27f8c6b344c3f5c6..0000000000000000000000000000000000000000 --- a/ensiie-project/src/User/UserRepository.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -namespace User; -class UserRepository -{ - /** - * @var \PDO - */ - private $connection; - - /** - * UserRepository constructor. - * @param \PDO $connection - */ - public function __construct(\PDO $connection) - { - $this->connection = $connection; - } - - public function fetchAll() - { - $rows = $this->connection->query('SELECT * FROM "user"')->fetchAll(\PDO::FETCH_OBJ); - $users = []; - foreach ($rows as $row) { - $user = new User(); - $user - ->setId($row->id) - ->setFirstname($row->firstname) - ->setLastname($row->lastname) - ->setBirthday(new \DateTimeImmutable($row->birthday)); - - $users[] = $user; - } - - return $users; - } - - -} diff --git a/ensiie-project/src/User/Utilisateur.php b/ensiie-project/src/User/Utilisateur.php new file mode 100644 index 0000000000000000000000000000000000000000..33b09e282e5a3e660818f57e550f85e7ab80e74c --- /dev/null +++ b/ensiie-project/src/User/Utilisateur.php @@ -0,0 +1,165 @@ +<?php +namespace Utilisateur; + +class Utilisateur +{ + /** + * @var string + */ + private $ariseID; + + /** + * @var string + */ + private $prenom; + + /** + * @var string + */ + private $nom; + + /** + * @var string + */ + private $pseudo; + + /** + * @var bool + */ + private $isAdmin; + + /** + * @var array<commande> + */ + private $commandes; + + + /** + * Constructeur valué + */ + public function Utilisateur($ariseID,$prenom,$nom,$pseudo,$isAdmin) + { + $this->ariseID = $ariseID; + $this->prenom = $prenom; + $this->nom = $nom; + $this->pseudo = $pseudo; + $this->isAdmin = $isAdmin; + } + + /** + * Constructeur par defaut + */ + public function Utilisateur() + { + Utilisateur("","","","",FALSE,array()); + } + + /** + * @return int + */ + public function getAriseID() + { + return $this->ariseID; + } + + /** + * @param int $ariseID + * @return Utilisateur + */ + public function setAriseID($ariseID) + { + $this->ariseID = $ariseID; + return $this; + } + + /** + * @return string + */ + public function getPrenom() + { + return $this->prenom; + } + + /** + * @param string $prenom + * @return Utilisateur + */ + public function setPrenom($prenom) + { + $this->prenom = $prenom; + return $this; + } + + /** + * @return string + */ + public function getNom() + { + return $this->nom; + } + + /** + * @param string $nom + * @return Utilisateur + */ + public function setNom($nom) + { + $this->nom = $nom; + return $this; + } + + /** + * @return string + */ + public function getPseudo() + { + return $this->pseudo; + } + + /** + * @param string $pseudo + * @return Utilisateur + */ + public function setPseudo($pseudo) + { + $this->pseudo = $pseudo; + return $this; + } + + /** + * @return string + */ + public function getIsAdmin() + { + return $this->isAdmin; + } + + /** + * @param string $isAdmin + * @return Utilisateur + */ + public function setIsAdmin($isAdmin) + { + $this->isAdmin = $isAdmin; + return $this; + } + + /** + * @return string + */ + public function getCommandes() + { + return $this->commandes; + } + + /** + * @param string $commandes + * @return Utilisateur + */ + public function setCommandes($commandes) + { + $this->commandes = $commandes; + return $this; + } +} +