diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php index 89e43ec..2bb7da7 100755 --- a/fluxRSS/src/DAL/ArticleGateway.php +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -35,10 +35,10 @@ class ArticleGateway */ 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), + $query = 'INSERT INTO Article VALUES (:id,:title,datePub,:description,:guid,:link,:mediaContent,:provenance);'; + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_INT), ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(), PDO::PARAM_STR), + ':datePub' => 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), diff --git a/fluxRSS/src/DAL/Connection.php b/fluxRSS/src/DAL/Connection.php index dc58de2..00952cf 100755 --- a/fluxRSS/src/DAL/Connection.php +++ b/fluxRSS/src/DAL/Connection.php @@ -42,10 +42,17 @@ class Connection extends PDO foreach ($parameters as $name => $value) { $this->stmt->bindValue($name, $value[0], $value[1]); } + if($this->stmt->execute()){ + return true; + } else { + $error = $this->stmt->errorInfo(); + throw new Exception("PDO error: ".$error[2]); + } - return $this->stmt->execute(); }catch (\PDOException $e){ - throw new Exception("PDO error"); + throw new Exception("PDO error: ".$e->getMessage()); + }catch (\Error $r){ + throw new Error("executionQuery not possible : ".$r->getMessage()); } } diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 9344801..35b61a9 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -41,7 +41,10 @@ class FluxGateway try{ $query = 'SELECT * FROM Flux;'; $this->con->executeQuery($query); - return $this->con->getResults(); + $results = $this->con->getResults(); + print("result findAllFlux Gateway"); + var_dump($results); + return $results; }catch (\PDOException $e){ throw new \Exception("PDO error"); } diff --git a/fluxRSS/src/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php index 1419941..a98e6e0 100755 --- a/fluxRSS/src/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -11,11 +11,9 @@ require 'AltoRouter.php'; class FrontControleur { public function __construct(){ -<<<<<<< HEAD:fluxRSS/src/controleur/FrontControleur.php $routeur = new AltoRouter(); -======= global $twig; @@ -52,7 +50,6 @@ class FrontControleur echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } } ->>>>>>> pre-master:fluxRSS/controleur/FrontControleur.php } diff --git a/fluxRSS/src/metier/Article.php b/fluxRSS/src/metier/Article.php index 809c3d1..d4a2cf0 100755 --- a/fluxRSS/src/metier/Article.php +++ b/fluxRSS/src/metier/Article.php @@ -4,26 +4,34 @@ namespace metier; class Article { - private string $id; + private int $id; private string $title; private string $date; private string $description; private string $guid; private string $link; private string $mediaContent; - private string $provenance; + private int $provenance; /** - * @param string $id + * @param int $id * @param string $title * @param string $date * @param string $description * @param string $guid * @param string $link * @param string $mediaContent - * @param string $provenance + * @param int $provenance */ - public function __construct(string $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, string $provenance) + public function __construct( + int $id, + string $title, + string $date, + string $description, + string $guid, + string $link, + string $mediaContent, + int $provenance) { $this->id = $id; $this->title = $title; diff --git a/fluxRSS/src/metier/Flux.php b/fluxRSS/src/metier/Flux.php index 627d9f2..70a07ad 100755 --- a/fluxRSS/src/metier/Flux.php +++ b/fluxRSS/src/metier/Flux.php @@ -32,4 +32,12 @@ class Flux { $this->flux = $flux; } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } } \ No newline at end of file diff --git a/fluxRSS/src/model/FluxModel.php b/fluxRSS/src/model/FluxModel.php index 5116de9..1cf740e 100755 --- a/fluxRSS/src/model/FluxModel.php +++ b/fluxRSS/src/model/FluxModel.php @@ -10,7 +10,7 @@ require_once "config/config.php"; class FluxModel { public function FindAllFlux(){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findAllFlux(); @@ -21,7 +21,7 @@ class FluxModel } public function addFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = $this->findFlux($flux); if ($data == array()) { $gateway->addFlux($flux); @@ -29,26 +29,26 @@ class FluxModel } public function addFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->addFlux($newFlux); return $newFlux; } public function removeFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $gateway->removeFlux($flux); } public function removeFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->removeFlux($newFlux); return $newFlux; } public function findFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFlux($flux); @@ -59,7 +59,7 @@ class FluxModel } public function findFluxBySrc(string $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFluxBySrc($flux); diff --git a/fluxRSS/src/model/Parser.php b/fluxRSS/src/model/Parser.php index 70f8b95..722a06a 100755 --- a/fluxRSS/src/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -21,26 +21,44 @@ class Parser } public function parseArticles(Flux $flux): array { + print("debut parseArticles******************
"); $dom = new DOMDocument(); + print("creation du dom
"); $tabArticle = array(); if ($dom->load($flux->getFlux())){ $items = $dom->getElementsByTagName('item'); - + print("après avoir getElementByTagName
"); + var_dump($items); foreach ($items as $item) { $title = $item->getElementsByTagName('title')[0]->nodeValue; + print("le titre
"); + var_dump($title); $date = $item->getElementsByTagName('pubDate')[0]->nodeValue; + print("la date
"); + var_dump($date); $guid = $item->getElementsByTagName('guid')[0]->nodeValue; $link = $item->getElementsByTagName('link')[0]->nodeValue; $description = $item->getElementsByTagName('description')[0]->nodeValue; - $media = $item->getElementsByTagName('media:content'); + print("media :
"); + var_dump($media); $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()); + $tabArticle[] = new Article( + (int)null, + $title, + $date, + $description, + $guid, + $link, + ($mediaUrl !== null) ? (string)$mediaUrl : '', + $flux->getId()); + print("Tableau de l'article"); + var_dump($tabArticle); } return $tabArticle; } else { @@ -55,10 +73,16 @@ class Parser */ public function parseAll($fluxes){ $tabArticles = []; + print("debut parseAll
"); foreach ($fluxes as $flux){ - var_dump($flux); - $tabArticles[] =$this->parseArticles($flux); + $fluxx = new Flux($flux[0],$flux[1]); + print("flux de parseAll
"); + var_dump($fluxx); + $tabArticles[] = $this->parseArticles($fluxx); + print("fin parsqeAll
"); + } + var_dump($tabArticles); return $tabArticles; } @@ -71,16 +95,20 @@ class Parser $this->articleGateway->removeAllArticleForParser(); $allItemFlux = $this->fluxGateway->findAllFlux(); - var_dump($allItemFlux); foreach ($allItemFlux as $ItemFlux){ $tabFluxes[] = $ItemFlux[1]; - } - $allArticles = $this->parseAll($tabFluxes); - var_dump($allArticles); - foreach ($allArticles as $article) { - $this->articleGateway->addArticle($article); } - return $allArticles; + print("tableau de flux
"); + var_dump($tabFluxes); + + $allTabArticles = $this->parseAll($allItemFlux); + + foreach ($allTabArticles as $tabArticle) { + foreach ($tabArticle as $item) { + $this->articleGateway->addArticle($item); + } + + } } }