MDL-61444 question: replace all question tag capability checks
[moodle.git] / mod / glossary / sql.php
blob914cc0c7667062309c20d9ea2b99d8a3e6b63b30
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 $pagelimit The number of entries on this page, or 0 if unlimited.
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, $pagelimit);
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, $pagelimit);
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, $pagelimit);
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, $pagelimit);
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, $pagelimit);
81 break;
83 case 'term':
84 $printpivot = false;
85 list($allentries, $count) = glossary_get_entries_by_term($glossary, $context, $hook, $offset, $pagelimit);
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, $pagelimit);
106 break;
108 break;