Beispiel #1
0
 /**
  * Browse a glossary entries by category.
  *
  * @param int $id The glossary ID.
  * @param int $categoryid The category ID.
  * @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_category($id, $categoryid, $from, $limit, $options)
 {
     global $DB;
     $params = self::validate_parameters(self::get_entries_by_category_parameters(), array('id' => $id, 'categoryid' => $categoryid, 'from' => $from, 'limit' => $limit, 'options' => $options));
     $id = $params['id'];
     $categoryid = $params['categoryid'];
     $from = $params['from'];
     $limit = $params['limit'];
     $options = $params['options'];
     $warnings = array();
     // 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('cat', $modes)) {
         throw new invalid_parameter_exception('invalidbrowsemode');
     }
     // Validate the category.
     if (in_array($categoryid, array(GLOSSARY_SHOW_ALL_CATEGORIES, GLOSSARY_SHOW_NOT_CATEGORISED))) {
         // All good.
     } else {
         if (!$DB->record_exists('glossary_categories', array('id' => $categoryid, 'glossaryid' => $id))) {
             throw new invalid_parameter_exception('invalidcategory');
         }
     }
     // Fetching the entries.
     $entries = array();
     list($records, $count) = glossary_get_entries_by_category($glossary, $context, $categoryid, $from, $limit, $options);
     foreach ($records as $key => $record) {
         self::fill_entry_details($record, $context);
         if ($record->categoryid === null) {
             $record->categoryid = GLOSSARY_SHOW_NOT_CATEGORISED;
         }
         if (isset($record->categoryname)) {
             $record->categoryname = external_format_string($record->categoryname, $context->id);
         }
         $entries[] = $record;
     }
     return array('count' => $count, 'entries' => $entries, 'warnings' => $warnings);
 }
Beispiel #2
0
 */
$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);
        unset($field);
        break;
    case GLOSSARY_APPROVAL_VIEW:
        $fullpivot = false;
        $printpivot = false;
        list($allentries, $count) = glossary_get_entries_to_approve($glossary, $context, $hook, $sortkey, $sortorder, $offset, $pagelimit);