예제 #1
0
파일: lib.php 프로젝트: fliphess/moodle
/**
 * Notify that the glossary was viewed.
 *
 * This will trigger relevant events and activity completion.
 *
 * @param stdClass $glossary The glossary object.
 * @param stdClass $course   The course object.
 * @param stdClass $cm       The course module object.
 * @param stdClass $context  The context object.
 * @param string   $mode     The mode in which the glossary was viewed.
 * @since Moodle 3.1
 */
function glossary_view($glossary, $course, $cm, $context, $mode)
{
    // Completion trigger.
    $completion = new completion_info($course);
    $completion->set_module_viewed($cm);
    // Trigger the course module viewed event.
    $event = \mod_glossary\event\course_module_viewed::create(array('objectid' => $glossary->id, 'context' => $context, 'other' => array('mode' => $mode)));
    $event->add_record_snapshot('course', $course);
    $event->add_record_snapshot('course_modules', $cm);
    $event->add_record_snapshot('glossary', $glossary);
    $event->trigger();
}
예제 #2
0
 public function test_course_module_viewed()
 {
     global $DB;
     // There is no proper API to call to trigger this event, so what we are
     // doing here is simply making sure that the events returns the right information.
     $course = $this->getDataGenerator()->create_course();
     $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id));
     $dbcourse = $DB->get_record('course', array('id' => $course->id));
     $dbglossary = $DB->get_record('glossary', array('id' => $glossary->id));
     $context = context_module::instance($glossary->cmid);
     $mode = 'letter';
     $event = \mod_glossary\event\course_module_viewed::create(array('objectid' => $dbglossary->id, 'context' => $context, 'other' => array('mode' => $mode)));
     $event->add_record_snapshot('course', $dbcourse);
     $event->add_record_snapshot('glossary', $dbglossary);
     // Triggering and capturing the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_glossary\\event\\course_module_viewed', $event);
     $this->assertEquals(CONTEXT_MODULE, $event->contextlevel);
     $this->assertEquals($glossary->cmid, $event->contextinstanceid);
     $this->assertEquals($glossary->id, $event->objectid);
     $expected = array($course->id, 'glossary', 'view', 'view.php?id=' . $glossary->cmid . '&tab=-1', $glossary->id, $glossary->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEquals(new moodle_url('/mod/glossary/view.php', array('id' => $glossary->cmid, 'mode' => $mode)), $event->get_url());
     $this->assertEventContextNotUsed($event);
 }
예제 #3
0
            $hook = 'ALL';
        }
        break;
}
switch ($tab) {
    case GLOSSARY_IMPORT_VIEW:
    case GLOSSARY_EXPORT_VIEW:
    case GLOSSARY_APPROVAL_VIEW:
        $showcommonelements = 0;
        break;
    default:
        $showcommonelements = 1;
        break;
}
// Trigger module viewed event.
$event = \mod_glossary\event\course_module_viewed::create(array('objectid' => $glossary->id, 'context' => $context, 'other' => array('mode' => $mode)));
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('glossary', $glossary);
$event->trigger();
// Mark as viewed
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
/// Printing the heading
$strglossaries = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary");
$strallcategories = get_string("allcategories", "glossary");
$straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");