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.
108 lines
2.9 KiB
108 lines
2.9 KiB
<?php
|
|
namespace Model;
|
|
use Entity\SourceEntity;
|
|
use Enum\TypeSourceEnum;
|
|
|
|
class SourceModel extends Model
|
|
{
|
|
|
|
public function createSource(string $title, string $date, TypeSourceEnum $type) : bool
|
|
{
|
|
$q = new SourceEntity(-1,$title, $date, TypeSourceEnum::Movie/*$type*/);
|
|
|
|
return $this -> gateway -> create($q);
|
|
|
|
}
|
|
|
|
public function getSourceById(int $id_source) : ?SourceEntity
|
|
{
|
|
$res = $this -> gateway -> findById($id_source);
|
|
|
|
if ($res)
|
|
return new sourceEntity(
|
|
$res[0]["id_source"],
|
|
$res[0]["title"],
|
|
$res[0]["dates"],
|
|
TypeSourceEnum::Movie//from($res[0]["type"])
|
|
);
|
|
return null;
|
|
}
|
|
|
|
public function getSourceByTitle(string $title) : ?SourceEntity
|
|
{
|
|
$res = $this->gateway->findByTitle($title);
|
|
if ($res)
|
|
return new sourceEntity(
|
|
$res[0]["id_source"],
|
|
$res[0]["title"],
|
|
$res[0]["dates"],
|
|
TypeSourceEnum::Movie//from($res[0]["type"])
|
|
);
|
|
return null;
|
|
}
|
|
|
|
public function getSourceByDate(string $date) : array
|
|
{
|
|
$res = $this->gateway->findByDate($date);
|
|
$src = [];
|
|
foreach ($res as $sources) {
|
|
$src[] = new sourceEntity(
|
|
$sources["id_source"],
|
|
$sources["title"],
|
|
$sources["dates"],
|
|
TypeSourceEnum::from($sources["type"])
|
|
);
|
|
}
|
|
return $src;
|
|
}
|
|
|
|
public function getSourceByType(TypeSourceEnum $type) : array
|
|
{
|
|
$res = $this->gateway->findByType($type);
|
|
$src = [];
|
|
foreach ($res as $sources) {
|
|
$src[] = new sourceEntity(
|
|
$sources["id_source"],
|
|
$sources["title"],
|
|
$sources["dates"],
|
|
TypeSourceEnum::from($sources["type"])
|
|
);
|
|
}
|
|
return $src;
|
|
}
|
|
|
|
public function getAllSources() : array
|
|
{
|
|
$res = $this -> gateway -> findAll();
|
|
$src = [];
|
|
foreach ($res as $sources) {
|
|
$src[] = new sourceEntity(
|
|
$sources["id_source"],
|
|
$sources["title"],
|
|
$sources["dates"],
|
|
TypeSourceEnum::from($sources["type"])
|
|
);
|
|
}
|
|
return $src;
|
|
}
|
|
|
|
public function deleteSource(int $id_source) : bool
|
|
{
|
|
return $this -> gateway -> delete($id_source);
|
|
}
|
|
|
|
public function updateSource(int $id_source, string $title, string $date) : bool
|
|
{
|
|
$q = $this -> getSourceById($id_source);
|
|
|
|
if ($q){
|
|
$q -> setTitle($title);
|
|
$q -> setDate($date);
|
|
return $this -> gateway -> update($q);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|