parser fixed, there's a connection problem to load articles into database

feature/article
Roxane ROSSETTO 1 year ago
parent 4e99917917
commit 12913ba1e7

@ -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),

@ -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());
}
}

@ -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");
}

@ -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
}

@ -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;

@ -32,4 +32,12 @@ class Flux
{
$this->flux = $flux;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
}

@ -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);

@ -21,26 +21,44 @@ class Parser
}
public function parseArticles(Flux $flux): array
{
print("debut parseArticles******************</br>");
$dom = new DOMDocument();
print("creation du dom</br>");
$tabArticle = array();
if ($dom->load($flux->getFlux())){
$items = $dom->getElementsByTagName('item');
print("après avoir getElementByTagName</br>");
var_dump($items);
foreach ($items as $item) {
$title = $item->getElementsByTagName('title')[0]->nodeValue;
print("le titre </br>");
var_dump($title);
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
print("la date </br>");
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 : </br>");
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</br>");
foreach ($fluxes as $flux){
var_dump($flux);
$tabArticles[] =$this->parseArticles($flux);
$fluxx = new Flux($flux[0],$flux[1]);
print("flux de parseAll</br>");
var_dump($fluxx);
$tabArticles[] = $this->parseArticles($fluxx);
print("fin parsqeAll</br>");
}
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</br>");
var_dump($tabFluxes);
$allTabArticles = $this->parseAll($allItemFlux);
foreach ($allTabArticles as $tabArticle) {
foreach ($tabArticle as $item) {
$this->articleGateway->addArticle($item);
}
}
}
}

Loading…
Cancel
Save