From c4a354196b6d56a54a639066cc2826946d1306d9 Mon Sep 17 00:00:00 2001 From: willcast Date: Sun, 16 Nov 2003 17:13:19 +0000 Subject: [PATCH] - Improved browse by author. - view.php?id=cm&show=[concept | alias ] done. --- mod/glossary/lib.php | 112 +++++++++++++++++++++++++----------------- mod/glossary/view.php | 82 ++++++++++++++++++++++++------- 2 files changed, 131 insertions(+), 63 deletions(-) diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 5867e9ca39..e9d0bc3e17 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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 '
' . get_string("explainalphabet","glossary") . '

'; + echo '

' . get_string("explainalphabet","glossary") . '
'; } - glossary_print_alphabet_links($cm, $glossary, $mode, $hook); - echo "
"; + 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 "
"; } 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 "$alphabet[$i]"; } else { - echo "wwwroot/mod/glossary/view.php?id=$cm->id&mode=$mode&hook=$alphabet[$i]\">$alphabet[$i]"; + echo "wwwroot/mod/glossary/view.php?id=$cm->id&mode=$mode&hook=$alphabet[$i]&sortkey=$sortkey&sortorder=$sortorder\">$alphabet[$i]"; } 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 = ''; + $bclose = ''; + $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 = " "; } 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 = ' '; } } - $cicon = ''; - $cneworder = ''; - $cbtag = ''; - $cendbtag = ''; - - $uicon = ''; - $uneworder = ''; - $ubtag = ''; - $uendbtag = ''; - - if ( $sortkey == 'CREATION' ) { - $cicon = $icon; - $cneworder = $neworder; - $cordertitle = $ordertitle; - $uordertitle = get_string("ascending","glossary"); - $cbtag = ''; - $cendbtag = ''; - } elseif ($sortkey == 'UPDATE') { - $uicon = $icon; - $uneworder = $neworder; - $cordertitle = get_string("ascending","glossary"); - $uordertitle = $ordertitle; - $ubtag = ''; - $uendbtag = ''; + $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 "
$strsort: $ubtagwwwroot/mod/glossary/view.php?id=$cm->id&sortkey=UPDATE$uneworder&mode=$mode\">$strsortbylastupdate$uicon$uendbtag | ". - "$cbtagwwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder&mode=$mode\">$strsortbycreation$cicon$cendbtag

"; + + 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 "
$sort: $sbtagwwwroot/mod/glossary/view.php?id=$cm->id&sortkey=$sorder$sneworder&mode=$mode\">$ssort$sicon$sendbtag | ". + "$fbtagwwwroot/mod/glossary/view.php?id=$cm->id&sortkey=$forder$fneworder&mode=$mode\">$fsort$ficon$fendbtag
"; } function glossary_sort_entries ( $entry0, $entry1 ) { diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 8f34a11604..4d72b6fc7a 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -14,11 +14,19 @@ 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"); } @@ -64,7 +72,11 @@ } } if ( $sortkey = strtoupper($sortkey) ) { - if ($sortkey != 'CREATION' and $sortkey != 'UPDATE') { + if ($sortkey != 'CREATION' and + $sortkey != 'UPDATE' and + $sortkey != 'FIRSTNAME' and + $sortkey != 'LASTNAME' + ) { $sortkey = ''; } } @@ -119,6 +131,12 @@ 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 @@ -263,11 +281,21 @@ $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; } @@ -275,13 +303,13 @@ $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"; @@ -346,7 +374,13 @@ 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': @@ -431,21 +465,28 @@ } foreach ($allentries as $entry) { -//glossary_debug($debug,"$entry->concept"); + /// 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]; @@ -456,26 +497,29 @@ } } } -//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(); @@ -487,17 +531,19 @@ echo ''; echo ''; + $pivottoshow = $currentpivot; if ( isset($entry->uid) ) { // printing the user icon if defined (only when browsing authors) echo '
'; $user = get_record("user","id",$entry->uid); print_user_picture($user->id, $course->id, $user->picture); + $pivottoshow = $entry->uname; } else { echo ''; } - echo " $currentpivot" ; + echo " $pivottoshow" ; echo '
'; if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS OR -- 2.39.5