diff --git a/controllers/ControllerAdmin.php b/controllers/ControllerAdmin.php index 79dbcf1..ceb7f9f 100644 --- a/controllers/ControllerAdmin.php +++ b/controllers/ControllerAdmin.php @@ -26,9 +26,19 @@ class controllerAdmin { $this->setNbArticlesParPage($_REQUEST["nbSourceParPage"]); break; default: - $gateway = new GatewayNews(new Connection($dsn,$user,$pass)); - $listeNews = $gateway->getNews(); - //echo $vues['listeNews']; + $gatewayNews = new GatewayNews(new Connection($dsn,$user,$pass)); + $page = 1; + if(isset($_GET['page'])){ + $page = $_GET['page']; + } + + + $listeNews = $gatewayNews->getNews($page,10); + + $pageAvant = $page - 1; + $pageApres = $page + 1; + + $pageMAX = $gatewayNews->getNbNews()/10 + 1; require($vues['listeNews']); break; } diff --git a/gateways/gatewayNews.php b/gateways/gatewayNews.php index 253baaf..67dac81 100644 --- a/gateways/gatewayNews.php +++ b/gateways/gatewayNews.php @@ -19,16 +19,24 @@ class GatewayNews ); } - public function getNews() + public function getNews($page,$nbArticlePage) { - $query = "SELECT * FROM news order by pubdate;"; - $this->con->executeQuery($query, array()); + $query = "SELECT * FROM news order by pubdate LIMIT :debut,:fin;"; + $this->con->executeQuery($query, array(':debut' => array($nbArticlePage * ($page-1),PDO::PARAM_INT), + ':fin' => array($nbArticlePage,PDO::PARAM_INT) + )); $results=$this->con->getResults(); Foreach ($results as $article){ $listeNews[] = new News($article["title"],$article['description'],$article['pubdate'],$article['link']); } return $listeNews; } + + public function getNbNews(){ + $query = "SELECT count(*) FROM news;"; + $this->con->executeQuery($query, array()); + return $this->con->getResults()[0]["count(*)"]; + } } ?> diff --git a/models/MdlAdmin.php b/models/MdlAdmin.php index f13e299..f7b4a75 100644 --- a/models/MdlAdmin.php +++ b/models/MdlAdmin.php @@ -1,8 +1,4 @@ channel->item as $item) diff --git a/update/appel.php b/update/appel.php index cee2581..e174e3b 100644 --- a/update/appel.php +++ b/update/appel.php @@ -1,6 +1,15 @@ "; } ?> + 0) { + echo '
'; + echo ""; + echo ''; + echo '
'; + } + if($pageApres <= $pageMAX){ + echo '
'; + echo ""; + echo ''; + echo '
'; + } + ?> \ No newline at end of file