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