Exemple #1
0
/**
 * Mark the activity completed (if required) and trigger the course_module_viewed event.
 *
 * @param  stdClass $choice     choice object
 * @param  stdClass $course     course object
 * @param  stdClass $cm         course module object
 * @param  stdClass $context    context object
 * @since Moodle 3.0
 */
function choice_view($choice, $course, $cm, $context) {

    // Trigger course_module_viewed event.
    $params = array(
        'context' => $context,
        'objectid' => $choice->id
    );

    $event = \mod_choice\event\course_module_viewed::create($params);
    $event->add_record_snapshot('course_modules', $cm);
    $event->add_record_snapshot('course', $course);
    $event->add_record_snapshot('choice', $choice);
    $event->trigger();

    // Completion.
    $completion = new completion_info($course);
    $completion->set_module_viewed($cm);
}
Exemple #2
0
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($choice->name), 2, null);
if ($notify and confirm_sesskey()) {
    if ($notify === 'choicesaved') {
        echo $OUTPUT->notification(get_string('choicesaved', 'choice'), 'notifysuccess');
    } else {
        if ($notify === 'mustchooseone') {
            echo $OUTPUT->notification(get_string('mustchooseone', 'choice'), 'notifyproblem');
        }
    }
}
/// Display the choice and possibly results
$eventdata = array();
$eventdata['objectid'] = $choice->id;
$eventdata['context'] = $context;
$event = \mod_choice\event\course_module_viewed::create($eventdata);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->trigger();
/// Check to see if groups are being used in this choice
$groupmode = groups_get_activity_groupmode($cm);
if ($groupmode) {
    groups_get_activity_group($cm, true);
    groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choice/view.php?id=' . $id);
}
$allresponses = choice_get_response_data($choice, $cm, $groupmode);
// Big function, approx 6 SQL calls per user
if (has_capability('mod/choice:readresponses', $context)) {
    choice_show_reportlink($allresponses, $cm);
}
echo '<div class="clearer"></div>';
Exemple #3
0
 /**
  * Test to ensure that event data is being stored correctly.
  */
 public function test_course_module_viewed()
 {
     global $USER;
     // Generate user data.
     $this->setAdminUser();
     $eventdata = array();
     $eventdata['objectid'] = $this->choice->id;
     $eventdata['context'] = $this->context;
     $eventdata['courseid'] = $this->course->id;
     $eventdata['other']['content'] = 'pageresourceview';
     // This is fired in a page view so we can't run this through a function.
     $event = \mod_choice\event\course_module_viewed::create($eventdata);
     // Redirect event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $event = $sink->get_events();
     // Data checking.
     $this->assertCount(1, $event);
     $this->assertInstanceOf('\\mod_choice\\event\\course_module_viewed', $event[0]);
     $this->assertEquals($USER->id, $event[0]->userid);
     $this->assertEquals(context_module::instance($this->choice->cmid), $event[0]->get_context());
     $expected = array($this->course->id, "choice", "view", 'view.php?id=' . $this->context->instanceid, $this->choice->id, $this->context->instanceid);
     $this->assertEventLegacyLogData($expected, $event[0]);
     $this->assertEventContextNotUsed($event[0]);
     $sink->close();
 }