You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.0 KiB
107 lines
3.0 KiB
<?php
|
|
namespace Gateway;
|
|
use Enum\TypeSourceEnum;
|
|
use Entity\SourceEntity;
|
|
use PDO;
|
|
|
|
class SourceGateway extends Gateway{
|
|
|
|
public function create(sourceEntity $s) : bool
|
|
{
|
|
$query = "
|
|
INSERT INTO Source
|
|
VALUES( :title, :date)
|
|
";
|
|
|
|
return $this -> co -> executeQuery($query, [
|
|
"title" => array($s->getTitle(), PDO::PARAM_STR),
|
|
"date" => array($s->getDate(), PDO::PARAM_STR),
|
|
"type" => array($s->getType(), PDO::PARAM_STR)
|
|
]);
|
|
}
|
|
|
|
public function findById(int $id) : array
|
|
{
|
|
$query = "SELECT * FROM Source WHERE id_source = :id";
|
|
|
|
$this -> co -> executeQuery($query, array("id_source" => array($id, PDO::PARAM_INT)));
|
|
return $res = $this -> co -> getResults();
|
|
}
|
|
|
|
public function findByTitle(string $t) : array
|
|
{
|
|
$query = "SELECT * FROM Source WHERE title = :t";
|
|
|
|
$this -> co -> executeQuery($query, ["t" => array($t, PDO::PARAM_STR)]);
|
|
return $res = $this -> co -> getResults();
|
|
|
|
// if ($res)
|
|
// return new sourceEntity(
|
|
// $res["id_source"],
|
|
// $res["title"],
|
|
// $res["date"]
|
|
// );
|
|
// return null;
|
|
}
|
|
|
|
public function findByDate(string $d) : array
|
|
{
|
|
$query = "SELECT * FROM Source WHERE dates = :d";
|
|
|
|
$this -> co -> executeQuery($query, ["d" => array($d, PDO::PARAM_STR)]);
|
|
return $this -> co -> getResults();
|
|
}
|
|
|
|
/*
|
|
public function findByType(TypeSourceEnum $type) : array
|
|
{
|
|
$query = "SELECT * FROM Source WHERE type = :t";
|
|
|
|
$this -> co -> executeQuery($query, ["t" => array($type, PDO::PARAM_STR)]);
|
|
return $this -> co -> getResults();
|
|
}
|
|
*/
|
|
|
|
public function findAll() : array
|
|
{
|
|
$query = "SELECT * FROM Source";
|
|
|
|
$this -> co -> executeQuery($query);
|
|
$res = $this -> co -> getResults();
|
|
|
|
$sources = [];
|
|
|
|
foreach ($res as $source) {
|
|
$sources[] = new sourceEntity(
|
|
$source["id_source"],
|
|
$source["title"],
|
|
$source["date"],
|
|
TypeSourceEnum::Movie//$res["source"]
|
|
);
|
|
}
|
|
return $sources;
|
|
}
|
|
|
|
public function delete(int $id) : bool
|
|
{
|
|
$query = "DELETE FROM Source WHERE id_source = :id_s";
|
|
|
|
$this -> co -> executeQuery($query, ["id_s" => array($id, PDO::PARAM_INT)]);
|
|
}
|
|
|
|
public function update(sourceEntity $s) : bool
|
|
{
|
|
$query = "
|
|
UPDATE Source
|
|
SET title = :t, date = :d
|
|
WHERE id_source = :id_s
|
|
";
|
|
return $this->co->executeQuery($query, [
|
|
"id_s" => array($s -> getIdSource(), PDO::PARAM_INT),
|
|
"t" => array($s -> getTitle(), PDO::PARAM_STR),
|
|
"d" => array($s -> getDate(), PDO::PARAM_STR)
|
|
]);
|
|
}
|
|
|
|
}
|