MDL-50427 mod_scorm: Move logging and completion to new API

This commit is contained in:
Juan Leyva
2015-07-20 09:13:42 +02:00
parent e1d4e288ac
commit ade341deb2
3 changed files with 106 additions and 8 deletions
+25
View File
@@ -1440,3 +1440,28 @@ function scorm_check_mode($scorm, &$newattempt, &$attempt, $userid, &$mode) {
}
}
}
/**
* Trigger the course_module_viewed event.
*
* @param stdClass $scorm scorm object
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @since Moodle 3.0
*/
function scorm_view($scorm, $course, $cm, $context) {
// Trigger course_module_viewed event.
$params = array(
'context' => $context,
'objectid' => $scorm->id
);
$event = \mod_scorm\event\course_module_viewed::create($params);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('scorm', $scorm);
$event->trigger();
}
+79
View File
@@ -0,0 +1,79 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* SCORM module library functions tests
*
* @package mod_scorm
* @category test
* @copyright 2015 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/mod/scorm/lib.php');
/**
* SCORM module library functions tests
*
* @package mod_scorm
* @category test
* @copyright 2015 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
class mod_scorm_lib_testcase extends externallib_advanced_testcase {
/**
* 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());
}
}
+2 -8
View File
@@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/scorm/lib.php');
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
require_once($CFG->dirroot.'/course/lib.php');
@@ -123,14 +124,7 @@ $shortname = format_string($course->shortname, true, array('context' => $context
$pagetitle = strip_tags($shortname.': '.format_string($scorm->name));
// Trigger module viewed event.
$event = \mod_scorm\event\course_module_viewed::create(array(
'objectid' => $scorm->id,
'context' => $contextmodule,
));
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('scorm', $scorm);
$event->add_record_snapshot('course_modules', $cm);
$event->trigger();
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);