/** * Whether the user can access the document or not. * * @throws \dml_missing_record_exception * @throws \dml_exception * @param int $id Glossary entry id * @return bool */ public function check_access($id) { global $USER; try { $entry = $this->get_entry($id); $cminfo = $this->get_cm('glossary', $entry->glossaryid, $entry->course); } catch (\dml_missing_record_exception $ex) { return \core_search\manager::ACCESS_DELETED; } catch (\dml_exception $ex) { return \core_search\manager::ACCESS_DENIED; } if (!glossary_can_view_entry($entry, $cminfo)) { return \core_search\manager::ACCESS_DENIED; } return \core_search\manager::ACCESS_GRANTED; }
/** * Notify that the entry was viewed. * * @param int $id The entry ID. * @return array of warnings and status result * @since Moodle 3.1 * @throws moodle_exception * @throws invalid_parameter_exception */ public static function view_entry($id) { global $DB, $USER; $params = self::validate_parameters(self::view_entry_parameters(), array('id' => $id)); $id = $params['id']; $warnings = array(); // Get and validate the glossary. $entry = $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST); list($glossary, $context, $course, $cm) = self::validate_glossary($entry->glossaryid); if (!glossary_can_view_entry($entry, $cm)) { throw new invalid_parameter_exception('invalidentry'); } // Trigger view. glossary_entry_view($entry, $context); return array('status' => true, 'warnings' => $warnings); }