From: willcast Date: Tue, 4 Nov 2003 18:38:22 +0000 (+0000) Subject: - Adding paging when the number of entries shown is greater than $CFG->glossary_entbypage X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=de1fe38401f12dc6cd985d2ffb4f558b4975ea76;p=moodle.git - Adding paging when the number of entries shown is greater than $CFG->glossary_entbypage - Adding $CFG->glossary_entbypage to config.html --- diff --git a/mod/glossary/config.html b/mod/glossary/config.html index 5e35d6c1fa..d515b3d6ea 100644 --- a/mod/glossary/config.html +++ b/mod/glossary/config.html @@ -8,6 +8,15 @@ Glossary Level Default Settings + +

glossary_entbypage: + + + + + + +

students_can_post_entries: diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 9f1a2f619f..786a5b54d8 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -5,7 +5,8 @@ require_once("lib.php"); require_variable($id); // Course Module ID - optional_variable($l,""); // letter to look for + optional_variable($l,""); // letter to look for + optional_variable($offset,0); // entries to bypass (paging purpouses) optional_variable($eid); // Entry ID optional_variable($search, ""); // search string optional_variable($includedefinition); // include definition in search function? @@ -16,6 +17,12 @@ optional_variable($sortkey,""); // Sorted view: CREATION or UPDATE optional_variable($sortorder,""); // it define the order of the sorting (ASC or DESC) + global $CFG; + $entriesbypage = $CFG->glossary_entbypage; + + if (!$entriesbypage) { + $entriesbypage = 10; + } if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); } @@ -185,31 +192,49 @@ $orderby = "timemodified $sortorder"; break; default: - $orderby = "$sortkey $sortorder"; + $orderby .= "$sortkey $sortorder"; } switch ($tab) { case GLOSSARY_CATEGORY_VIEW: if ($cat == GLOSSARY_SHOW_ALL_CATEGORIES) { - $sql = "SELECT gec.id gecid, gc.name, gc.id CID, ge.* - FROM {$CFG->prefix}glossary_entries ge, + $sqlselect = "SELECT gec.id gecid, gc.name, gc.id CID, ge.*"; + $sqlfrom = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories gec, - {$CFG->prefix}glossary_categories gc - WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND + {$CFG->prefix}glossary_categories gc"; + $sqlwhere = "WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND gec.entryid = ge.id AND gc.id = gec.categoryid"; if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) { - $sql .= ' ORDER BY gc.name, ge.timecreated'; + $sqlorderby = ' ORDER BY gc.name, ge.timecreated'; } else { - $sql .= ' ORDER BY gc.name, ge.concept'; + $sqlorderby = ' ORDER BY gc.name, ge.concept'; } - $allentries = get_records_sql($sql); + $count = count_records_sql("select count(*) $sqlfrom $sqlwhere"); + $sqllimit = " LIMIT $offset, $entriesbypage"; + + $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit"); } else { if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) { - $allentries = glossary_get_entries_sorted($glossary, '',$orderby); + $sqlselect = "SELECT *"; + $sqlfrom = "FROM {$CFG->prefix}glossary_entries"; + $sqlwhere = "WHERE (glossaryid = $glossary->id or sourceglossaryid = $glossary->id)"; + $sqlorderby = "ORDER BY $orderby"; + + $count = count_records_sql("select count(*) $sqlfrom $sqlwhere"); + $sqllimit = " LIMIT $offset, $entriesbypage"; + $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit"); } else { - $allentries = glossary_get_entries_by_category($glossary, $cat, '',$orderby); + $sqlselect = "SELECT *"; + $sqlfrom = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories c"; + $sqlwhere = "WHERE (ge.id = c.entryid and c.categoryid = $cat) and + (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id)"; + $sqlorderby = "ORDER BY $orderby"; + + $count = count_records_sql("select count(*) $sqlfrom $sqlwhere"); + $sqllimit = " LIMIT $offset, $entriesbypage"; + $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit"); } } $currentcategory = ""; @@ -231,16 +256,22 @@ if ($l != 'ALL' and $l != 'SPECIAL') { switch ($CFG->dbtype) { case 'postgres7': - $where = 'substr(ucase(concept),1,' . strlen($l) . ') = \'' . strtoupper($l) . '\''; + $where = 'and substr(ucase(concept),1,' . strlen($l) . ') = \'' . strtoupper($l) . '\''; break; case 'mysql': - $where = 'left(ucase(concept),' . strlen($l) . ") = '$l'"; + $where = 'and left(ucase(concept),' . strlen($l) . ") = '$l'"; break; default: $where = ''; } } - $allentries = glossary_get_entries_sorted($glossary, $where,$orderby); + $sqlselect = "SELECT *"; + $sqlfrom = "FROM {$CFG->prefix}glossary_entries ge"; + $sqlwhere = "WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) $where"; + $sqlorderby = "ORDER BY $orderby"; + $count = count_records_sql("select count(*) $sqlfrom $sqlwhere"); + $sqllimit = " LIMIT $offset, $entriesbypage"; + $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit"); } $currentletter = ''; break; @@ -248,6 +279,25 @@ $dumpeddefinitions = 0; if ($allentries) { + $paging = ''; + if ($count > $entriesbypage ) { + for ($i = 0; ($i*$entriesbypage) < $count ; $i++ ) { + if ( $paging != '' ) { + if ($i % 20 == 0) { + $paging .= '
'; + } else { + $paging .= ' | '; + } + } + if ($offset / $entriesbypage == $i) { + $paging .= '' . ($i + 1 ) . ''; + } else { + $paging .= "" . ($i+1) . ''; + } + } + $paging = "

" . get_string ("jumpto") . " $paging
"; + } + echo "$paging

"; if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) { echo '
'; } @@ -347,7 +397,6 @@ } glossary_print_entry($course, $cm, $glossary, $entry, $tab, $cat); - if ($glossary->displayformat != GLOSSARY_FORMAT_SIMPLE) { echo '

'; } @@ -365,6 +414,9 @@ } print_simple_box_end(); } else { + if ( $paging ) { + echo "
$paging
"; + } switch ($glossary->displayformat) { case GLOSSARY_FORMAT_CONTINUOUS: echo '

';