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.
51 lines
1.5 KiB
51 lines
1.5 KiB
<?php
|
|
namespace DAL;
|
|
|
|
use Exception;
|
|
use metier\Article;
|
|
use PDO;
|
|
class ArticleGateway
|
|
{
|
|
private $con;
|
|
|
|
/**
|
|
* @param $con
|
|
*/
|
|
public function __construct($con)
|
|
{
|
|
$this->con = $con;
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
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),
|
|
':date' => array($article->getDate(), PDO::PARAM_STR),
|
|
':description' => array($article->getDescription(), PDO::PARAM_STR),
|
|
':guid' => array($article->getGuid(), PDO::PARAM_STR),
|
|
':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");
|
|
}
|
|
}
|
|
} |