|
|
|
@ -3,6 +3,7 @@ namespace DAL;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use metier\Article;
|
|
|
|
|
use metier\Flux;
|
|
|
|
|
use PDO;
|
|
|
|
|
class ArticleGateway
|
|
|
|
|
{
|
|
|
|
@ -21,20 +22,16 @@ class ArticleGateway
|
|
|
|
|
*/
|
|
|
|
|
public function getAllArticles():array
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$query = 'SELECT * FROM Article;';
|
|
|
|
|
$this->con->executeQuery($query, array());
|
|
|
|
|
return $this->con->getResults();
|
|
|
|
|
}catch (\PDOException $e){
|
|
|
|
|
throw new Exception("PDO error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function addArticle(Article $article){
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
$query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);';
|
|
|
|
|
$this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR),
|
|
|
|
|
':title' => array($article->getTitle(), PDO::PARAM_STR),
|
|
|
|
@ -44,17 +41,17 @@ class ArticleGateway
|
|
|
|
|
':link' => array($article->getLink(), PDO::PARAM_STR),
|
|
|
|
|
':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR),
|
|
|
|
|
':provenance' => array($article->getProvenance(), PDO::PARAM_INT)));
|
|
|
|
|
}catch (\PDOException $e){
|
|
|
|
|
throw new Exception("PDO error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeAllArticleForParser(){
|
|
|
|
|
try{
|
|
|
|
|
$query = 'DELETE FROM Article;';
|
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
|
}catch(\PDOException $p){
|
|
|
|
|
throw new Exception("Data is not delete.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function findArticleByFlux(int $flux){
|
|
|
|
|
$query = 'SELECT * FROM Article WHERE provenance = :flux;';
|
|
|
|
|
$this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_INT)));
|
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
|
return $this->con->getResults();
|
|
|
|
|
}
|
|
|
|
|
}
|