parent
cfe515bdaf
commit
05952b9434
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once "../public/script/Connection.php";
|
||||
require_once "commentaryEntity.php";
|
||||
|
||||
class CommentaryGateway {
|
||||
private Connection $co ;
|
||||
public function __construct(Connection $co) {
|
||||
$this->co = $co;
|
||||
}
|
||||
|
||||
public function create(commentaryEntity $c) :bool {
|
||||
|
||||
$query="INSERT INTO Commentary VALUES(:id_comment, :comment , :date)";
|
||||
|
||||
return $this -> co -> executeQuery($query, array(
|
||||
"id_comment" => array($c->getIdComment(), PDO::PARAM_INT),
|
||||
"comment" => array($c->getComment(), PDO::PARAM_STR),
|
||||
"date" => array($c->getDate(), PDO::PARAM_STR)));
|
||||
}
|
||||
|
||||
public function findById(int $id) : ?commentaryEntity {
|
||||
|
||||
$query="SELECT * FROM Commentary WHERE id_comment = :id_comment";
|
||||
|
||||
$this -> co -> executeQuery($query, array("id_comment" => $id));
|
||||
$res = $this -> co -> getResults();
|
||||
if($res)
|
||||
return new commentaryEntity($res["id_comment"], $res["comment"], $res["date"]);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function findAll() : array {
|
||||
$query="SELECT * FROM Commentary";
|
||||
$this -> co -> executeQuery($query);
|
||||
$res = $this -> co -> getResults();
|
||||
|
||||
$comments = [];
|
||||
foreach ($res as $comment) {
|
||||
|
||||
$comments[] = new commentaryEntity(
|
||||
$comment["id_comment"],
|
||||
$comment["comment"],
|
||||
$comment["date"]
|
||||
);
|
||||
}
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
public function delete(int $id) : bool {
|
||||
$query="DELETE FROM Commentary WHERE id_comment = :id_comment";
|
||||
return $this -> co -> executeQuery($query, array("id_comment" => $id));
|
||||
|
||||
}
|
||||
|
||||
public function update(commentaryEntity $c) : bool {
|
||||
|
||||
$query="UPDATE Commentary SET comment = :comment WHERE id_comment = :id_comment";
|
||||
|
||||
return $this -> co -> executeQuery($query, array(
|
||||
"comment" => array($c->getComment(),PDO::PARAM_STR),
|
||||
"id_comment" => array($c->getIdComment(),PDO::PARAM_INT))
|
||||
);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue