generated from Templates_CodeFirst/templateHtmlCss
parent
342337af68
commit
b2fb03908a
@ -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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
@ -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…
Reference in new issue