Example #1
0
 /**
  * Browse a glossary entries by author.
  *
  * @param int $id The glossary ID.
  * @param string $letter A letter, or a special keyword.
  * @param string $field The field to search from.
  * @param string $sort The direction of the order.
  * @param int $from Start returning records from here.
  * @param int $limit Number of records to return.
  * @param array $options Array of options.
  * @return array Containing count, entries and warnings.
  * @since Moodle 3.1
  * @throws moodle_exception
  * @throws invalid_parameter_exception
  */
 public static function get_entries_by_author($id, $letter, $field, $sort, $from, $limit, $options)
 {
     $params = self::validate_parameters(self::get_entries_by_author_parameters(), array('id' => $id, 'letter' => $letter, 'field' => core_text::strtoupper($field), 'sort' => core_text::strtoupper($sort), 'from' => $from, 'limit' => $limit, 'options' => $options));
     $id = $params['id'];
     $letter = $params['letter'];
     $field = $params['field'];
     $sort = $params['sort'];
     $from = $params['from'];
     $limit = $params['limit'];
     $options = $params['options'];
     $warnings = array();
     if (!in_array($field, array('FIRSTNAME', 'LASTNAME'))) {
         throw new invalid_parameter_exception('invalidfield');
     } else {
         if (!in_array($sort, array('ASC', 'DESC'))) {
             throw new invalid_parameter_exception('invalidsort');
         }
     }
     // Get and validate the glossary.
     list($glossary, $context) = self::validate_glossary($id);
     // Validate the mode.
     $modes = self::get_browse_modes_from_display_format($glossary->displayformat);
     if (!in_array('author', $modes)) {
         throw new invalid_parameter_exception('invalidbrowsemode');
     }
     // Fetching the entries.
     $entries = array();
     list($records, $count) = glossary_get_entries_by_author($glossary, $context, $letter, $field, $sort, $from, $limit, $options);
     foreach ($records as $key => $record) {
         self::fill_entry_details($record, $context);
         $entries[] = $record;
     }
     return array('count' => $count, 'entries' => $entries, 'warnings' => $warnings);
 }
Example #2
0
 * string $sortkey The key to sort the records.
 * string $sortorder The order of the sorting.
 * int $offset The number of records to skip.
 * int $pagelimit The number of entries on this page, or 0 if unlimited.
 * string $mode The mode of browsing.
 * string $tab The tab selected.
 */
$userispivot = false;
$fullpivot = true;
$pivotkey = 'concept';
switch ($tab) {
    case GLOSSARY_AUTHOR_VIEW:
        $userispivot = true;
        $pivotkey = 'userid';
        $field = $sortkey == 'LASTNAME' ? 'LASTNAME' : 'FIRSTNAME';
        list($allentries, $count) = glossary_get_entries_by_author($glossary, $context, $hook, $field, $sortorder, $offset, $pagelimit);
        unset($field);
        break;
    case GLOSSARY_CATEGORY_VIEW:
        $hook = (int) $hook;
        // Make sure it's properly casted to int.
        list($allentries, $count) = glossary_get_entries_by_category($glossary, $context, $hook, $offset, $pagelimit);
        $pivotkey = 'categoryname';
        if ($hook != GLOSSARY_SHOW_ALL_CATEGORIES) {
            $printpivot = false;
        }
        break;
    case GLOSSARY_DATE_VIEW:
        $printpivot = false;
        $field = $sortkey == 'CREATION' ? 'CREATION' : 'UPDATE';
        list($allentries, $count) = glossary_get_entries_by_date($glossary, $context, $field, $sortorder, $offset, $pagelimit);