Skip to content
Extraits de code Groupes Projets
Valider 7010d328 rédigé par begue2018's avatar begue2018
Parcourir les fichiers

Code de la classe utilisateur

parent 57f5ac4d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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
);
......@@ -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
......@@ -6,4 +6,6 @@
* Time: 08:35
*/
function connect().
?>
\ No newline at end of file
......@@ -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
......
<?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;
}
}
<?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;
}
}
<?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;
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter