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; } }