From 8bc3ce99f24dcfe04243cc264c83973246fa5054 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Wed, 11 Mar 2015 15:16:56 +0000 Subject: [PATCH] routeSQL : Add informationArea support routeSQL : BUG : correct the pager : missing last page git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2006 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- routeSQL.php | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/routeSQL.php b/routeSQL.php index 62b609c..3fc0d48 100644 --- a/routeSQL.php +++ b/routeSQL.php @@ -110,7 +110,7 @@ class routeSQL $postPage = false; $content = "
\n"; $displayedNumbers = 0; - for ($i = 1 ; $i < ($nbentries/$num) ; $i++) + for ($i = 1 ; $i < (1+$nbentries/($num)) ; $i++) { if ($i < ($page - $maxClickPaginator/2)) { @@ -203,6 +203,24 @@ class routeSQL return $content; } + /** Display the informations */ + private function informationsArea ($nbentries, $page, $num, $search) + { + $content = ""; + $content .= "
\n"; + $message = dgettext("domframework", + "Display the element {FIRST} to {LAST} on {COUNT} elements"); + $message = str_replace ("{FIRST}", 1+($num*($page-1)), $message); + if ($nbentries < ($num*$page)) + $message = str_replace ("{LAST}", $nbentries, $message); + else + $message = str_replace ("{LAST}", ($num*$page), $message); + $message = str_replace ("{COUNT}", $nbentries, $message); + $content .= $message; + $content .= "
\n"; + return $content; + } + /** Create the routes and the associated actions */ public function routes () { @@ -213,7 +231,7 @@ class routeSQL $route->redirect ("/".$this->url_prefix, ""); }); - $route->get ($this->url_prefix."(\?({p1}={v1})(&{p2}={v2}(&{p3}={v3})?)?)?", + $route->get ($this->url_prefix."(\?({p1}=({v1})?)(&{p2}=({v2})?(&{p3}=({v3})?)?)?)?", function ($p1, $v1, $p2, $v2, $p3, $v3) use ($route) { // LIST ALL THE OBJECTS OF THE TABLE @@ -252,6 +270,7 @@ class routeSQL $criteria[] = array ($column, "%$search%", "LIKE"); $datas = $this->objectDB->read ($criteria, null, null, true); } + $count = count ($datas); if ($num > 1000) $route->redirect ("/".$this->url_prefix. "?page=$page&num=1000&search=$search", ""); @@ -259,9 +278,9 @@ class routeSQL $route->redirect ("/".$this->url_prefix. "?page=1&num=$num&search=$search", ""); // Push on the last page if the values are too high - if (count ($datas) > 0 && ($page-1)*$num > count ($datas)) + if ($count > 0 && ($page-1)*$num > $count) { - $maxPage = intval(count ($datas)/$num); + $maxPage = intval ($count/$num)+1; $route->redirect ("/".$this->url_prefix. "?page=$maxPage&num=$num&search=$search", ""); } @@ -280,6 +299,7 @@ class routeSQL $content .= ".routeSQL .searchArea { border:1px solid #ddd; border-radius:5px; padding:10px; margin:3px; float:left; }\n"; $content .= ".routeSQL .searchArea form { margin:-5px; }\n"; $content .= ".routeSQL .listNumberDisplayedEntries form { margin:-3px; }\n"; + $content .= ".routeSQL .informationsArea { border:1px solid #ddd; border-radius:5px; padding:10px; margin:3px; float:left; }\n"; $content .= ".routeSQL .paginator { border:1px solid #ddd; border-radius:5px; padding:10px; margin:3px; float:left; }\n"; $content .= ".routeSQL .paginator a { border:1px solid grey; border-radius:5px; padding:3px; }\n"; $content .= ".routeSQL .paginator .selected { background-color:#04d; color:white;font-weight:bold; }\n"; @@ -300,8 +320,9 @@ class routeSQL $content .= "
\n"; $content .= $this->externalActions (); $content .= $this->listNumberDisplayedEntries ($num); - $content .= $this->paginator(count ($datas), $page, $num, $search); + $content .= $this->paginator($count, $page, $num, $search); $content .= $this->searchArea ($search); + $content .= $this->informationsArea ($count, $page, $num, $search); $content .= "
\n"; // End of topBar $content .= " \n"; $content .= " \n"; @@ -313,13 +334,13 @@ class routeSQL $content .= " \n"; $content .= " \n"; $content .= " \n"; - if (count ($datas) === 0) + if ($count === 0) { // Add one column more for actions - $count = count($titles); + $countTitles = count($titles); if ($this->displayActions) - $count++; - $content .= " \n"; } @@ -371,8 +392,9 @@ class routeSQL $content .= "
\n"; $content .= $this->externalActions (); $content .= $this->listNumberDisplayedEntries ($num); - $content .= $this->paginator(count ($datas), $page, $num, $search); + $content .= $this->paginator($count, $page, $num, $search); $content .= $this->searchArea ($search); + $content .= $this->informationsArea ($count, $page, $num, $search); $content .= "
\n"; // End of bottomBar $content .= "\n"; echo $content;
".dgettext("domframework","Actions")."
"; + $countTitles++; + $content .= "
"; $content .= dgettext("domframework","No entry available"); $content .= "