toutes les gateways

main
thchazot1 2 years ago
parent 342337af68
commit b2fb03908a

@ -6,22 +6,40 @@
require_once("connection.php");
require_once('tacheGateway.php');
require_once('userGateway.php');
require_once("listeGateway.php");
require_once('user.php');
//A CHANGER
$user= 'thchazot1';
$pass='achanger';
$dsn='mysql:host=localhost;dbname=dbthchazot1';
$id=468;
$name='LALALILALOU';
$id=1;
$name='Argent';
$content='Argent, Encore de l\'argent';
try{
$con=new Connection($dsn,$user,$pass);
$t=new Tache($id, $name, $content, FALSE);
$gateway=new TacheGateway($con);
$u=new User(1, "test", "mdp");
$t=new Tache($id, $name, $content, true);
$t1=new Tache(478, "TEST", $content, false);
$l=new Liste(6, "test", false, null, array($t, $t1));
$tacheGateway=new TacheGateway($con);
$userGateway=new UserGateway($con);
$listeGateway=new ListeGateway($con);
$listeGateway->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);
@ -29,6 +47,7 @@ try{
print($tache);
echo "<br>";
}
*/
}
catch( PDOException $Exception ) {
echo 'erreur';

@ -6,18 +6,19 @@ require_once('tache.php');
class Liste
{
private $id;
private $name;
private $private;
private $creator;
private $taches;
private int $id;
private string $name;
private bool $private;
private ?User $creator;
private array $taches;
function __construct( int $id, string $name, boolean $private, User $creator, array $taches)
function __construct(int $id, string $name, bool $private, ?User $creator, array $taches)
{
$this->id=$id;
$this->name=$name;
$this->$creator=$creator;
$this->$taches=$taches;
$this->private=$private;
$this->creator=$creator;
$this->taches=$taches;
}
public function __toString()
@ -26,30 +27,34 @@ class Liste
}
public function getId(){
return $id;
return $this->id;
}
public function getName(){
return $name;
return $this->name;
}
public function getCreator(){
return $creator;
return $this->creator;
}
public function getPrivate(){
return $this->private;
}
public function getTaches(){
return $taches;
return $this->taches;
}
public function setName(string $name){
$this->name=$name;
}
public function setPrivate(boolean $private){
public function setPrivate(bool $private){
$this->private=$private;
}
public function setCreator(string $creator){
public function setCreator(?User $creator){
$this->creator=$creator;
}

@ -0,0 +1,68 @@
<?php
require_once('liste.php');
class ListeGateway
{
private $con;
public function __construct(Connection $con){
$this->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;
}
}
*/
}
?>

@ -4,10 +4,10 @@ require_once('user.php');
class Tache
{
private $id;
private $name;
private $content;
private $completed;
private int $id;
private string $name;
private string $content;
private bool $completed;
function __construct( int $id, string $name, string $content, bool $completed)
{

@ -17,6 +17,16 @@ class TacheGateway
$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";
@ -28,6 +38,13 @@ class TacheGateway
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)){

@ -1,6 +1,6 @@
<?php
class Utilisateur
class User
{
private $id;
private $username;
@ -14,25 +14,29 @@ class Utilisateur
public function __toString()
{
return $this->id . " " . $this->username . " " . $this->contenu;
return $this->id . " " . $this->username;
}
public function getId(){
return $id;
return $this->id;
}
public function getUsername(){
return $username;
return $this->username;
}
public function getPassword(){
return $password;
return $this->password;
}
public function setUsername(string $username){
$this->username=$username;
}
public function setPassword(string $password){
$this->password=$password;
}
}
?>

@ -0,0 +1,64 @@
<?php
require_once('user.php');
class UserGateway
{
private $con;
public function __construct(Connection $con){
$this->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;
}
*/
}
?>

@ -1,42 +0,0 @@
<html>
<body>
test
<?php
require_once("connection.php");
require_once('tacheGateway.php');
require_once('tache.php');
/*
//A CHANGER
$user= 'thchazot1';
$pass='achanger';
$dsn='mysql:host=localhost;dbname=dbthchazot1';
try{
$con=new Connection($dsn,$user,$pass);
$t=new Tache($id, $name, $content);
$gateway=new TacheGateway($con);
$gateway->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'] . "<br><br>");
}
}
catch( PDOException $Exception ) {
echo 'erreur';
echo $Exception->getMessage();
}
?*/
?>
</body>
</html>
Loading…
Cancel
Save