|
|
|
@ -5,6 +5,7 @@ namespace model;
|
|
|
|
|
use DAL\ArticleGateway;
|
|
|
|
|
use DAL\FluxGateway;
|
|
|
|
|
use DOMDocument;
|
|
|
|
|
use Exception;
|
|
|
|
|
use metier\Article;
|
|
|
|
|
use metier\Flux;
|
|
|
|
|
|
|
|
|
@ -17,31 +18,37 @@ class Parser
|
|
|
|
|
$this->fluxGateway = $fluxGateway;
|
|
|
|
|
$this->articleGateway = $articleGateway;
|
|
|
|
|
}
|
|
|
|
|
public function parseArticles(Flux $flux){
|
|
|
|
|
public function parseArticles(Flux $flux): array
|
|
|
|
|
{
|
|
|
|
|
$dom = new DOMDocument();
|
|
|
|
|
$tabArticle = array();
|
|
|
|
|
|
|
|
|
|
$dom->load($flux->getFlux());
|
|
|
|
|
$items = $dom->getElementsByTagName('item');
|
|
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
$title = $item->getElementsByTagName('title')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
$guid = $item->getElementsByTagName('guid')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
$link = $item->getElementsByTagName('link')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
$description = $item->getElementsByTagName('description')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
//manque ajout de l'image
|
|
|
|
|
|
|
|
|
|
$tabArticle[] = new Article((int)Null, $title, $date, $description, $guid, $link, $description, $flux->getId());
|
|
|
|
|
if ($dom->load($flux->getFlux())){
|
|
|
|
|
$items = $dom->getElementsByTagName('item');
|
|
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
$title = $item->getElementsByTagName('title')[0]->nodeValue;
|
|
|
|
|
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
|
|
|
|
|
$guid = $item->getElementsByTagName('guid')[0]->nodeValue;
|
|
|
|
|
$link = $item->getElementsByTagName('link')[0]->nodeValue;
|
|
|
|
|
$description = $item->getElementsByTagName('description')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
$media = $item->getElementsByTagName('media:content');
|
|
|
|
|
$mediaUrl = null;
|
|
|
|
|
if ($media->length > 0){
|
|
|
|
|
$mediaUrl = $media->item(0)->getAttribute('url');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tabArticle[] = new Article((int)null, $title, $date, $description, $guid, $link, $mediaUrl, $flux->getId());
|
|
|
|
|
}
|
|
|
|
|
return $tabArticle;
|
|
|
|
|
} else {
|
|
|
|
|
// En cas d'erreur lors du chargement du flux RSS, lever une exception
|
|
|
|
|
throw new Exception("Erreur lors du chargement du flux RSS");
|
|
|
|
|
}
|
|
|
|
|
return $tabArticle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function parseAll($fluxes){
|
|
|
|
|
foreach ($fluxes as $flux){
|
|
|
|
|
$tabArticles[] =$this->parseArticles($flux);
|
|
|
|
|