From 00257a2ba4e09520880d3a947c189b4f7b41817a Mon Sep 17 00:00:00 2001 From: Johan LACHENAL Date: Tue, 22 Nov 2022 11:13:52 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20factory=20pour=20les=20cla?= =?UTF-8?q?sses=20m=C3=A9tiers=20Enigme=20et=20Partie,=20la=20Factory=20d'?= =?UTF-8?q?=20Enigme=20est=20souvent=20utilis=C3=A9e=20pour=20cr=C3=A9er?= =?UTF-8?q?=20des=20parties=20et=20la=20factory=20de=20partie=20sera=20uti?= =?UTF-8?q?le=20pour=20faire=20l'=20historique=20des=20parties=20plus=20ta?= =?UTF-8?q?rd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/EnigmeGateway.php | 27 +++++++++++++++++---------- WEB/Controller/PartieGateway.php | 3 +++ WEB/Factory/EnigmeFactory.php | 12 ++++++++++++ WEB/Factory/PartieFactory.php | 12 ++++++++++++ WEB/Model/Enigme.php | 12 +++++++++++- WEB/Model/Partie.php | 4 +++- 6 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 WEB/Factory/EnigmeFactory.php create mode 100644 WEB/Factory/PartieFactory.php diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 2f2eb05d..a4d543a8 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -1,5 +1,5 @@ con->executeQuery($query, array( ':id' => array($enigme->getIdEnigme(), PDO::PARAM_STR), ':admin' => array($enigme->getAdmin(), PDO::PARAM_STR), @@ -32,7 +32,8 @@ class EnigmeGateway ':rappel' => array($enigme->getRappel(), PDO::PARAM_STR), ':solution' => array($enigme->getSolution(), PDO::PARAM_STR), ':test' => array($enigme->getTest(), PDO::PARAM_STR), - ':tempsDeResolution' => array($enigme->getTempsDeResolution(), PDO::PARAM_INT) + ':tempsDeResolution' => array($enigme->getTempsDeResolution(), PDO::PARAM_INT), + ':points' => array($enigme->getPoints(), PDO::PARAM_INT) )); } @@ -44,19 +45,24 @@ class EnigmeGateway )); } - public function findById(string $idEnigme) + public function findById(string $idEnigme) : array { $query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme"; $this->con->executequery($query,array( ':idEnigme' => array($idEnigme,PDO::PARAM_STR) )); $results=$this->con->getResults(); - $tabEnigme=array(); - foreach ($results as $row) - { - $tabEnigme[]= new Enigme(row['id'],row['admin'],row['enonce'],row['aide'],row['rappel'],row['solution'],row['test'],row['tempsDeResolution']); - } - return $tabEnigme; + $tabEnigme=EnigmeFactory::create($results); + return $tabEnigme; + } + + public function findByTempsDeResolution() : array + { + $query = "SELECT * FROM Enigme ORDER BY tempsDeResolution"; + $this->con->executequery($query); + $results = $this->con->getResults(); + $tabEnigme=EnigmeFactory::create($results); + return $tabEnigme; } public function showAll(): void @@ -72,6 +78,7 @@ class EnigmeGateway echo $row['rappel'] . '
'; echo $row['solution'] . '
'; echo $row['test'] . '
'; + echo $row['points'] . '
'; } } } diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 7d35c6ff..afb471df 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -1,4 +1,6 @@ con = $con; } public function insert(Partie $partie){ + $query= "INSERT INTO Game VALUES (:idPartie)"; $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), PDO::PARAM_STR))); } diff --git a/WEB/Factory/EnigmeFactory.php b/WEB/Factory/EnigmeFactory.php new file mode 100644 index 00000000..b84fdcae --- /dev/null +++ b/WEB/Factory/EnigmeFactory.php @@ -0,0 +1,12 @@ +idEnigme=$idEnigme; $this->enonce=$enonce; $this->solution=$solution; @@ -37,6 +38,7 @@ class Enigme $this->aide=NULL; $this->rappel=NULL; $this->admin=$admin; + $this->points=$points; } public function __constructSolo(string $idEnigme, string $enonce, string $aide, string $rappel, string $solution, string $test,string $admin){ @@ -177,4 +179,12 @@ class Enigme { $this->tempsDeResolution = $tempsDeResolution; } + public function getPoints(): int + { + return $this->points; + } + public function setPoints(int $points): void + { + $this->points = $points; + } } \ No newline at end of file diff --git a/WEB/Model/Partie.php b/WEB/Model/Partie.php index 705b2b5b..d0113343 100644 --- a/WEB/Model/Partie.php +++ b/WEB/Model/Partie.php @@ -1,11 +1,12 @@ idPartie = $idPartie; $this->datePartie = getdate(); + $listeEnigme = []; } /**