From: stronk7 Date: Wed, 24 Nov 2004 23:37:46 +0000 (+0000) Subject: New paging system for glosaries. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e2cf5316c1e0e6dcc993c1a36fdeab0668fb573c;p=moodle.git New paging system for glosaries. 100% compatible with Moodle's one. Supports more options. Perhaps we could use it sitewide. Merged from MOODLE_14_STABLE --- diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 4dc39cf522..7b003ebcbd 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -675,7 +675,6 @@ function glossary_print_entry_aliases($course, $cm, $glossary, $entry,$mode="", } if ($return != '') { $return .= ''; -// $return = "
$return
"; } } if ($type == 'print') { @@ -701,11 +700,11 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$mode="",$ho $return .= " "; - if ( ($glossary->allowcomments && !isguest()) || isteacher($glossary->course)) { + if ( (!empty($USER->id) && $glossary->allowcomments && !isguest()) || $isteacher) { $return .= " id&eid=$entry->id\">\"\" "; } - 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); @@ -2043,4 +2042,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=" ", $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 .= "
"; + $code .= "

".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 = "$separator1"; + if ($pagefrom > 1) { + $firstpagecode .= "$separator..."; + } + } + if ($pageto < $maxpage) { + if ($pageto < $maxpage -1) { + $lastpagecode = "$separator..."; + } + $lastpagecode .= "$separator".($maxpage+1).""; + } + + //Previous + if ($page > 0 && $previousandnext) { + $pagenum = $page - 1; + $code .= " (".get_string("previous").") "; + } + + //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$pagetoshow"; + } + $pagenum++; + } + + //Add last + $code .= $lastpagecode; + + //Next + if ($page < $maxpage && $page < $maxpageallowed && $previousandnext) { + $pagenum = $page + 1; + $code .= "$separator(".get_string("next").")"; + } + + //Add special + if ($showspecial) { + $code .= '
'; + if ($specialselected) { + $code .= $specialtext; + } else { + $code .= "$separator$specialtext"; + } + } + + //End html + $code .= "

"; + $code .= "
"; + } + + return $code; +} + ?> diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 9a3a741009..3a7915f8bc 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -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) ) { @@ -284,35 +290,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,'  ', get_string("allentries","glossary"), -1); - $paging = get_string("allentries","glossary"); - if ( $offset < 0 ) { - $paging = '' . $paging . ''; - } else { - $paging = "" . $paging . ''; - } - if ($count > $entriesbypage ) { - for ($i = 0; ($i*$entriesbypage) < $count ; $i++ ) { - if ( $paging != '' ) { - if ($i % 20 == 0 and $i) { - $paging .= '
'; - } else { - $paging .= ' | '; - } - } - $pagenumber = (string) ($i + 1 ); - if ($offset / $entriesbypage == $i) { - $paging .= '' . $pagenumber . ''; - } else { - $paging .= "" . $pagenumber . ''; - } - } - $paging = "
" . get_string ("jumpto") . " $paging
"; - } else { - $paging = ''; - } + echo '
'; echo $paging; + echo '
'; $ratings = NULL; $ratingsmenuused = false; @@ -401,7 +383,10 @@ } if ( $paging ) { - echo "
$paging"; + echo '
'; + echo '
'; + echo $paging; + echo '
'; } echo '

'; echo '';