parent
c61553cfce
commit
0836c9c616
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
class CharacterEntity
|
||||
{
|
||||
|
||||
private int $id_character;
|
||||
|
||||
private string $name;
|
||||
|
||||
private string $img_path;
|
||||
|
||||
public function __construct(int $id_character, string $name, string $img_path)
|
||||
{
|
||||
$this -> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
require_once "../public/script/Connection.php";
|
||||
require_once "characterEntity.php";
|
||||
|
||||
class CharacterGateway
|
||||
{
|
||||
|
||||
private Connection $co;
|
||||
|
||||
public function __construct(Connection $co)
|
||||
{
|
||||
$this -> 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)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
require_once "characterEntity.php";
|
||||
require_once "characterGateway.php";
|
||||
|
||||
class CharacterModel
|
||||
{
|
||||
|
||||
private characterGateway $gateway;
|
||||
|
||||
public function __construct(characterGateway $gateway)
|
||||
{
|
||||
$this -> 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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class CommentaryEntity {
|
||||
|
||||
private int $id_comment;
|
||||
private string $comment;
|
||||
private string $date;
|
||||
|
||||
|
||||
public function __construct(int $id_comment, string $comment, string $date) {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?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))
|
||||
);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
require_once "commentaryEntity.php";
|
||||
require_once "commentaryGateway.php";
|
||||
class CommentaryModel {
|
||||
|
||||
private commentaryGateway $gw;
|
||||
|
||||
function __construct(commentaryGateway $gw) {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class SourceEntity
|
||||
{
|
||||
private int $id_source;
|
||||
|
||||
private string $title;
|
||||
|
||||
private string $date;
|
||||
|
||||
public function __construct(int $id_source, string $title, string $date)
|
||||
{
|
||||
$this -> 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 ;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
require_once "../public/script/Connection.php";
|
||||
require_once "sourceEntity.php";
|
||||
class SourceGateway {
|
||||
|
||||
private Connection $co;
|
||||
|
||||
public function __construct(Connection $co)
|
||||
{
|
||||
$this -> 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)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
require_once "sourceEntity.php";
|
||||
require_once "sourceGateway.php";
|
||||
|
||||
class SourceModel
|
||||
{
|
||||
|
||||
private sourceGateway $gateway;
|
||||
|
||||
public function __construct(SourceGateway $gateway)
|
||||
{
|
||||
$this -> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue