Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
 /**
  * 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) = self::validate_glossary($entry->glossaryid);
     if (empty($entry->approved) && $entry->userid != $USER->id && !has_capability('mod/glossary:approve', $context)) {
         throw new invalid_parameter_exception('invalidentry');
     }
     // Trigger view.
     glossary_entry_view($entry, $context);
     return array('status' => true, 'warnings' => $warnings);
 }
        if (!$entry->approved and $USER->id != $entry->userid) {
            $context = context_module::instance($entry->cmid);
            if (!has_capability('mod/glossary:approve', $context)) {
                unset($entries[$key]);
                continue;
            }
        }
        // Make sure entry is not autolinking itself.
        $GLOSSARY_EXCLUDEENTRY = $entry->id;
        $context = context_module::instance($entry->cmid);
        $definition = file_rewrite_pluginfile_urls($entry->definition, 'pluginfile.php', $context->id, 'mod_glossary', 'entry', $entry->id);
        $options = new stdClass();
        $options->para = false;
        $options->trusted = $entry->definitiontrust;
        $options->context = $context;
        $entries[$key]->definition = format_text($definition, $entry->definitionformat, $options);
        $entries[$key]->attachments = '';
        if (!empty($entries[$key]->attachment)) {
            $attachments = glossary_print_attachments($entry, $cm, 'html');
            $entries[$key]->attachments = html_writer::tag('p', $attachments);
        }
        $entries[$key]->footer = "<p style=\"text-align:right\">&raquo;&nbsp;<a href=\"{$CFG->wwwroot}/mod/glossary/view.php?g={$entry->glossaryid}\">" . format_string($entry->glossaryname, true) . "</a></p>";
        glossary_entry_view($entry, $modinfo->cms[$entry->cmid]->context);
    }
}
echo $OUTPUT->header();
$result = new stdClass();
$result->success = true;
$result->entries = $entries;
echo json_encode($result);
echo $OUTPUT->footer();
Beispiel #4
0
 public function test_glossary_entry_view()
 {
     $this->resetAfterTest(true);
     // Generate all the things.
     $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
     $c1 = $this->getDataGenerator()->create_course();
     $g1 = $this->getDataGenerator()->create_module('glossary', array('course' => $c1->id));
     $e1 = $gg->create_content($g1);
     $u1 = $this->getDataGenerator()->create_user();
     $ctx = context_module::instance($g1->cmid);
     $this->getDataGenerator()->enrol_user($u1->id, $c1->id);
     // Assertions.
     $sink = $this->redirectEvents();
     glossary_entry_view($e1, $ctx);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $this->assertEquals('\\mod_glossary\\event\\entry_viewed', $events[0]->eventname);
     $this->assertEquals($e1->id, $events[0]->objectid);
     $sink->close();
 }