diff --git a/models/characterEntity.php b/models/characterEntity.php new file mode 100644 index 0000000..bac366e --- /dev/null +++ b/models/characterEntity.php @@ -0,0 +1,46 @@ + id_character = $id_character; + $this -> name = $name; + $this -> img_path = $img_path; + } + + public function getIdCharacter() : int + { + return $this -> id_character; + } + public function getName() : string + { + return $this -> name; + } + public function getImgPath() : string + { + return $this -> img_path; + } + + public function setIdCharacter(int $id_character) : void + { + $this -> id_character = $id_character; + } + public function setName(string $name) : void + { + $this -> name = $name; + } + public function setImgPath(string $img_path) : void + { + $this -> img_path = $img_path; + } + +} + diff --git a/models/characterGateway.php b/models/characterGateway.php new file mode 100644 index 0000000..36bf969 --- /dev/null +++ b/models/characterGateway.php @@ -0,0 +1,105 @@ + co = $co; + } + + public function create(characterEntity $c) : bool + { + $query = " + INSERT INTO Character + VALUES(:id_character, :name, :img_path) + "; + + return $this -> co -> executeQuery($query, [ + "id_character" => array($c -> getIdCharacter(), PDO::PARAM_INT), + "name" => array($c -> getName(), PDO::PARAM_STR), + "img_path" => array($c -> getImgPath(), PDO::PARAM_STR) + ]); + + } + + public function findById(int $id) : ?characterEntity + { + $query = "SELECT * FROM Character WHERE id_character = :id_c"; + + $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]); + $res = $this ->co -> getResults(); + + if($res) + return new characterEntity( + $res["id_character"], + $res["name"], + $res["img_path"] + ); + return null; + } + + public function findByName(string $name) : ?characterEntity + { + $query = "SELECT * FROM Character WHERE name = :n"; + + $this -> co -> executeQuery($query, ["n" => array($name, PDO::PARAM_STR)]); + $res = $this ->co -> getResults(); + + if($res) + return new characterEntity( + $res["id_character"], + $res["name"], + $res["img_path"] + ); + return null; + } + + public function findAll() : array + { + $query = "SELECT * FROM Character"; + + $this -> co -> executeQuery($query); + $res = $this ->co -> getResults(); + + $characters = []; + + foreach ($res as $character) + { + $characters[] = new characterEntity( + $character["id_character"], + $character["name"], + $character["img_path"] + ); + } + return $characters; + } + + public function delete(int $id) : bool + { + $query = "DELETE FROM Character WHERE id_character = :id_c"; + + return $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]); + } + + public function update(characterEntity $c) : bool + { + $query = " + UPDATE Character + SET name = :n, img_path = :i + WHERE id_character = :id_c + "; + + return $this -> co -> executeQuery($query, [ + "id_c" => array($c -> getIdCharacter(), PDO::PARAM_INT), + "name" => array($c -> getName(), PDO::PARAM_STR), + "i" => array($c -> getImgPath(), PDO::PARAM_STR) + ]); + } + +} \ No newline at end of file diff --git a/models/characterModel.php b/models/characterModel.php new file mode 100644 index 0000000..a9769b0 --- /dev/null +++ b/models/characterModel.php @@ -0,0 +1,54 @@ + gateway = $gateway; + } + + public function createCharacter(int $id_character, string $name , string $img_path) : bool + { + $q = new CharacterEntity($id_character, $name, $img_path); + + return $this -> gateway -> create($q); + } + public function getCharacterById(int $id_character) : ?CharacterEntity + { + return $this -> gateway -> findById($id_character); + } + + public function getCharacterByName(string $name) : ?CharacterEntity + { + return $this -> gateway -> findByName($name); + } + + public function getAllCharacters() : array + { + return $this -> gateway -> findAll(); + } + + public function deleteCharacter(int $id_character) : bool + { + return $this -> gateway -> delete($id_character); + } + + public function updateCharacter(int $id_character, string $name, string $img_path) : bool + { + $q = $this -> gateway -> findById($id_character); + + if($q){ + $q -> setName($name); + $q -> setImgPath($img_path); + return $this -> gateway -> update($q); + } + return false; + } + +} \ No newline at end of file diff --git a/models/commentaryEntity.php b/models/commentaryEntity.php new file mode 100644 index 0000000..ccd8f1a --- /dev/null +++ b/models/commentaryEntity.php @@ -0,0 +1,39 @@ +id_comment = $id_comment; + $this->comment = $comment; + $this->date = $date; + } + + public function getIdComment(): int { + return $this->id_comment; + } + public function getComment(): string { + return $this->comment; + } + public function getDate(): string { + return $this->date; + } + + public function setIdComment(int $id_comment): void { + $this->id_comment = $id_comment; + } + + public function setComment(string $comment): void { + $this->comment = $comment; + } + + public function setDate(string $date): void { + $this->date = $date; + } + + +} \ No newline at end of file diff --git a/models/commentaryGateway.php b/models/commentaryGateway.php new file mode 100644 index 0000000..4643478 --- /dev/null +++ b/models/commentaryGateway.php @@ -0,0 +1,68 @@ +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)) + ); + + } +} \ No newline at end of file diff --git a/models/commentaryModel.php b/models/commentaryModel.php new file mode 100644 index 0000000..c104f9b --- /dev/null +++ b/models/commentaryModel.php @@ -0,0 +1,42 @@ +gw = $gw; + } + + public function createComment(int $id_comment, string $comment, string $date): bool { + + $c = new CommentaryEntity($id_comment, $comment, $date); + return $this->gw->create($c); + } + + public function getComment(int $id_comment): ?commentaryEntity { + return $this -> gw -> findById($id_comment); + } + + public function getComments(): array { + return $this -> gw -> findAll(); + } + + public function deleteComment(int $id_comment): bool { + return $this -> gw -> delete($id_comment); + } + + public function updateComment(int $id_comment, string $comment): bool { + + $c = $this -> gw -> findById($id_comment); + + if($c){ + $c -> setComment($comment); + return $this->gw -> update($c); + } + return false; + } + +} \ No newline at end of file diff --git a/models/sourceEntity.php b/models/sourceEntity.php new file mode 100644 index 0000000..5a983d5 --- /dev/null +++ b/models/sourceEntity.php @@ -0,0 +1,47 @@ + id_source = $id_source ; + $this -> title = $title ; + $this -> date = $date; + } + + public function getIdSource() : int + { + return $this -> id_source ; + } + + public function getTitle() : string + { + return $this -> title ; + } + + public function getDate() : string + { + return $this -> date ; + } + + public function setIdSource(int $id_source) : void + { + $this -> id_source = $id_source ; + } + + public function setTitle(string $title): void{ + $this -> title = $title ; + } + + public function setDate(string $date) : void + { + $this -> date = $date ; + } + +} \ No newline at end of file diff --git a/models/sourceGateway.php b/models/sourceGateway.php new file mode 100644 index 0000000..8389526 --- /dev/null +++ b/models/sourceGateway.php @@ -0,0 +1,116 @@ + co = $co; + } + + public function create(sourceEntity $s) : bool + { + $query = " + INSERT INTO Source + VALUES(:id_source, :title, :date) + "; + + return $this -> co -> executeQuery($query, [ + "id_source" => array($s->getIdSource(), PDO::PARAM_INT), + "title" => array($s->getTitle(), PDO::PARAM_STR), + "date" => array($s->getDate(), PDO::PARAM_STR) + ]); + } + + public function findById(int $id) : ?sourceEntity + { + $query = "SELECT * FROM Source WHERE id_source = :id"; + + $this -> co -> executeQuery($query, array("id_source" => array($id, PDO::PARAM_INT))); + $res = $this -> co -> getResults(); + + if ($res) + return new sourceEntity( + $res["id_source"], + $res["title"], + $res["date"] + ); + return null; + } + + public function findByTitle(string $t) : ?sourceEntity + { + $query = "SELECT * FROM Source WHERE title = :t"; + + $this -> co -> executeQuery($query, ["title" => array($t, PDO::PARAM_STR)]); + $res = $this -> co -> getResults(); + + if ($res) + return new sourceEntity( + $res["id_source"], + $res["title"], + $res["date"] + ); + return null; + } + + public function findByDate(string $d) : ?sourceEntity + { + $query = "SELECT * FROM Source WHERE date = :d"; + + $this -> co -> executeQuery($query, ["date" => array($d, PDO::PARAM_STR)]); + $res = $this -> co -> getResults(); + + if ($res) + return new sourceEntity( + $res["id_source"], + $res["title"], + $res["date"] + ); + return null; + } + + 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"] + ); + } + 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) + ]); + } + +} \ No newline at end of file diff --git a/models/sourceModel.php b/models/sourceModel.php new file mode 100644 index 0000000..4a4a7e2 --- /dev/null +++ b/models/sourceModel.php @@ -0,0 +1,61 @@ + gateway = $gateway; + } + + public function createSource(int $id_source, string $title, string $date) : bool + { + $q = new SourceEntity($id_source , $title, $date); + + return $this -> gateway -> create($q); + } + + public function getSourceById(int $id_source) : ?SourceEntity + { + return $this -> gateway -> findById($id_source); + } + + public function getSourceByTitle(string $title) : ?SourceEntity + { + return $this -> gateway -> findByTitle($title); + } + + public function getSourceByDate(string $date) : ?SourceEntity + { + return $this -> gateway -> findByDate($date); + } + + public function getSources() : array + { + return $this -> gateway -> findAll(); + } + + 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 -> gateway -> findById($id_source); + + if ($q){ + $q -> setTitle($title); + $q -> setDate($date); + return $this -> gateway -> update($q); + } + return false; + } + +} +