]> git.mjollnir.org Git - moodle.git/commitdiff
- Adding paging when the number of entries shown is greater than $CFG->glossary_entbypage
authorwillcast <willcast>
Tue, 4 Nov 2003 18:38:22 +0000 (18:38 +0000)
committerwillcast <willcast>
Tue, 4 Nov 2003 18:38:22 +0000 (18:38 +0000)
- Adding $CFG->glossary_entbypage to config.html

mod/glossary/config.html
mod/glossary/view.php

index 5e35d6c1fabd9c04628a1d497155c09a57381c90..d515b3d6eabd0e0baaca5b9151b953be6bc74441 100644 (file)
@@ -8,6 +8,15 @@
 <tr valign=top>
     <td colspan = 3 align=center><strong>Glossary Level Default Settings</strong></td>
 </tr>
+<tr valign=top>
+    <td align=right><p>glossary_entbypage:</td>
+    <td>
+    <input name=glossary_entbypage type=text size=5 value="<?php p($CFG->glossary_entbypage) ?>">
+    </td>
+    <td>
+    <?php print_string("entbypage", "glossary") ?>
+    </td>
+</tr>
 <tr valign=top>
     <td align=right><p>students_can_post_entries:</td>
     <td>
index 9f1a2f619f4e40c67e2f015876e08d9bddbddcde..786a5b54d895ac95abda808fe7da6799afe9a704 100644 (file)
@@ -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?
     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");
     } 
             $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 = "";
                 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;
     
     $dumpeddefinitions = 0;
     if ($allentries) {
+        $paging = '';
+        if ($count > $entriesbypage ) {
+            for ($i = 0; ($i*$entriesbypage) < $count  ; $i++   ) {
+                if ( $paging != '' ) {
+                    if ($i % 20 == 0) {
+                        $paging .= '<br>';
+                    } else {
+                        $paging .= ' | ';
+                    }
+                }
+                if ($offset / $entriesbypage == $i) {
+                    $paging .= '<strong>' . ($i + 1 ) . '</strong>';
+                } else {
+                    $paging .= "<a href=\"view.php?id=$id&l=$l&search=$search&tab=$tab&cat=$cat&includedefinition=$includedefinition&sortkey=$sortkey&sortored=$sortorder&offset=" . ($i*$entriesbypage) . "\">" . ($i+1) . '</a>';
+                }
+            }
+            $paging  = "<font size=1><center>" . get_string ("jumpto") . " $paging</center></font>";
+        }
+        echo "$paging<p>";
         if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
             echo '<table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=left bgcolor="#FFFFFF">';
         }
                 } 
     
                 glossary_print_entry($course, $cm, $glossary, $entry, $tab, $cat);
-    
                 if ($glossary->displayformat != GLOSSARY_FORMAT_SIMPLE) {
                     echo '<p>';
                 } 
         } 
         print_simple_box_end();
     } else {
+        if ( $paging ) {
+            echo "<table border=0><tr><td>$paging</td></tr></table>";
+        }
         switch ($glossary->displayformat) {
             case GLOSSARY_FORMAT_CONTINUOUS:
                 echo '</td></tr></table><p>';