From 156d749bfb3a8637ad88aba82087fdb7247ca5f6 Mon Sep 17 00:00:00 2001 From: maxime point Date: Mon, 13 Nov 2023 14:02:03 +0100 Subject: [PATCH 1/6] :construction: ajout du parser manque partie sur l'image --- fluxRSS/metier/Flux.php | 9 +++++++++ fluxRSS/model/Parser.php | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 fluxRSS/model/Parser.php diff --git a/fluxRSS/metier/Flux.php b/fluxRSS/metier/Flux.php index d68b0ba..a167fbe 100755 --- a/fluxRSS/metier/Flux.php +++ b/fluxRSS/metier/Flux.php @@ -4,6 +4,7 @@ namespace metier; class Flux { + private string $id; private string $flux; /** @@ -21,4 +22,12 @@ class Flux { $this->flux = $flux; } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } } \ No newline at end of file diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php new file mode 100644 index 0000000..26b69a2 --- /dev/null +++ b/fluxRSS/model/Parser.php @@ -0,0 +1,42 @@ +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()); + } + return $tabArticle; + } + + public function parseAll(Flux $fluxes){ + foreach ($fluxes as $flux){ + $tabArticles[] =$this->parseArticles($flux); + } + return $tabArticles; + } +} \ No newline at end of file -- 2.36.3 From e45c8c1ecaf11d8eacdce4ffca3e1db89b5d11b0 Mon Sep 17 00:00:00 2001 From: point Date: Mon, 13 Nov 2023 18:30:42 +0100 Subject: [PATCH 2/6] ajout fonction de tous les articles parser --- fluxRSS/model/Parser.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php index 26b69a2..3d82bc7 100644 --- a/fluxRSS/model/Parser.php +++ b/fluxRSS/model/Parser.php @@ -2,12 +2,21 @@ namespace model; +use DAL\ArticleGateway; +use DAL\FluxGateway; use DOMDocument; use metier\Article; use metier\Flux; class Parser { + private FluxGateway $fluxGateway; + private ArticleGateway $articleGateway; + + public function __construct(FluxGateway $fluxGateway, ArticleGateway $articleGateway){ + $this->fluxGateway = $fluxGateway; + $this->articleGateway = $articleGateway; + } public function parseArticles(Flux $flux){ $dom = new DOMDocument(); $tabArticle = array(); @@ -33,10 +42,20 @@ class Parser return $tabArticle; } - public function parseAll(Flux $fluxes){ + public function parseAll($fluxes){ foreach ($fluxes as $flux){ $tabArticles[] =$this->parseArticles($flux); } return $tabArticles; } + + public function addAllArticles(){ + $allFlux = $this->fluxGateway->findAllFlux(); + + $allArticles = $this->parseAll($allFlux); + + foreach ($allArticles as $article) { + $this->articleGateway->addArticle($article); + } + } } \ No newline at end of file -- 2.36.3 From a48a445c939f5fd0c4c8270131f29ef300884cc1 Mon Sep 17 00:00:00 2001 From: point Date: Mon, 13 Nov 2023 18:31:33 +0100 Subject: [PATCH 3/6] ajout fonction de tous les articles parser + modif composer.json --- fluxRSS/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fluxRSS/composer.json b/fluxRSS/composer.json index 6eaab9c..21ca7cc 100644 --- a/fluxRSS/composer.json +++ b/fluxRSS/composer.json @@ -1,7 +1,8 @@ { "require": { "twig/twig": "^3.0", - "ext-pdo": "*" + "ext-pdo": "*", + "ext-dom": "*" }, "autoload": { "psr-4": { -- 2.36.3 From 0f2cba021dcab2b3f8e8d0ee480739d1d9a5fca1 Mon Sep 17 00:00:00 2001 From: point Date: Tue, 14 Nov 2023 09:00:04 +0100 Subject: [PATCH 4/6] =?UTF-8?q?:construction:=20ajout=20partie=20image=20d?= =?UTF-8?q?e=20Parser.php=20et=20modif=20gestion=20erreur=20Controleur.php?= =?UTF-8?q?=20=C3=A0=20tester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fluxRSS/controleur/Controleur.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fluxRSS/controleur/Controleur.php b/fluxRSS/controleur/Controleur.php index e5907f7..ca4318e 100644 --- a/fluxRSS/controleur/Controleur.php +++ b/fluxRSS/controleur/Controleur.php @@ -37,9 +37,10 @@ class Controleur } } catch (\PDOException $e) { //si erreur BD, pas le cas ici - $dVueEreur[] = 'Erreur inattendue!!! '; + $dVueEreur[] = 'Erreur PDO : ' . $e->getMessage(); + echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } catch (\Exception $e2) { - $dVueEreur[] = 'Erreur inattendue!!! '; + $dVueEreur[] = 'Erreur : ' . $e2->getMessage(); echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } @@ -69,9 +70,11 @@ class Controleur $age = $_POST['txtAge']; \config\Validation::val_form($nom, $age, $dVueEreur); + /* $model = new \metier\Simplemodel(); $data = $model->get_data(); - + */ + $dVue = [ 'nom' => $nom, 'age' => $age, -- 2.36.3 From 040f274f3f80d9e9dafb30d1d4b0f904d2facc98 Mon Sep 17 00:00:00 2001 From: point Date: Tue, 14 Nov 2023 09:29:48 +0100 Subject: [PATCH 5/6] =?UTF-8?q?:construction:=20ajout=20partie=20image=20d?= =?UTF-8?q?e=20Parser.php=20=C3=A0=20tester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fluxRSS/model/Parser.php | 45 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php index 3d82bc7..6e61732 100644 --- a/fluxRSS/model/Parser.php +++ b/fluxRSS/model/Parser.php @@ -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); -- 2.36.3 From d63486a4ad71ad2db8e8b98f744918ca6a15db9e Mon Sep 17 00:00:00 2001 From: point Date: Tue, 14 Nov 2023 09:48:20 +0100 Subject: [PATCH 6/6] modif FluxGateway --- fluxRSS/DAL/FluxGateway.php | 1 + 1 file changed, 1 insertion(+) diff --git a/fluxRSS/DAL/FluxGateway.php b/fluxRSS/DAL/FluxGateway.php index 8e6e41b..57ca526 100755 --- a/fluxRSS/DAL/FluxGateway.php +++ b/fluxRSS/DAL/FluxGateway.php @@ -2,6 +2,7 @@ namespace DAL; +use metier\Flux; use PDO; class FluxGateway -- 2.36.3