Permalink
Browse files

New paging system for glosaries.

100% compatible with Moodle's one.
Supports more options. Perhaps we could use it
sitewide.
  • Loading branch information...
1 parent a961a2b commit b9734b5d15c2eb4dd28269f67f73106c49bcf381 stronk7 committed Nov 24, 2004
Showing with 153 additions and 31 deletions.
  1. +140 −3 mod/glossary/lib.php
  2. +13 −28 mod/glossary/view.php
View
@@ -675,7 +675,6 @@ function glossary_print_entry_aliases($course, $cm, $glossary, $entry,$mode="",
}
if ($return != '') {
$return .= '</select>';
-// $return = "<table border=0 align=$align><tr><td>$return</td></tr></table>";
}
}
if ($type == 'print') {
@@ -701,11 +700,11 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$mode="",$ho
$return .= "</font> ";
- if ( ($glossary->allowcomments && !isguest()) || isteacher($glossary->course)) {
+ if ( (!empty($USER->id) && $glossary->allowcomments && !isguest()) || $isteacher) {
$return .= " <a title=\"" . get_string("addcomment","glossary") . "\" href=\"comment.php?id=$cm->id&eid=$entry->id\"><img src=\"comment.gif\" height=11 width=11 border=0></a> ";
}
- if ($isteacher or ($glossary->studentcanpost and $entry->userid == $USER->id)) {
+ if ($isteacher or (!empty($USER->id) and $glossary->studentcanpost and $entry->userid == $USER->id)) {
// only teachers can export entries so check it out
if ($isteacher and !$ismainglossary and !$importedentry) {
$mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
@@ -2048,4 +2047,142 @@ function glossary_print_rating_menu($entryid, $userid, $scale) {
choose_from_menu($scale, $entryid, $rating->rating, "$strrate...");
}
+
+function glossary_get_paging_bar($totalcount, $page, $perpage, $baseurl, $maxpageallowed=99999, $maxdisplay=20, $separator="&nbsp;", $specialtext="", $specialvalue=-1, $previousandnext = true) {
+// Returns the html code to represent any pagging bar. Paramenters are:
+//
+// Mandatory:
+// $totalcount: total number of records to be displayed
+// $page: page currently selected (0 based)
+// $perpage: number of records per page
+// $baseurl: url to link in each page, the string 'page=XX' will be added automatically.
+// Optional:
+// $maxpageallowed: maximum number of page allowed.
+// $maxdisplay: maximum number of page links to show in the bar
+// $separator: string to be used between pages in the bar
+// $specialtext: string to be showed as an special link
+// $specialvalue: value (page) to be used in the special link
+// $previousandnext: to decide if we want the previous and next links
+//
+// The function dinamically show the first and last pages, and "scroll" over pages.
+// Fully compatible with Moodle's print_paging_bar() function. Perhaps some day this
+// could replace the general one. ;-)
+
+ $code = '';
+
+ $showspecial = false;
+ $specialselected = false;
+
+ //Check if we have to show the special link
+ if (!empty($specialtext)) {
+ $showspecial = true;
+ }
+ //Check if we are with the special link selected
+ if ($showspecial && $page == $specialvalue) {
+ $specialselected = true;
+ }
+
+ //If there are results (more than 1 page)
+ if ($totalcount > $perpage) {
+ $code .= "<center>";
+ $code .= "<p>".get_string("page").":";
+
+ $maxpage = (int)(($totalcount-1)/$perpage);
+
+ //Lower and upper limit of page
+ if ($page < 0) {
+ $page = 0;
+ }
+ if ($page > $maxpageallowed) {
+ $page = $maxpageallowed;
+ }
+ if ($page > $maxpage) {
+ $page = $maxpage;
+ }
+
+ //Calculate the window of pages
+ $pagefrom = $page - ((int)($maxdisplay / 2));
+ if ($pagefrom < 0) {
+ $pagefrom = 0;
+ }
+ $pageto = $pagefrom + $maxdisplay - 1;
+ if ($pageto > $maxpageallowed) {
+ $pageto = $maxpageallowed;
+ }
+ if ($pageto > $maxpage) {
+ $pageto = $maxpage;
+ }
+
+ //Some movements can be necessary if don't see enought pages
+ if ($pageto - $pagefrom < $maxdisplay - 1) {
+ if ($pageto - $maxdisplay + 1 > 0) {
+ $pagefrom = $pageto - $maxdisplay + 1;
+ }
+ }
+
+ //Calculate first and last if necessary
+ $firstpagecode = '';
+ $lastpagecode = '';
+ if ($pagefrom > 0) {
+ $firstpagecode = "$separator<a href=\"{$baseurl}page=0\">1</a>";
+ if ($pagefrom > 1) {
+ $firstpagecode .= "$separator...";
+ }
+ }
+ if ($pageto < $maxpage) {
+ if ($pageto < $maxpage -1) {
+ $lastpagecode = "$separator...";
+ }
+ $lastpagecode .= "$separator<a href=\"{$baseurl}page=$maxpage\">".($maxpage+1)."</a>";
+ }
+
+ //Previous
+ if ($page > 0 && $previousandnext) {
+ $pagenum = $page - 1;
+ $code .= "&nbsp;(<a href=\"{$baseurl}page=$pagenum\">".get_string("previous")."</a>)&nbsp;";
+ }
+
+ //Add first
+ $code .= $firstpagecode;
+
+ $pagenum = $pagefrom;
+
+ //List of maxdisplay pages
+ while ($pagenum <= $pageto) {
+ $pagetoshow = $pagenum +1;
+ if ($pagenum == $page && !$specialselected) {
+ $code .= "$separator$pagetoshow";
+ } else {
+ $code .= "$separator<a href=\"{$baseurl}page=$pagenum\">$pagetoshow</a>";
+ }
+ $pagenum++;
+ }
+
+ //Add last
+ $code .= $lastpagecode;
+
+ //Next
+ if ($page < $maxpage && $page < $maxpageallowed && $previousandnext) {
+ $pagenum = $page + 1;
+ $code .= "$separator(<a href=\"{$baseurl}page=$pagenum\">".get_string("next")."</a>)";
+ }
+
+ //Add special
+ if ($showspecial) {
+ $code .= '<br />';
+ if ($specialselected) {
+ $code .= $specialtext;
+ } else {
+ $code .= "$separator<a href=\"{$baseurl}page=$specialvalue\">$specialtext</a>";
+ }
+ }
+
+ //End html
+ $code .= "</p>";
+ $code .= "</center>";
+ }
+
+ return $code;
+}
+
?>
View
@@ -21,6 +21,7 @@
$sortkey = optional_param('sortkey'); // Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME...
$sortorder = optional_param('sortorder'); // it defines the order of the sorting (ASC or DESC)
$offset = optional_param('offset',0); // entries to bypass (for paging purpouses)
+ $page = optional_param('page',0); // Page to show (for paging purpouses)
$show = optional_param('show'); // [ concept | alias ] => mode=term hook=$show
if (!empty($id)) {
@@ -63,6 +64,11 @@
$entriesbypage = $CFG->glossary_entbypage;
}
+/// If we have received a page, recalculate offset
+ if ($page != 0 && $offset == 0) {
+ $offset = $page * $entriesbypage;
+ }
+
/// setting the default values for the display mode of the current glossary
/// only if the glossary is viewed by the first time
if ( $dp = get_record('glossary_formats','name', $glossary->displayformat) ) {
@@ -281,35 +287,11 @@
if ($allentries) {
- /// printing the paging links
+ $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch&",9999,10,'&nbsp;&nbsp;', get_string("allentries","glossary"), -1);
- $paging = get_string("allentries","glossary");
- if ( $offset < 0 ) {
- $paging = '<strong>' . $paging . '</strong>';
- } else {
- $paging = "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=-1&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch\">" . $paging . '</a>';
- }
- if ($count > $entriesbypage ) {
- for ($i = 0; ($i*$entriesbypage) < $count ; $i++ ) {
- if ( $paging != '' ) {
- if ($i % 20 == 0 and $i) {
- $paging .= '<br>';
- } else {
- $paging .= ' | ';
- }
- }
- $pagenumber = (string) ($i + 1 );
- if ($offset / $entriesbypage == $i) {
- $paging .= '<strong>' . $pagenumber . '</strong>';
- } else {
- $paging .= "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=" . ($i*$entriesbypage) . "&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch\">" . $pagenumber . '</a>';
- }
- }
- $paging = "<font size=1><center>" . get_string ("jumpto") . " $paging</center></font>";
- } else {
- $paging = '';
- }
+ echo '<div style="font-size: smaller;">';
echo $paging;
+ echo '</div>';
$ratings = NULL;
$ratingsmenuused = false;
@@ -398,7 +380,10 @@
}
if ( $paging ) {
- echo "<hr />$paging";
+ echo '<hr />';
+ echo '<div style="font-size: smaller;">';
+ echo $paging;
+ echo '</div>';
}
echo '<p>';
echo '</center>';

0 comments on commit b9734b5

Please sign in to comment.