MDL-40056 events: Created Event classes to replace add_to_log() - mod_scorm

Created attempt_deleted event
Created interactions_viewed event
Created report_viewed event
Created sco_launched event
Created tracks_viewed event
Created user_report_viewed event
Created course module related events
This commit is contained in:
Ankit Agarwal 2014-01-07 14:06:26 +08:00
parent 8a0667a994
commit a501fe1385
8 changed files with 723 additions and 0 deletions

View File

@ -0,0 +1,99 @@
<?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/>.
/**
* This file contains an event for when attempts are deleted.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when attempts are deleted.
*
* @property-read array $other {
* Extra information about event properties.
*
* @type int attemptid Attempt id.
* }
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class attempt_deleted extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['level'] = self::LEVEL_TEACHING;
}
/**
* Returns non-localised description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' deleted attempt for scorm activity with attemptid ' . $this->other['attemptid'];
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventattemptdeleted', 'mod_scorm');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/scorm/report.php', array('id' => $this->context->instanceid));
}
/**
* Replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'scorm', 'delete attempts', 'report.php?id=' . $this->context->instanceid,
$this->other['attemptid'], $this->context->instanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (empty($this->other['attemptid'])) {
throw new \coding_exception('The event must specify attemptid.');
}
parent::validate_data();
}
}

View File

@ -0,0 +1,37 @@
<?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/>.
/**
* mod_scorm course module instances list viewed event.
*
* @package mod_scorm
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* mod_scorm course module instances list viewed event class.
*
* @package mod_scorm
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
}

View File

@ -0,0 +1,56 @@
<?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/>.
/**
* This file contains an event for when a scorm activity is viewed.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a scorm activity is viewed.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'scorm';
}
/**
* Replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'scorm', 'pre-view', 'view.php?id=' . $this->context->instanceid, $this->objectid,
$this->context->instanceid);
}
}

View File

@ -0,0 +1,108 @@
<?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/>.
/**
* This file contains an event for when user interactions is viewed.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a user interactions are viewed.
*
* @property-read array $other {
* Extra information about event properties.
*
* @type int attemptid Attempt id.
* @type int instanceid Instance id of the scorm activity.
* }
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class interactions_viewed extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_TEACHING;
}
/**
* Returns non-localised description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' viewed interactions for user ' . $this->relateduserid;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventinteractionsviewed', 'mod_scorm');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
$params = array(
'id' => $this->context->instanceid,
'user' => $this->relateduserid,
'attempt' => $this->other['attemptid']
);
return new \moodle_url('/mod/scorm/userreportinteractions.php', $params);
}
/**
* Return the legacy event log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'scorm', 'userreportinteractions', 'report/userreportinteractions.php?id=' .
$this->context->instanceid . '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'],
$this->other['instanceid'], $this->context->instanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (empty($this->other['attemptid'])) {
throw new \coding_exception('The \\mod_scorm\\event\\interactions_viewed must specify attemptid.');
}
if (empty($this->other['instanceid'])) {
throw new \coding_exception('The \\mod_scorm\\event\\interactions_viewed must specify instanceid of the activity.');
}
}
}

View File

@ -0,0 +1,100 @@
<?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/>.
/**
* This file contains an event for when a scorm report is viewed.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a scorm report is viewed.
*
* @property-read array $other {
* Extra information about event properties.
*
* @string mode Mode of the report viewed.
* }
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_viewed extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'scorm';
}
/**
* Returns non-localised description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' viewed scorm report (' . $this->other['mode'] . ') with instanceid ' .
$this->objectid;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventreportviewed', 'mod_scorm');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/scorm/report.php', array('id' => $this->context->instanceid, 'mode' => $this->other['mode']));
}
/**
* Replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'scorm', 'report', 'report.php?id=' . $this->context->instanceid .
'&mode=' . $this->other['mode'], $this->objectid, $this->context->instanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (empty($this->other['mode'])) {
throw new \coding_exception('The event must specify mode to define which report was viewed.');
}
}
}

View File

@ -0,0 +1,101 @@
<?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/>.
/**
* This file contains an event for when sco is loaded.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a sco is loaded.
*
* @property-read array $other {
* Extra information about event properties.
*
* @type string loadedcontent A reference to the content loaded.
* @type int instanceid Instance id of the scorm activity.
* }
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sco_launched extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'scorm_scoes';
}
/**
* Returns non-localised description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' launched a sco with id ' . $this->objectid;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventscolaunched', 'mod_scorm');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/scorm/player.php', array('id' => $this->context->instanceid, 'scoid' => $this->objectid));
}
/**
* Replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'scorm', 'launch', 'view.php?id=' . $this->context->instanceid,
$this->other['loadedcontent'], $this->context->instanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (empty($this->other['loadedcontent'])) {
throw new \coding_exception('The event mod_scorm\\event\\sco_launched must specify loadedcontent.');
}
}
}

View File

@ -0,0 +1,114 @@
<?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/>.
/**
* This file contains an event for when user tracks is viewed.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a user tracks is viewed.
*
* @property-read array $other {
* Extra information about event properties.
*
* @type int attemptid Attempt id.
* @type int instanceid Instance id of the scorm activity.
* @type int scoid Sco Id for which the trackes are viewed.
* }
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tracks_viewed extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_TEACHING;
}
/**
* Returns non-localised description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' viewed interactions for user ' . $this->relateduserid;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventtracksviewed', 'mod_scorm');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
$params = array(
'id' => $this->context->instanceid,
'user' => $this->relateduserid,
'attempt' => $this->other['attemptid'],
'scoid' => $this->other['scoid']
);
return new \moodle_url('/mod/scorm/userreporttracks.php', $params);
}
/**
* Return the legacy event log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'scorm', 'userreporttracks', 'report/userreporttracks.php?id=' . $this->context->instanceid
. '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'] . '&scoid=' . $this->other['scoid'],
$this->other['instanceid'], $this->context->instanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (empty($this->other['attemptid'])) {
throw new \coding_exception('The \\mod_scorm\\event\\tracks_viewed must specify attemptid.');
}
if (empty($this->other['instanceid'])) {
throw new \coding_exception('The \\mod_scorm\\event\\tracks_viewed must specify instanceid of the activity.');
}
if (empty($this->other['scoid'])) {
throw new \coding_exception('The \\mod_scorm\\event\\tracks_viewed must specify scoid for the report.');
}
parent::validate_data();
}
}

View File

@ -0,0 +1,108 @@
<?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/>.
/**
* This file contains an event for when a user report is viewed.
*
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a user report is viewed.
*
* @property-read array $other {
* Extra information about event properties.
*
* @type int attemptid Attempt id.
* @type int instanceid Instance id of the scorm activity.
* }
* @package mod_scorm
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_report_viewed extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_TEACHING;
}
/**
* Returns non-localised description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' viewed user report for user ' . $this->relateduserid;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventuserreportviewed', 'mod_scorm');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
$params = array(
'id' => $this->context->instanceid,
'user' => $this->relateduserid,
'attempt' => $this->other['attemptid']
);
return new \moodle_url('/mod/scorm/userreport.php', $params);
}
/**
* Return the legacy event log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'scorm', 'userreport', 'report/userreport.php?id=' .
$this->context->instanceid . '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'],
$this->other['instanceid'], $this->context->instanceid);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (empty($this->other['attemptid'])) {
throw new \coding_exception('The \\mod_scorm\\event\\user_report_viewed must specify attemptid.');
}
if (empty($this->other['instanceid'])) {
throw new \coding_exception('The \\mod_scorm\\event\\user_report_viewed must specify instanceid of the activity.');
}
}
}