Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  
   3  /**
   4   * SQL.PHP
   5   *    This file is include from view.php and print.php
   6   * @copyright 2003
   7   **/
   8  
   9  /**
  10   * This file defines, or redefines, the following variables:
  11   *
  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.
  21   *
  22   * It relies on the following variables:
  23   *
  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.
  33   */
  34  
  35  $userispivot = false;
  36  $fullpivot = true;
  37  $pivotkey = 'concept';
  38  
  39  switch ($tab) {
  40  
  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;
  49  
  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;
  56          }
  57          break;
  58  
  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;
  66  
  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;
  73  
  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;
  82  
  83              case 'term':
  84                  $printpivot = false;
  85                  list($allentries, $count) = glossary_get_entries_by_term($glossary, $context, $hook, $offset, $pagelimit);
  86                  break;
  87  
  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();
  99                  }
 100                  unset($entry, $canapprove);
 101                  break;
 102  
 103              case 'letter':
 104              default:
 105                  list($allentries, $count) = glossary_get_entries_by_letter($glossary, $context, $hook, $offset, $pagelimit);
 106                  break;
 107          }
 108          break;
 109  }