first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+154
View File
@@ -0,0 +1,154 @@
<?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/>.
/**
* The mod_choice answer created event.
*
* @package mod_choice
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice answer created event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int choiceid: id of choice.
* - int optionid: id of the option.
* }
*
* @package mod_choice
* @since Moodle 3.2
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class answer_created extends \core\event\base {
/**
* Creates an instance of the event from the records
*
* @param stdClass $choiceanswer record from 'choice_answers' table
* @param stdClass $choice record from 'choice' table
* @param stdClass $cm record from 'course_modules' table
* @param stdClass $course
* @return self
*/
public static function create_from_object($choiceanswer, $choice, $cm, $course) {
global $USER;
$eventdata = array();
$eventdata['objectid'] = $choiceanswer->id;
$eventdata['context'] = \context_module::instance($cm->id);
$eventdata['userid'] = $USER->id;
$eventdata['courseid'] = $course->id;
$eventdata['relateduserid'] = $choiceanswer->userid;
$eventdata['other'] = array();
$eventdata['other']['choiceid'] = $choice->id;
$eventdata['other']['optionid'] = $choiceanswer->optionid;
$event = self::create($eventdata);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('choice', $choice);
$event->add_record_snapshot('choice_answers', $choiceanswer);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has added the option with id '" . $this->other['optionid'] . "' for the
user with id '$this->relateduserid' from the choice activity with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventanswercreated', 'mod_choice');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/choice/view.php', array('id' => $this->contextinstanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['objecttable'] = 'choice_answers';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['choiceid'])) {
throw new \coding_exception('The \'choiceid\' value must be set in other.');
}
if (!isset($this->other['optionid'])) {
throw new \coding_exception('The \'optionid\' value must be set in other.');
}
}
/**
* This is used when restoring course logs where it is required that we
* map the objectid to it's new value in the new course.
*
* @return string the name of the restore mapping the objectid links to
*/
public static function get_objectid_mapping() {
return array('db' => 'choice_answers', 'restore' => 'answer');
}
/**
* This is used when restoring course logs where it is required that we
* map the information in 'other' to it's new value in the new course.
*
* @return array an array of other values and their corresponding mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['choiceid'] = array('db' => 'choice', 'restore' => 'choice');
$othermapped['optionid'] = array('db' => 'choice_options', 'restore' => 'choice_option');
return $othermapped;
}
}
+142
View File
@@ -0,0 +1,142 @@
<?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/>.
/**
* The mod_choice answer deleted event.
*
* @package mod_choice
* @copyright 2016 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice answer deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int choiceid: id of choice.
* - int optionid: id of the option.
* }
*
* @package mod_choice
* @since Moodle 3.1
* @copyright 2016 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class answer_deleted extends \core\event\base {
/**
* Creates an instance of the event from the records
*
* @param stdClass $choiceanswer record from 'choice_answers' table
* @param stdClass $choice record from 'choice' table
* @param stdClass $cm record from 'course_modules' table
* @param stdClass $course
* @return self
*/
public static function create_from_object($choiceanswer, $choice, $cm, $course) {
global $USER;
$eventdata = array();
$eventdata['objectid'] = $choiceanswer->id;
$eventdata['context'] = \context_module::instance($cm->id);
$eventdata['userid'] = $USER->id;
$eventdata['courseid'] = $course->id;
$eventdata['relateduserid'] = $choiceanswer->userid;
$eventdata['other'] = array();
$eventdata['other']['choiceid'] = $choice->id;
$eventdata['other']['optionid'] = $choiceanswer->optionid;
$event = self::create($eventdata);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('choice', $choice);
$event->add_record_snapshot('choice_answers', $choiceanswer);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has deleted the option with id '" . $this->other['optionid'] . "' for the
user with id '$this->relateduserid' from the choice activity with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventanswerdeleted', 'mod_choice');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/choice/view.php', array('id' => $this->contextinstanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['objecttable'] = 'choice_answers';
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['choiceid'])) {
throw new \coding_exception('The \'choiceid\' value must be set in other.');
}
if (!isset($this->other['optionid'])) {
throw new \coding_exception('The \'optionid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'choice_answers', 'restore' => \core\event\base::NOT_MAPPED);
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['choiceid'] = array('db' => 'choice', 'restore' => 'choice');
$othermapped['optionid'] = array('db' => 'choice_options', 'restore' => 'choice_option');
return $othermapped;
}
}
@@ -0,0 +1,136 @@
<?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/>.
/**
* The mod_choice answer submitted event.
*
* @package mod_choice
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice answer submitted event class.
*
* This event is deprecated in Moodle 3.2, it can no longer be triggered, do not
* write event observers for it. This event can only be initiated during
* restore from previous Moodle versions and appear in the logs.
*
* Event observers should listen to mod_choice\event\answer_created instead that
* will be triggered once for each option selected
*
* @property-read array $other {
* Extra information about event.
*
* - int choiceid: id of choice.
* - int optionid: (optional) id of option.
* }
*
* @deprecated since 3.2
* @package mod_choice
* @since Moodle 2.6
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class answer_submitted extends \core\event\base {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' made the choice with id '$this->objectid' in the choice activity
with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventanswersubmitted', 'mod_choice');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/choice/view.php', array('id' => $this->contextinstanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
// The objecttable here is wrong. We are submitting an answer, not a choice activity.
// This also makes the description misleading as it states we made a choice with id
// '$this->objectid' which just refers to the 'choice' table. The trigger for
// this event should be triggered after we insert to the 'choice_answers' table.
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'choice';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
debugging('Event \\mod_choice\event\\answer_submitted should not be used '
. 'any more for triggering new events and can only be initiated during restore. '
. 'For new events please use \\mod_choice\\event\\answer_created', DEBUG_DEVELOPER);
if (!isset($this->other['choiceid'])) {
throw new \coding_exception('The \'choiceid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'choice', 'restore' => 'choice');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['choiceid'] = array('db' => 'choice', 'restore' => 'choice');
// The 'optionid' is being passed as an array, so we can't map it. The event is
// triggered each time a choice is answered, where it may be possible to select
// multiple choices, so the value is converted to an array, which is then passed
// to the event. Ideally this event should be triggered every time we insert to the
// 'choice_answers' table so this will only be an int.
$othermapped['optionid'] = \core\event\base::NOT_MAPPED;
return $othermapped;
}
public static function is_deprecated() {
return true;
}
}
+138
View File
@@ -0,0 +1,138 @@
<?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/>.
/**
* The mod_choice answer updated event.
*
* @package mod_choice
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice answer updated event class.
*
* This event is deprecated in Moodle 3.2, it can no longer be triggered, do not
* write event observers for it. This event can only be initiated during
* restore from previous Moodle versions and appear in the logs.
*
* Event observers should listen to mod_choice\event\answer_created and
* mod_choice\event\answer_deleted instead, these events will be triggered for
* each option that was user has selected or unselected
*
* @property-read array $other {
* Extra information about event.
*
* - int choiceid: id of choice.
* - int optionid: (optional) id of option.
* }
*
* @deprecated since 3.2
* @package mod_choice
* @since Moodle 2.6
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class answer_updated extends \core\event\base {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated their choice with id '$this->objectid' in the choice activity
with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventanswerupdated', 'mod_choice');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/choice/view.php', array('id' => $this->contextinstanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
// The objecttable here is wrong. We are updating an answer, not a choice activity.
// This also makes the description misleading as it states we made a choice with id
// '$this->objectid' which just refers to the 'choice' table. The trigger for
// this event should be triggered after we update the 'choice_answers' table.
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'choice';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
debugging('Event \\mod_choice\event\\answer_updated should not be used '
. 'any more for triggering new events and can only be initiated during restore. '
. 'For new events please use \\mod_choice\\event\\answer_created '
. 'and \\mod_choice\\event\\answer_deleted', DEBUG_DEVELOPER);
if (!isset($this->other['choiceid'])) {
throw new \coding_exception('The \'choiceid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'choice', 'restore' => 'choice');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['choiceid'] = array('db' => 'choice', 'restore' => 'choice');
// The 'optionid' is being passed as an array, so we can't map it. The event is
// triggered each time a choice is answered, where it may be possible to select
// multiple choices, so the value is converted to an array, which is then passed
// to the event. Ideally this event should be triggered every time we update the
// 'choice_answers' table so this will only be an int.
$othermapped['optionid'] = \core\event\base::NOT_MAPPED;
return $othermapped;
}
public static function is_deprecated() {
return true;
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* The mod_choice instance list viewed event.
*
* @package mod_choice
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice instance list viewed event class.
*
* @package mod_choice
* @since Moodle 2.7
* @copyright 2013 onwards 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 {
}
@@ -0,0 +1,50 @@
<?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/>.
/**
* The mod_choice course module viewed event.
*
* @package mod_choice
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice course module viewed event class.
*
* @package mod_choice
* @since Moodle 2.6
* @copyright 2013 Adrian Greeve
* @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['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'choice';
}
public static function get_objectid_mapping() {
return array('db' => 'choice', 'restore' => 'choice');
}
}
@@ -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/>.
/**
* The mod_choice report viewed event.
*
* @package mod_choice
* @copyright 2016 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice report viewed event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - string content: The content we are viewing.
* - string format: The report format
* - int choiced: The id of the choice
* }
*
* @package mod_choice
* @since Moodle 3.1
* @copyright 2016 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_downloaded extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventreportdownloaded', 'mod_choice');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has downloaded the report in the '".$this->other['format']."' format for
the choice activity with course module id '$this->contextinstanceid'";
}
/**
* Returns relevant URL.
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/choice/report.php', array('id' => $this->contextinstanceid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Report format downloaded.
if (!isset($this->other['content'])) {
throw new \coding_exception('The \'content\' value must be set in other.');
}
// Report format downloaded.
if (!isset($this->other['format'])) {
throw new \coding_exception('The \'format\' value must be set in other.');
}
// ID of the choice activity.
if (!isset($this->other['choiceid'])) {
throw new \coding_exception('The \'choiceid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return false;
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['choiceid'] = array('db' => 'choice', 'restore' => 'choice');
return $othermapped;
}
}
@@ -0,0 +1,88 @@
<?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/>.
/**
* The mod_choice report viewed event.
*
* @package mod_choice
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_choice report viewed event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - string content: (optional) The content we are viewing.
* }
*
* @package mod_choice
* @since Moodle 2.6
* @copyright 2013 Adrian Greeve
* @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['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'choice';
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventreportviewed', 'mod_choice');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has viewed the report for the choice activity with course module id
'$this->contextinstanceid'";
}
/**
* Returns relevant URL.
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/choice/report.php', array('id' => $this->contextinstanceid));
}
public static function get_objectid_mapping() {
return array('db' => 'choice', 'restore' => 'choice');
}
public static function get_other_mapping() {
// No need to map the 'content' value.
return false;
}
}