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.
62 lines
1.4 KiB
62 lines
1.4 KiB
<?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;
|
|
}
|
|
|
|
}
|
|
|