parser and order by date fonctionne avec la date

feature/merging_branch
maxime.point2 1 year ago
parent bb971a6959
commit 06c440591e

@ -22,7 +22,7 @@ class ArticleGateway
*/ */
public function getAllArticles():array public function getAllArticles():array
{ {
$query = 'SELECT * FROM Article;'; $query = 'SELECT * FROM Article ORDER BY datePub DESC;';
$this->con->executeQuery($query, array()); $this->con->executeQuery($query, array());
return $this->con->getResults(); return $this->con->getResults();
} }
@ -31,7 +31,7 @@ class ArticleGateway
* @throws Exception * @throws Exception
*/ */
public function addArticle(Article $article){ public function addArticle(Article $article){
$query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; $query = "INSERT INTO Article VALUES (:id,:title,STR_TO_DATE(:datePub, '%d/%m/%y %H:%i'),:description,:guid,:link,:mediaContent,:provenance);";
$this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR),
':title' => array($article->getTitle(), PDO::PARAM_STR), ':title' => array($article->getTitle(), PDO::PARAM_STR),
':datePub' => array($article->getDate(), PDO::PARAM_STR), ':datePub' => array($article->getDate(), PDO::PARAM_STR),

@ -5,6 +5,7 @@ namespace model;
use DAL\ArticleGateway; use DAL\ArticleGateway;
use DAL\Connection; use DAL\Connection;
use DAL\FluxGateway; use DAL\FluxGateway;
use DateTime;
use DOMDocument; use DOMDocument;
use Exception; use Exception;
use metier\Article; use metier\Article;
@ -37,10 +38,12 @@ class Parser
$mediaUrl = $media->item(0)->getAttribute('url'); $mediaUrl = $media->item(0)->getAttribute('url');
} }
$dateTime = new DateTime($date);
$tabArticle[] = new Article( $tabArticle[] = new Article(
(int)null, (int)null,
$title, $title,
$date, $dateTime->format('d/m/y H:i') . '',
$description, $description,
$guid, $guid,
$link, $link,
@ -78,11 +81,11 @@ class Parser
$allItemFlux = $this->fluxGateway->findAllFlux(); $allItemFlux = $this->fluxGateway->findAllFlux();
foreach ($allItemFlux as $ItemFlux){ foreach ($allItemFlux as $ItemFlux){
$tabFluxes[] = $ItemFlux[1]; $tabFluxes[] = new Flux(intval($ItemFlux['id']), $ItemFlux['flux']);
} }
$allTabArticles = $this->parseAll($allItemFlux);
foreach ($allTabArticles as $tabArticle) { foreach ($tabFluxes as $flux) {
$tabArticle = $this->parseArticles($flux);
foreach ($tabArticle as $item) { foreach ($tabArticle as $item) {
$this->articleGateway->addArticle($item); $this->articleGateway->addArticle($item);
} }

@ -10,5 +10,6 @@ require '../../vendor/autoload.php';
$gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
$gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
$pars = new Parser( $gwFl,$gwArt); $pars = new Parser( $gwFl,$gwArt);
$pars->addAllArticles();;
var_dump($pars); var_dump($pars);
Loading…
Cancel
Save