public function test_glossary_view() { global $CFG; $origcompletion = $CFG->enablecompletion; $CFG->enablecompletion = true; $this->resetAfterTest(true); // Generate all the things. $c1 = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $g1 = $this->getDataGenerator()->create_module('glossary', array('course' => $c1->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1)); $g2 = $this->getDataGenerator()->create_module('glossary', array('course' => $c1->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1)); $u1 = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($u1->id, $c1->id); $modinfo = course_modinfo::instance($c1->id); $cm1 = $modinfo->get_cm($g1->cmid); $cm2 = $modinfo->get_cm($g2->cmid); $ctx1 = $cm1->context; $completion = new completion_info($c1); $this->setUser($u1); // Confirm what we've set up. $this->assertEquals(COMPLETION_NOT_VIEWED, $completion->get_data($cm1, false, $u1->id)->viewed); $this->assertEquals(COMPLETION_INCOMPLETE, $completion->get_data($cm1, false, $u1->id)->completionstate); $this->assertEquals(COMPLETION_NOT_VIEWED, $completion->get_data($cm2, false, $u1->id)->viewed); $this->assertEquals(COMPLETION_INCOMPLETE, $completion->get_data($cm2, false, $u1->id)->completionstate); // Simulate the view call. $sink = $this->redirectEvents(); glossary_view($g1, $c1, $cm1, $ctx1, 'letter'); $events = $sink->get_events(); // Assertions. $this->assertCount(3, $events); $this->assertEquals('\\core\\event\\course_module_completion_updated', $events[0]->eventname); $this->assertEquals('\\core\\event\\course_module_completion_updated', $events[1]->eventname); $this->assertEquals('\\mod_glossary\\event\\course_module_viewed', $events[2]->eventname); $this->assertEquals($g1->id, $events[2]->objectid); $this->assertEquals('letter', $events[2]->other['mode']); $this->assertEquals(COMPLETION_VIEWED, $completion->get_data($cm1, false, $u1->id)->viewed); $this->assertEquals(COMPLETION_COMPLETE, $completion->get_data($cm1, false, $u1->id)->completionstate); $this->assertEquals(COMPLETION_NOT_VIEWED, $completion->get_data($cm2, false, $u1->id)->viewed); $this->assertEquals(COMPLETION_INCOMPLETE, $completion->get_data($cm2, false, $u1->id)->completionstate); // Tear down. $sink->close(); $CFG->enablecompletion = $origcompletion; }
/** * Notify that the course module was viewed. * * @param int $id The glossary instance ID. * @param string $mode The view mode. * @return array of warnings and status result * @since Moodle 3.1 * @throws moodle_exception */ public static function view_glossary($id, $mode) { $params = self::validate_parameters(self::view_glossary_parameters(), array('id' => $id, 'mode' => $mode)); $id = $params['id']; $mode = $params['mode']; $warnings = array(); // Get and validate the glossary. list($glossary, $context, $course, $cm) = self::validate_glossary($id); // Trigger module viewed event. glossary_view($glossary, $course, $cm, $context, $mode); return array('status' => true, 'warnings' => $warnings); }
public function test_course_check_module_updates_since() { global $CFG, $DB, $USER; require_once $CFG->dirroot . '/mod/glossary/lib.php'; require_once $CFG->dirroot . '/rating/lib.php'; require_once $CFG->dirroot . '/comment/lib.php'; $this->resetAfterTest(true); $CFG->enablecompletion = true; $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1, 'allowcomments' => 1, 'assessed' => RATING_AGGREGATE_AVERAGE, 'scale' => 100)); $glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary'); $context = context_module::instance($glossary->cmid); $modinfo = get_fast_modinfo($course); $cm = $modinfo->get_cm($glossary->cmid); $user = $this->getDataGenerator()->create_user(); $studentrole = $DB->get_record('role', array('shortname' => 'student')); $this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id); $from = time(); $teacher = $this->getDataGenerator()->create_user(); $teacherrole = $DB->get_record('role', array('shortname' => 'teacher')); $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id); assign_capability('mod/glossary:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id, true); // Check nothing changed right now. $updates = course_check_module_updates_since($cm, $from); $this->assertFalse($updates->configuration->updated); $this->assertFalse($updates->completion->updated); $this->assertFalse($updates->gradeitems->updated); $this->assertFalse($updates->comments->updated); $this->assertFalse($updates->ratings->updated); $this->assertFalse($updates->introfiles->updated); $this->assertFalse($updates->outcomes->updated); $this->waitForSecond(); // Do some changes. $this->setUser($user); $entry = $glossarygenerator->create_content($glossary); $this->setUser($teacher); // Name. set_coursemodule_name($glossary->cmid, 'New name'); // Add some ratings. $rm = new rating_manager(); $result = $rm->add_rating($cm, $context, 'mod_glossary', 'entry', $entry->id, 100, 50, $user->id, RATING_AGGREGATE_AVERAGE); // Change grades. $glossary->cmidnumber = $glossary->cmid; glossary_update_grades($glossary, $user->id); $this->setUser($user); // Completion status. glossary_view($glossary, $course, $cm, $context, 'letter'); // Add one comment. $args = new stdClass(); $args->context = $context; $args->course = $course; $args->cm = $cm; $args->area = 'glossary_entry'; $args->itemid = $entry->id; $args->client_id = 1; $args->component = 'mod_glossary'; $manager = new comment($args); $manager->add('blah blah blah'); // Check upgrade status. $updates = course_check_module_updates_since($cm, $from); $this->assertTrue($updates->configuration->updated); $this->assertTrue($updates->completion->updated); $this->assertTrue($updates->gradeitems->updated); $this->assertTrue($updates->comments->updated); $this->assertTrue($updates->ratings->updated); $this->assertFalse($updates->introfiles->updated); $this->assertFalse($updates->outcomes->updated); }
$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. glossary_view($glossary, $course, $cm, $context, $mode); /// 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"); $strwaitingapproval = get_string('waitingapproval', 'glossary'); /// If we are in approval mode, prit special header $PAGE->set_title($glossary->name); $PAGE->set_heading($course->fullname); $url = new moodle_url('/mod/glossary/view.php', array('id' => $cm->id)); if (isset($mode)) { $url->param('mode', $mode);