From 4cb7ea559f43fc27b797b35b49e24510f2ae63d0 Mon Sep 17 00:00:00 2001 From: thchazot1 Date: Wed, 23 Nov 2022 16:51:17 +0100 Subject: [PATCH] =?UTF-8?q?le=20moment=20ou=20j'ai=20cass=C3=A9=20le=20aut?= =?UTF-8?q?o=20increment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connection.php | 33 ++++++++++++++++++++++ index.php | 40 +++++++++++++++++++++++++++ liste.php | 62 ++++++++++++++++++++++++++++++++++++++++++ page.html | 2 +- tache.php | 55 +++++++++++++++++++++++++++++++++++++ tacheGateway.php | 47 ++++++++++++++++++++++++++++++++ user.php | 38 ++++++++++++++++++++++++++ utilisateurGateway.php | 42 ++++++++++++++++++++++++++++ 8 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 connection.php create mode 100644 index.php create mode 100644 liste.php create mode 100644 tache.php create mode 100644 tacheGateway.php create mode 100644 user.php create mode 100644 utilisateurGateway.php diff --git a/connection.php b/connection.php new file mode 100644 index 0000000..e0725ab --- /dev/null +++ b/connection.php @@ -0,0 +1,33 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} + + +/** * @param string $query + * @param array $parameters * + * @return bool Returns `true` on success, `false` otherwise +*/ + +public function executeQuery(string $query, array $parameters = []) : bool{ + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + + return $this->stmt->execute(); +} + +public function getResults() : array { + return $this->stmt->fetchall(); + +} +} + +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..54961ad --- /dev/null +++ b/index.php @@ -0,0 +1,40 @@ + + + + +insert($t, 1); + + $tabTache=$gateway->getTacheFromIdList(1); + foreach($tabTache as $tache){ + print($tache); + echo "
"; + } +} +catch( PDOException $Exception ) { + echo 'erreur'; + echo $Exception->getMessage(); +} +?> + + + \ No newline at end of file diff --git a/liste.php b/liste.php new file mode 100644 index 0000000..949b959 --- /dev/null +++ b/liste.php @@ -0,0 +1,62 @@ +id=$id; + $this->name=$name; + $this->$creator=$creator; + $this->$taches=$taches; + } + + public function __toString() + { + return $this->id . " " . $this->name . " " . $this->creator; + } + + public function getId(){ + return $id; + } + + public function getName(){ + return $name; + } + + public function getCreator(){ + return $creator; + } + + public function getTaches(){ + return $taches; + } + + public function setName(string $name){ + $this->name=$name; + } + + public function setPrivate(boolean $private){ + $this->private=$private; + } + + public function setCreator(string $creator){ + $this->creator=$creator; + } + + public function setTaches(array $taches){ + $this->taches=$taches; + } + +} + +?> \ No newline at end of file diff --git a/page.html b/page.html index 086cdcf..02262eb 100644 --- a/page.html +++ b/page.html @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/tache.php b/tache.php new file mode 100644 index 0000000..a9a429a --- /dev/null +++ b/tache.php @@ -0,0 +1,55 @@ +id=$id; + $this->name=$name; + $this->content=$content; + $this->completed=$completed; + } + + public function __toString() + { + return $this->id . " " . $this->name . " " . $this->content . " " . $this->completed; + } + + + public function getId(){ + return $this->id; + } + + public function getName(){ + return $this->name; + } + + public function getContent(){ + return $this->content; + } + + public function getCompleted(){ + return $this->completed; + } + + public function setName(string $name){ + $this->name=$name; + } + + public function setContent(string $content){ + $this->content=$content; + } + + public function setCompleted(bool $completed){ + $this->completed=$completed; + } +} + +?> \ No newline at end of file diff --git a/tacheGateway.php b/tacheGateway.php new file mode 100644 index 0000000..a3acd3c --- /dev/null +++ b/tacheGateway.php @@ -0,0 +1,47 @@ +con = $con; + } + + public function insert(Tache $t, int $idList): void{ + $query = "INSERT INTO Tache VALUES (null, :name, :content, :completed, :idList)"; + $this->con->executeQuery($query, array(':name' => array($t->getName(), PDO::PARAM_STR), ':content' => array($t->getContent(), PDO::PARAM_STR), ':completed' => array($t->getCompleted(), PDO::PARAM_BOOL), ':idList' => array($idList, PDO::PARAM_INT))); + } + + public function getTacheFromIdList(int $id): array{ + $tabTaches=[]; + $query = "SELECT * FROM Tache t where idListe=:id"; + $this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); + $results=$this->con->getResults(); + foreach ($results as $row) { + $tabTaches[]=new Tache($row['id'], $row['name'], $row['content'], $row['completed']); + } + return $tabTaches; + } + +/* + public function findByName(string $name): array{ + if (!empty($name)){ + $query = "SELECT * FROM Tache WHERE name=:name"; + $this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR))); + + $results=$con->getResults(); + foreach ($results as $row ) { + $tabTaches[]=new Tache($row['id'], $row['name'], $row['content']); + } + return $tabTaches; + } + } +*/ +} + +?> \ No newline at end of file diff --git a/user.php b/user.php new file mode 100644 index 0000000..af208ae --- /dev/null +++ b/user.php @@ -0,0 +1,38 @@ +id=$id; + $this->username=$username; + $this->password=$password; + } + + public function __toString() + { + return $this->id . " " . $this->username . " " . $this->contenu; + } + + + public function getId(){ + return $id; + } + + public function getUsername(){ + return $username; + } + + public function getPassword(){ + return $password; + } + + public function setUsername(string $username){ + $this->username=$username; + } +} + +?> \ No newline at end of file diff --git a/utilisateurGateway.php b/utilisateurGateway.php new file mode 100644 index 0000000..8fa6a81 --- /dev/null +++ b/utilisateurGateway.php @@ -0,0 +1,42 @@ + + + +test + +insert($t); + + $query = "SELECT * FROM Tache"; + + $con->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); + $results=$con->getResults(); + Foreach($results as $row){ + echo ($row['id']. " | ". $row['name'] . " | ". $row['content'] . "

"); + } +} +catch( PDOException $Exception ) { + echo 'erreur'; + echo $Exception->getMessage(); +} +?*/ +?> + + +