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
This commit is contained in:
42
routeSQL.php
42
routeSQL.php
@@ -110,7 +110,7 @@ class routeSQL
|
||||
$postPage = false;
|
||||
$content = " <div class='paginator'>\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 .= " <div class='informationsArea'>\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 .= " </div>\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 .= " <div class='topBar'>\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 .= " </div>\n"; // End of topBar
|
||||
$content .= " <table>\n";
|
||||
$content .= " <thead>\n";
|
||||
@@ -313,13 +334,13 @@ class routeSQL
|
||||
$content .= " <th>".dgettext("domframework","Actions")."</th>\n";
|
||||
$content .= " </thead>\n";
|
||||
$content .= " <tbody>\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 .= " <tr><td colspan='$count' class='noentry'>";
|
||||
$countTitles++;
|
||||
$content .= " <tr><td colspan='$countTitles' class='noentry'>";
|
||||
$content .= dgettext("domframework","No entry available");
|
||||
$content .= "</td></tr>\n";
|
||||
}
|
||||
@@ -371,8 +392,9 @@ class routeSQL
|
||||
$content .= " <div class='bottomBar'>\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 .= " </div>\n"; // End of bottomBar
|
||||
$content .= "</div>\n";
|
||||
echo $content;
|
||||
|
||||
Reference in New Issue
Block a user