diff --git a/README.md b/README.md deleted file mode 100644 index 6b599c0..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -[![Build Status](https://codefirst.iut.uca.fr/api/badges/lilian.breton/PHP_Project/status.svg)](https://codefirst.iut.uca.fr/lilian.breton/PHP_Project) - -# PHP_Project - -A simple template for a web page in html css. \ No newline at end of file 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..b0c8622 --- /dev/null +++ b/index.php @@ -0,0 +1,59 @@ + + + + +insert($l); + +/* + $tacheGateway->delete($t); + $user=$userGateway->insert(new User(1, "test", "mdp")); + $user=$userGateway->findByNamePassword("test", "mdp"); + print($user); + $gateway->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..11d4c37 --- /dev/null +++ b/liste.php @@ -0,0 +1,67 @@ +id=$id; + $this->name=$name; + $this->private=$private; + $this->creator=$creator; + $this->taches=$taches; + } + + public function __toString() + { + return $this->id . " " . $this->name . " " . $this->creator; + } + + public function getId(){ + return $this->id; + } + + public function getName(){ + return $this->name; + } + + public function getCreator(){ + return $this->creator; + } + + public function getPrivate(){ + return $this->private; + } + + public function getTaches(){ + return $this->taches; + } + + public function setName(string $name){ + $this->name=$name; + } + + public function setPrivate(bool $private){ + $this->private=$private; + } + + public function setCreator(?User $creator){ + $this->creator=$creator; + } + + public function setTaches(array $taches){ + $this->taches=$taches; + } + +} + +?> \ No newline at end of file diff --git a/listeGateway.php b/listeGateway.php new file mode 100644 index 0000000..81a2346 --- /dev/null +++ b/listeGateway.php @@ -0,0 +1,68 @@ +con = $con; + } + + public function insert(Liste $l): void{ + $tacheGateway=new TacheGateway($this->con); + foreach($l->getTaches() as $taches){ + $tacheGateway->insert($taches, $this->getLastId()+1); + } + if ($l->getCreator()==null){ + $query = "INSERT INTO Liste VALUES (null, :name, :private, null)"; + $this->con->executeQuery($query, array(':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL))); + } + else{ + $query = "INSERT INTO Liste VALUES (null, :name, :private, :creator)"; + $this->con->executeQuery($query, array(':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL), ':creator' => array($l->getCreator()->getId(), PDO::PARAM_STR))); + } + } + + public function delete(Liste $l): void{ + $tacheGateway=new TacheGateway($this->con); + foreach($l->getTaches() as $taches){ + $tacheGateway->delete($taches); + } + + $query = "DELETE FROM Liste where id=:id"; + $this->con->executeQuery($query, array(':id' => array($l->getId(), PDO::PARAM_INT))); + } + + public function update(Liste $l): void{ + $query = "UPDATE Liste SET name=:name, private=:private WHERE id=:id"; + $this->con->executeQuery($query, array(':id' => array($l->getId(), PDO::PARAM_INT), ':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL))); + } + + public function getLastId(): int{ + $query = "SELECT max(id) as oldId FROM Liste"; + $this->con->executeQuery($query, array()); + $results=$this->con->getResults(); + return $results[0]['oldId']; + } + +/* + 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/mycoolstyle.css b/mycoolstyle.css deleted file mode 100644 index 92d69df..0000000 --- a/mycoolstyle.css +++ /dev/null @@ -1,32 +0,0 @@ -body { - padding-left: 11em; - font-family: Georgia, 'Georgia', "Times New Roman", - Times, serif; - color: darksalmon; - background-color: rgb(39, 39, 84) } - ul.navbar { - list-style-type: none; - padding: 0; - margin: 0; - position: absolute; - top: 2em; - left: 1em; - width: 9em } - h1 { - font-family: Helvetica, Geneva, Arial, - SunSans-Regular, sans-serif } - ul.navbar li { - background: white; - margin: 0.5em 0; - padding: 0.3em; - border-right: 1em solid darksalmon } - ul.navbar a { - text-decoration: none } - a:link { - color: blue } - a:visited { - color: darkblue } - address { - margin-top: 1em; - padding-top: 1em; - border-top: thin dotted } \ No newline at end of file diff --git a/page.html b/page.html deleted file mode 100644 index 086cdcf..0000000 --- a/page.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - PHP_Project - One incredible styled html page - - - - - - - - - -

PHP_Project is my first page, and it has got style!

- -

Welcome on this template html/css project - -

Very simple, some links, some menu... make it your own -… - -

I have nothing more to say - - -

Template made in 2022
- with Code#0 Code#0 -
- - - \ No newline at end of file diff --git a/tache.php b/tache.php new file mode 100644 index 0000000..e0a9e44 --- /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..9a253da --- /dev/null +++ b/tacheGateway.php @@ -0,0 +1,64 @@ +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 delete(Tache $t): void{ + $query = "DELETE FROM Tache where id=:id"; + $this->con->executeQuery($query, array(':id' => array($t->getId(), PDO::PARAM_INT))); + } + + public function update(Tache $t): void{ + $query = "UPDATE Tache SET name=:name, content=:content, completed=:completed WHERE id=:id"; + $this->con->executeQuery($query, array(':id' => array($t->getId(), PDO::PARAM_INT), ':name' => array($t->getName(), PDO::PARAM_STR), ':content' => array($t->getContent(), PDO::PARAM_STR), ':completed' => array($t->getCompleted(), PDO::PARAM_BOOL))); + } + + 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 getLastId(): int{ + $query = "SELECT max(id) as oldId FROM Tache"; + $this->con->executeQuery($query, array()); + $results=$this->con->getResults(); + return $results[0]['oldId']; + } + +/* + 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..4eb6e1d --- /dev/null +++ b/user.php @@ -0,0 +1,42 @@ +id=$id; + $this->username=$username; + $this->password=$password; + } + + public function __toString() + { + return $this->id . " " . $this->username; + } + + + public function getId(){ + return $this->id; + } + + public function getUsername(){ + return $this->username; + } + + public function getPassword(){ + return $this->password; + } + + public function setUsername(string $username){ + $this->username=$username; + } + + public function setPassword(string $password){ + $this->password=$password; + } +} + +?> \ No newline at end of file diff --git a/userGateway.php b/userGateway.php new file mode 100644 index 0000000..67eba8e --- /dev/null +++ b/userGateway.php @@ -0,0 +1,64 @@ +con = $con; + } + + public function insert(User $u): void{ + $query = "INSERT INTO Utilisateur VALUES (null, :username, :password)"; + $this->con->executeQuery($query, array(':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR))); + } + + public function delete(User $u): void{ + $query = "DELETE FROM Utilisateur where id=:id"; + $this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT))); + } + + public function update(User $u): void{ + $query = "UPDATE Utilisateur SET username=:username, password=:password WHERE id=:id"; + $this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT), ':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR))); + } + + public function findByNamePassword(string $username, string $password): ?User{ + if (!empty($username) && !empty($password)){ + $query = "SELECT * FROM Utilisateur WHERE username=:username AND password=:password"; + $this->con->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR), ':password' => array($password, PDO::PARAM_STR))); + $results=$this->con->getResults(); + if (!empty($results)){ + $user=new User($results[0]['id'], $results[0]['username'], $results[0]['password']); + return $user; + } + } + return null; + } + + public function getLastId(): int{ + $query = "SELECT max(id) as oldId FROM User"; + $this->con->executeQuery($query, array()); + $results=$this->con->getResults(); + return $results[0]['oldId']; + } + +/* + 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; + } + + +*/ +} + +?> \ No newline at end of file