예제 #1
0
 /**
  * Test course_module_viewed event.
  */
 public function test_course_module_viewed()
 {
     // 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();
     $resource = $this->getDataGenerator()->create_module('resource', array('course' => $course->id));
     $params = array('context' => context_module::instance($resource->cmid), 'objectid' => $resource->id);
     $event = \mod_resource\event\course_module_viewed::create($params);
     // 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_resource\\event\\course_module_viewed', $event);
     $this->assertEquals(context_module::instance($resource->cmid), $event->get_context());
     $this->assertEquals($resource->id, $event->objectid);
     $expected = array($course->id, 'resource', 'view', 'view.php?id=' . $resource->cmid, $resource->id, $resource->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
 }
예제 #2
0
파일: lib.php 프로젝트: nnnguyen/moodletest
/**
 * Mark the activity completed (if required) and trigger the course_module_viewed event.
 *
 * @param  stdClass $resource   resource object
 * @param  stdClass $course     course object
 * @param  stdClass $cm         course module object
 * @param  stdClass $context    context object
 * @since Moodle 3.0
 */
function resource_view($resource, $course, $cm, $context) {

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

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

    // Completion.
    $completion = new completion_info($course);
    $completion->set_module_viewed($cm);
}
예제 #3
0
        print_error('invalidcoursemodule');
    }
    $opencast = $DB->get_record('opencast', array('id'=>$cm->instance), '*', MUST_EXIST);
}

$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);

require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/resource:view', $context);

$params = array(
    'context' => $context,
    'objectid' => $opencast->id
);
$event = \mod_resource\event\course_module_viewed::create($params);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('opencast', $opencast);
$event->trigger();

// Update 'viewed' state if required by completion system
$completion = new completion_info($course);
$completion->set_module_viewed($cm);

$PAGE->set_url('/mod/opencast/view.php', array('id' => $cm->id));

$media = get_episode_mediainfo($opencast->eventid);
echo $OUTPUT->header();
echo "<h2>$opencast->name</h2>";
 /**
  * Read media resource
  *
  * @throws \coding_exception
  * @return stdClass
  */
 private function read_media()
 {
     global $PAGE, $COURSE, $DB;
     $cm = $PAGE->cm;
     $context = \context_module::instance($cm->id);
     // Trigger module instance viewed event.
     $event = \mod_resource\event\course_module_viewed::create(array('objectid' => $cm->instance, 'context' => $context));
     $resource = $DB->get_record('resource', array('id' => $cm->instance));
     $event->add_record_snapshot('course_modules', $cm);
     $event->add_record_snapshot('course', $COURSE);
     $event->add_record_snapshot('resource', $resource);
     $event->trigger();
     $resource->content = $this->get_media_html($resource, $context, $cm);
     // Update 'viewed' state if required by completion system.
     $completion = new \completion_info($COURSE);
     $completion->set_module_viewed($cm);
     $renderer = $PAGE->get_renderer('core', 'course');
     $resource->completionhtml = $renderer->course_section_cm_completion($COURSE, $completion, $cm);
     return $resource;
 }