Example #1
0
    /**
     * Trigger the course module viewed event.
     *
     * @param int $scormid the scorm instance id
     * @return array of warnings and status result
     * @since Moodle 3.0
     * @throws moodle_exception
     */
    public static function view_scorm($scormid) {
        global $DB, $CFG;
        require_once($CFG->dirroot . '/mod/scorm/lib.php');

        $params = self::validate_parameters(self::view_scorm_parameters(),
                                            array(
                                                'scormid' => $scormid
                                            ));
        $warnings = array();

        // Request and permission validation.
        $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($scorm, 'scorm');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        // Call the scorm/lib API.
        scorm_view($scorm, $course, $cm, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
Example #2
0
 /**
  * Test scorm_view
  * @return void
  */
 public function test_scorm_view()
 {
     global $CFG;
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     scorm_view($this->scorm, $this->course, $this->cm, $this->context);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = array_shift($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_scorm\\event\\course_module_viewed', $event);
     $this->assertEquals($this->context, $event->get_context());
     $url = new \moodle_url('/mod/scorm/view.php', array('id' => $this->cm->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
Example #3
0
 /**
  * Test scorm_view
  * @return void
  */
 public function test_scorm_view()
 {
     global $CFG;
     $this->resetAfterTest();
     $this->setAdminUser();
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id));
     $context = context_module::instance($scorm->cmid);
     $cm = get_coursemodule_from_instance('scorm', $scorm->id);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     scorm_view($scorm, $course, $cm, $context);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = array_shift($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_scorm\\event\\course_module_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $url = new \moodle_url('/mod/scorm/view.php', array('id' => $cm->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
Example #4
0
        $courseurl = course_get_url($course, $cm->sectionnum)->out(false);
    }
    $PAGE->requires->data_for_js('scormplayerdata', array('launch' => $launch, 'currentorg' => $orgidentifier, 'sco' => $scoid, 'scorm' => $scorm->id, 'courseurl' => $courseurl, 'cwidth' => $scorm->width, 'cheight' => $scorm->height, 'popupoptions' => $scorm->options), true);
    $PAGE->requires->string_for_js('popupsblocked', 'scorm');
    $PAGE->requires->string_for_js('popuplaunched', 'scorm');
    $PAGE->requires->js('/mod/scorm/view.js', true);
}
if (isset($SESSION->scorm)) {
    unset($SESSION->scorm);
}
$strscorms = get_string("modulenameplural", "scorm");
$strscorm = get_string("modulename", "scorm");
$shortname = format_string($course->shortname, true, array('context' => $context));
$pagetitle = strip_tags($shortname . ': ' . format_string($scorm->name));
// Trigger module viewed event.
scorm_view($scorm, $course, $cm, $contextmodule);
if (empty($preventskip) && empty($launch) && has_capability('mod/scorm:skipview', $contextmodule)) {
    scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);
}
// Print the page header.
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($scorm->name));
if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
    if ($action == 'delete') {
        $confirmurl = new moodle_url($PAGE->url, array('action' => 'deleteconfirm'));
        echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url);
        echo $OUTPUT->footer();
        exit;
    } else {