- Improved browse by author.
authorwillcast <willcast>
Sun, 16 Nov 2003 17:13:19 +0000 (17:13 +0000)
committerwillcast <willcast>
Sun, 16 Nov 2003 17:13:19 +0000 (17:13 +0000)
- view.php?id=cm&show=[concept | alias ] done.

mod/glossary/lib.php
mod/glossary/view.php

index 5867e9ca39330980d9bcf58c2f41187c9e7f6497..e9d0bc3e170e701ada2fdcceb5317f0339487583 100644 (file)
@@ -175,7 +175,8 @@ function glossary_print_recent_activity($course, $isteacher, $timestart) {
     if (!$logs = get_records_select("log", "time > '$timestart' AND ".
                                            "course = '$course->id' AND ".
                                            "module = 'glossary' AND ".
-                                           "action = 'add entry'", "time ASC")) {
+                                           "(action = 'add entry' OR ".
+                                           " action  = 'approve entry')", "time ASC")) {
         return false;
     }
 
@@ -188,7 +189,7 @@ function glossary_print_recent_activity($course, $isteacher, $timestart) {
         $modvisible = instance_is_visible($log->module,$tempmod);
 
         //Only if the mod is visible
-        if ($modvisible) {
+        if ($modvisible and $entry->approved) {
             $entries[$log->info] = glossary_log_info($log);
             $entries[$log->info]->time = $log->time;
             $entries[$log->info]->url  = $log->url;
@@ -920,7 +921,7 @@ function glossary_print_approval_menu($cm, $glossary,$mode, $hook, $sortkey = ''
     }
     glossary_print_special_links($cm, $glossary, $mode, $hook);
 
-    glossary_print_alphabet_links($cm, $glossary, $mode, $hook);
+    glossary_print_alphabet_links($cm, $glossary, $mode, $hook,$sortkey, $sortorder);
 
     glossary_print_all_links($cm, $glossary, $mode, $hook);
         
@@ -947,7 +948,7 @@ function glossary_print_alphabet_menu($cm, $glossary, $mode, $hook, $sortkey='',
 
         glossary_print_special_links($cm, $glossary, $mode, $hook);
 
-        glossary_print_alphabet_links($cm, $glossary, $mode, $hook);
+        glossary_print_alphabet_links($cm, $glossary, $mode, $hook, $sortkey, $sortorder);
 
         glossary_print_all_links($cm, $glossary, $mode, $hook);
     } else {
@@ -957,12 +958,13 @@ function glossary_print_alphabet_menu($cm, $glossary, $mode, $hook, $sortkey='',
 
 function glossary_print_author_menu($cm, $glossary,$mode, $hook, $sortkey = '', $sortorder = '') {
     if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
-        echo '<center>' . get_string("explainalphabet","glossary") . '<p>';
+        echo '<center>' . get_string("explainalphabet","glossary") . '<br \>';
     }
 
-    glossary_print_alphabet_links($cm, $glossary, $mode, $hook);
-    echo "<br />";
+    glossary_print_sorting_links($cm, $mode, $sortkey,$sortorder);
+    glossary_print_alphabet_links($cm, $glossary, $mode, $hook, $sortkey, $sortorder);
     glossary_print_all_links($cm, $glossary, $mode, $hook);
+//    echo "<br />";
 }
 
 function glossary_print_categories_menu($cm, $glossary, $hook, $category) {
@@ -1055,7 +1057,7 @@ global $CFG;
      }
 }
 
-function glossary_print_alphabet_links($cm, $glossary, $mode, $hook) {
+function glossary_print_alphabet_links($cm, $glossary, $mode, $hook, $sortkey, $sortorder) {
 global $CFG;
      if ( $glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
           $alphabet = explode(",", get_string("alphabet"));
@@ -1064,7 +1066,7 @@ global $CFG;
               if ( $hook == $alphabet[$i] and $hook) {
                    echo "<b>$alphabet[$i]</b>";
               } else {
-                   echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&mode=$mode&hook=$alphabet[$i]\">$alphabet[$i]</a>";
+                   echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&mode=$mode&hook=$alphabet[$i]&sortkey=$sortkey&sortorder=$sortorder\">$alphabet[$i]</a>";
               }
               if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
                    echo ' | ';
@@ -1077,60 +1079,80 @@ global $CFG;
 
 function glossary_print_sorting_links($cm, $mode, $sortkey = '',$sortorder = '') {
 global $CFG;
-    $strsort             = get_string("sortchronogically", "glossary");
-    $strsortbycreation   = get_string("sortbycreation", "glossary");
-    $strsortbylastupdate = get_string("sortbylastupdate", "glossary");
 
+    $asc    = get_string("ascending","glossary");
+    $desc   = get_string("descending","glossary");
+    $bopen  = '<b>';
+    $bclose = '</b>';
+    
      $neworder = '';
      if ( $sortorder ) {
          if ( $sortorder == 'asc' ) {
              $neworder = '&sortorder=desc';
-             $ordertitle = get_string("descending","glossary");
+             $newordertitle = $desc;
          } else {
              $neworder = '&sortorder=asc';
-             $ordertitle = get_string("ascending","glossary");
+             $newordertitle = $asc;
          }
          $icon = " <img src=\"$sortorder.gif\" border=0 width=16 height=16>";
      } else {
-         if ( $sortkey != 'CREATION' and $sortkey != 'UPDATE' ) {
+         if ( $sortkey != 'CREATION' and $sortkey != 'UPDATE' and
+               $sortkey != 'FIRSTNAME' and $sortkey != 'LASTNAME' ) {
              $icon = "";
-             $ordertitle = get_string("ascending","glossary");
+             $newordertitle = $asc;
          } else {
-             $ordertitle = get_string("descending","glossary");
+             $newordertitle = $desc;
              $neworder = '&sortorder=desc';
              $icon = ' <img src="asc.gif" border=0 width=16 height=16>';
          }
      }
-     $cicon = '';
-     $cneworder = '';
-     $cbtag = '';
-     $cendbtag = '';
-
-     $uicon = '';
-     $uneworder = '';
-     $ubtag = '';
-     $uendbtag = '';
-
-     if ( $sortkey == 'CREATION' ) {
-         $cicon = $icon;
-         $cneworder = $neworder;
-         $cordertitle = $ordertitle;
-         $uordertitle = get_string("ascending","glossary");
-         $cbtag = '<b>';
-         $cendbtag = '</b>';
-     } elseif ($sortkey == 'UPDATE') {
-         $uicon = $icon;
-         $uneworder = $neworder;
-         $cordertitle = get_string("ascending","glossary");
-         $uordertitle = $ordertitle;
-         $ubtag = '<b>';
-         $uendbtag = '</b>';
+     $ficon     = '';
+     $fneworder = '';
+     $fbtag     = '';
+     $fendbtag  = '';
+
+     $sicon     = '';
+     $sneworder = '';
+     $stag      = '';
+     $sendbtag  = '';
+
+     if ( $sortkey == 'CREATION' or $sortkey == 'FIRSTNAME' ) {
+         $ficon       = $icon;
+         $fneworder   = $neworder;
+         $fordertitle = $newordertitle;
+         $sordertitle = $asc;
+         $fbtag       = $bopen;
+         $fendbtag    = $bclose;
+     } elseif ($sortkey == 'UPDATE' or $sortkey == 'LASTNAME') {
+         $sicon = $icon;
+         $sneworder   = $neworder;
+         $fordertitle = $asc;
+         $sordertitle = $newordertitle;
+         $sbtag       = $bopen;
+         $sendbtag    = $bclose;
      } else {
-         $cordertitle = get_string("ascending","glossary");
-         $uordertitle = get_string("ascending","glossary");
+         $fordertitle = $asc;
+         $sordertitle = $asc;
      }
-     echo "<br>$strsort: $ubtag<a title=\"$strsortbylastupdate $uordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=UPDATE$uneworder&mode=$mode\">$strsortbylastupdate$uicon</a>$uendbtag | ".
-                          "$cbtag<a title=\"$strsortbycreation $cordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder&mode=$mode\">$strsortbycreation$cicon</a>$cendbtag</p>";
+
+     if ( $sortkey == 'CREATION' or $sortkey == 'UPDATE' ) {
+         $forder = 'CREATION';
+         $sorder =  'UPDATE';
+         $fsort  = get_string("sortbycreation", "glossary");
+         $ssort  = get_string("sortbylastupdate", "glossary");
+
+         $sort        = get_string("sortchronogically", "glossary");
+     } elseif ( $sortkey == 'FIRSTNAME' or $sortkey == 'LASTNAME') {
+         $forder = 'FIRSTNAME';
+         $sorder =  'LASTNAME';
+         $fsort  = get_string("firstname");
+         $ssort  = get_string("lastname");
+
+         $sort        = get_string("sortby", "glossary");
+     }
+
+     echo "<br>$sort: $sbtag<a title=\"$ssort $sordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=$sorder$sneworder&mode=$mode\">$ssort$sicon</a>$sendbtag | ".
+                          "$fbtag<a title=\"$fsort $fordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=$forder$fneworder&mode=$mode\">$fsort$ficon</a>$fendbtag<br \>";
 }
 
 function glossary_sort_entries ( $entry0, $entry1 ) {
index 8f34a11604a9fb539a35b897e42815b405c34dcb..4d72b6fc7a94e98aebd10f0aad0d8ad5c6bbca11 100644 (file)
     optional_variable($fullsearch,0); // full search (concept and definition) when searching?
 
     optional_variable($sortkey,"");    // Sorted view: 
-                                       //    [ CREATION | UPDATE | concept | timecreated | ... ]
+                                       //    [ CREATION | UPDATE | FIRSTNAME | LASTNAME |
+                                       //      concept | timecreated | ... ]
     optional_variable($sortorder,"");  // it defines the order of the sorting (ASC or DESC)
 
     optional_variable($offset,0);    // entries to bypass (for paging purpouses)
 
+    optional_variable($show,"");     // [ concept | alias ] => mode=term hook=$show
+
+    if ( $show ) {
+        $mode = 'term';
+        $hook = $show;
+        $show = '';
+    }
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
     }     
         }
     }
     if ( $sortkey = strtoupper($sortkey) ) {
-        if ($sortkey != 'CREATION' and $sortkey != 'UPDATE') {
+        if ($sortkey != 'CREATION' and 
+            $sortkey != 'UPDATE' and 
+            $sortkey != 'FIRSTNAME' and 
+            $sortkey != 'LASTNAME'
+            ) {
             $sortkey = '';
         }
     }
         if ( !$hook ) {
             $hook = 'ALL';
         } 
+        if ( !$sortkey ) {
+            $sortkey = 'FIRSTNAME';
+        } 
+        if ( !$sortorder ) {
+            $sortorder = 'asc';
+        }
     break;
 
     case 'letter':  /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
         $where = '';
         switch ($CFG->dbtype) {
         case 'postgres7':
-            $usernamefield = "u.firstname || ' ' || u.lastname";
+            $usernametoshow = "u.firstname || ' ' || u.lastname";
+            if ( $sortkey == 'FIRSTNAME' ) {
+                $usernamefield = "u.firstname || ' ' || u.lastname";
+            } else {
+                $usernamefield = "u.lastname || ' ' || u.firstname";
+            }
             $where = "AND substr(ucase($usernamefield),1," .  strlen($hook) . ") = '" . strtoupper($hook) . "'";
         break;
         case 'mysql':
-            $usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
+            $usernametoshow = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
+            if ( $sortkey == 'FIRSTNAME' ) {
+                $usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
+            } else {
+                $usernamefield = "CONCAT(CONCAT(u.lastname,' '), u.firstname)";
+            }
             $where = "AND left(ucase($usernamefield)," .  strlen($hook) . ") = '$hook'";
         break;
         }
             $where = '';
         }
 
-        $sqlselect  = "SELECT ge.id, $usernamefield pivot, u.id uid, ge.*";
+        $sqlselect  = "SELECT ge.id, $usernamefield pivot, $usernametoshow uname, u.id uid, ge.*";
         $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}user u";
         $sqlwhere   = "WHERE ge.userid = u.id  AND
                              ge.approved != 0
                              $where AND 
                              (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id)";
-        $sqlorderby = "ORDER BY $usernamefield, ge.concept";
+        $sqlorderby = "ORDER BY $usernamefield $sortorder, ge.concept";
 
         $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
         $sqllimit = " LIMIT $offset, $entriesbypage";
         case 'term': 
             $printpivot = 0;
             $sqlfrom .= ", {$CFG->prefix}glossary_alias ga";
-            $where = "AND ge.id = ga.entryid AND ( ge.concept = '$hook' OR ga.alias = '$hook' )";
+            $where = "AND ge.id = ga.entryid AND                            
+                          (ge.concept = '$hook' OR ga.alias = '$hook' )
+                     ";
+//            $where = "AND ge.id = ga.entryid AND (
+//                           (ge.casesensitive != 0 and ( ge.concept LIKE BINARY '$hook' OR ga.alias LIKE BINARY '$hook' ) ) or
+//                           (ge.casesensitive = 0 and ( ucase(ge.concept) = ucase('$hook') OR ucase(ga.alias) = ucase('$hook') ) )
+//                       )";
         break;
 
         case 'entry': 
         }
         
         foreach ($allentries as $entry) {
-//glossary_debug($debug,"<b>$entry->concept</b>");
+        /// Setting the pivot for the current entry
             $pivot = $entry->pivot;
             if ( !$fullpivot ) {
                 $pivot = $pivot[0];
             }            
             
-            /// Validating special cases not covered by the SQL statement
+        /// 
+        /// Validating special cases not covered by the SQL statement
+        /// 
+
+        /// if we're browsing by alphabet and the current concept does not begin with
+        ///     the letter we are look for.
             $showentry = 1;
             if ( $mode == 'letter' and $hook != 'SPECIAL' and $hook != 'ALL' ) {
                 if ( substr($entry->concept, 0, strlen($hook)) != $hook ) {
                     $showentry = 0;
                 }
             } 
-//glossary_debug($debug,(++$num) . ": $showentry");
-            if ( $hook == 'SPECIAL' ) {
+            
+        /// if we're browsing for letter, looking for special characters not covered
+        ///     in the alphabet 
+            if ( $showentry and $hook == 'SPECIAL' ) {
                 $initial = $entry->concept[0];
                 for ($i = 0; $i < count($alphabet); $i++) {
                     $curletter = $alphabet[$i];
                     }
                 }
             } 
-//glossary_debug($debug,(++$num) . ": $showentry");
-            if ( $mode == 'cat' and $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
+
+        /// if we're browsing categories, looking for entries not categorised.
+            if ( $showentry and $mode == 'cat' and $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
                 if ( record_exists("glossary_entries_categories", "entryid", $entry->id)) {
                     $showentry = 0;
                 } 
             }
-//glossary_debug($debug,(++$num) . ": $showentry");
-            if ( $mode != 'approval' ) {
+
+        /// if the entry is not approved, deal with it based on the current view and
+        ///     user.
+            if ( $showentry and $mode != 'approval' ) {
                 if ( !$entry->approved and isteacher($course->id, $entry->userid) ) {
                     $showentry = 0;
                 }            
             }
-//glossary_debug($debug,(++$num) . ": $showentry");
+
             /// ok, if it's a valid entry.. Print it.
             if ( $showentry ) {
             
                 /// if there's a group break
                 if ( $currentpivot != strtoupper($pivot) ) {  
 
-                    // print the group break if apply and necessary
+                    // print the group break if apply
                     if ( $printpivot )  {
                         if ( $tableisopen ) {
                             print_simple_box_end();
                         echo '<table width="95%" border="0" class="generaltabselected" bgcolor="' . $THEME->cellheading2 . '">';
 
                         echo '<tr>';
+                        $pivottoshow = $currentpivot;
                         if ( isset($entry->uid) ) {
                         // printing the user icon if defined (only when browsing authors)
                             echo '<td align="left">';
                             
                             $user = get_record("user","id",$entry->uid);
                             print_user_picture($user->id, $course->id, $user->picture);
+                            $pivottoshow = $entry->uname;
                         } else {
                             echo '<td align="center">';
                         }
 
-                        echo "<strong> $currentpivot</strong>" ;
+                        echo "<strong> $pivottoshow</strong>" ;
                         echo '</td></tr></table>';
 
                         if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS OR