MDL-54623 mod_assign: Unit test for list_participants()
[moodle.git] / mod / glossary / sql.php
blob7e6a0c5ce7e61704483f0215ef9919ba92f94be4
1 <?php
3 /**
4 * SQL.PHP
5 * This file is include from view.php and print.php
6 * @copyright 2003
7 **/
9 /**
10 * This file defines, or redefines, the following variables:
12 * bool $userispivot Whether the user is the pivot.
13 * bool $fullpivot Whether the pivot should be displayed in full.
14 * bool $printpivot Whether the pivot should be displayed.
15 * string $pivotkey The property of the record at which the pivot is.
16 * int $count The number of records matching the request.
17 * array $allentries The entries matching the request.
18 * mixed $field Unset in this file.
19 * mixed $entry Unset in this file.
20 * mixed $canapprove Unset in this file.
22 * It relies on the following variables:
24 * object $glossary The glossary object.
25 * context $context The glossary context.
26 * mixed $hook The hook for the selected tab.
27 * string $sortkey The key to sort the records.
28 * string $sortorder The order of the sorting.
29 * int $offset The number of records to skip.
30 * int $entriesbypage The number of entries per page.
31 * string $mode The mode of browsing.
32 * string $tab The tab selected.
35 $userispivot = false;
36 $fullpivot = true;
37 $pivotkey = 'concept';
39 switch ($tab) {
41 case GLOSSARY_AUTHOR_VIEW:
42 $userispivot = true;
43 $pivotkey = 'userid';
44 $field = ($sortkey == 'LASTNAME' ? 'LASTNAME' : 'FIRSTNAME');
45 list($allentries, $count) = glossary_get_entries_by_author($glossary, $context, $hook,
46 $field, $sortorder, $offset, $entriesbypage);
47 unset($field);
48 break;
50 case GLOSSARY_CATEGORY_VIEW:
51 $hook = (int) $hook; // Make sure it's properly casted to int.
52 list($allentries, $count) = glossary_get_entries_by_category($glossary, $context, $hook, $offset, $entriesbypage);
53 $pivotkey = 'categoryname';
54 if ($hook != GLOSSARY_SHOW_ALL_CATEGORIES) {
55 $printpivot = false;
57 break;
59 case GLOSSARY_DATE_VIEW:
60 $printpivot = false;
61 $field = ($sortkey == 'CREATION' ? 'CREATION' : 'UPDATE');
62 list($allentries, $count) = glossary_get_entries_by_date($glossary, $context, $field, $sortorder,
63 $offset, $entriesbypage);
64 unset($field);
65 break;
67 case GLOSSARY_APPROVAL_VIEW:
68 $fullpivot = false;
69 $printpivot = false;
70 list($allentries, $count) = glossary_get_entries_to_approve($glossary, $context, $hook, $sortkey, $sortorder,
71 $offset, $entriesbypage);
72 break;
74 case GLOSSARY_STANDARD_VIEW:
75 default:
76 $fullpivot = false;
77 switch ($mode) {
78 case 'search':
79 list($allentries, $count) = glossary_get_entries_by_search($glossary, $context, $hook, $fullsearch,
80 $sortkey, $sortorder, $offset, $entriesbypage);
81 break;
83 case 'term':
84 $printpivot = false;
85 list($allentries, $count) = glossary_get_entries_by_term($glossary, $context, $hook, $offset, $entriesbypage);
86 break;
88 case 'entry':
89 $printpivot = false;
90 $entry = glossary_get_entry_by_id($hook);
91 $canapprove = has_capability('mod/glossary:approve', $context);
92 if ($entry && ($entry->glossaryid == $glossary->id || $entry->sourceglossaryid != $glossary->id)
93 && (!empty($entry->approved) || $entry->userid == $USER->id || $canapprove)) {
94 $count = 1;
95 $allentries = array($entry);
96 } else {
97 $count = 0;
98 $allentries = array();
100 unset($entry, $canapprove);
101 break;
103 case 'letter':
104 default:
105 list($allentries, $count) = glossary_get_entries_by_letter($glossary, $context, $hook, $offset, $entriesbypage);
106 break;
108 break;