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
@@ -0,0 +1,65 @@
<?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/>.
/**
* Activity base class.
*
* @package mod_lesson
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Activity base class.
*
* @package mod_lesson
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
/**
* feedback_viewed_events
*
* @return string
*/
protected function feedback_viewed_events() {
return array('\mod_lesson\event\lesson_ended');
}
/**
* feedback_check_grades
*
* @return bool
*/
protected function feedback_check_grades() {
// We don't need to check grades as we get the feedback while completing the activity.
return false;
}
/**
* Returns the name of the field that controls activity availability.
*
* @return null|string
*/
protected function get_timeclose_field() {
return 'deadline';
}
}
@@ -0,0 +1,90 @@
<?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/>.
/**
* Cognitive depth indicator - lesson.
*
* @package mod_lesson
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Cognitive depth indicator - lesson.
*
* @package mod_lesson
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cognitive_depth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:cognitivedepth', 'mod_lesson');
}
public function get_indicator_type() {
return self::INDICATOR_COGNITIVE;
}
public function get_cognitive_depth_level(\cm_info $cm) {
return self::COGNITIVE_LEVEL_5;
}
/**
* feedback_submitted
*
* @param \cm_info $cm
* @param int $contextid
* @param int $userid
* @param int $after
* @return bool
*/
protected function feedback_submitted(\cm_info $cm, $contextid, $userid, $after = false) {
if (empty($this->activitylogs[$contextid][$userid]) ||
empty($this->activitylogs[$contextid][$userid]['\mod_lesson\event\lesson_ended'])) {
return false;
}
// Multiple lesson attempts completed counts as submitted after feedback.
return (2 >= count($this->activitylogs[$contextid][$userid]['\mod_lesson\event\lesson_ended']->timecreated));
}
/**
* feedback_replied
*
* @param \cm_info $cm
* @param int $contextid
* @param int $userid
* @param int $after
* @return bool
*/
protected function feedback_replied(\cm_info $cm, $contextid, $userid, $after = false) {
// No level 4.
return false;
}
}
@@ -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/>.
/**
* Social breadth indicator - lesson.
*
* @package mod_lesson
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Social breadth indicator - lesson.
*
* @package mod_lesson
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class social_breadth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:socialbreadth', 'mod_lesson');
}
public function get_indicator_type() {
return self::INDICATOR_SOCIAL;
}
public function get_social_breadth_level(\cm_info $cm) {
return self::SOCIAL_LEVEL_2;
}
}
+110
View File
@@ -0,0 +1,110 @@
<?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/>.
/**
* Cache data source for the lesson overrides.
*
* @package mod_lesson
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_lesson\cache;
use cache_definition;
/**
* Class lesson_overrides
*
* @package mod_lesson
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class overrides implements \cache_data_source {
/** @var overrides the singleton instance of this class. */
protected static $instance = null;
/**
* Returns an instance of the data source class that the cache can use for loading data using the other methods
* specified by this interface.
*
* @param cache_definition $definition
* @return object
*/
public static function get_instance_for_cache(cache_definition $definition): overrides {
if (is_null(self::$instance)) {
self::$instance = new overrides();
}
return self::$instance;
}
/**
* Loads the data for the key provided ready formatted for caching.
*
* @param string|int $key The key to load.
* @return mixed What ever data should be returned, or false if it can't be loaded.
* @throws \coding_exception
*/
public function load_for_cache($key) {
global $DB;
[$lessonid, $ug, $ugid] = explode('_', $key);
$lessonid = (int) $lessonid;
switch ($ug) {
case 'u':
$userid = (int) $ugid;
$override = $DB->get_record(
'lesson_overrides',
['lessonid' => $lessonid, 'userid' => $userid],
'available, deadline, timelimit, review, maxattempts, retake, password'
);
break;
case 'g':
$groupid = (int) $ugid;
$override = $DB->get_record(
'lesson_overrides',
['lessonid' => $lessonid, 'groupid' => $groupid],
'available, deadline, timelimit, review, maxattempts, retake, password'
);
break;
default:
throw new \coding_exception('Invalid cache key');
}
// Return null instead of false, because false will not be cached.
return $override ?: null;
}
/**
* Loads several keys for the cache.
*
* @param array $keys An array of keys each of which will be string|int.
* @return array An array of matching data items.
*/
public function load_many_for_cache(array $keys) {
$results = [];
foreach ($keys as $key) {
$results[] = $this->load_for_cache($key);
}
return $results;
}
}
@@ -0,0 +1,109 @@
<?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/>.
declare(strict_types=1);
namespace mod_lesson\completion;
use core_completion\activity_custom_completion;
/**
* Activity custom completion subclass for the lesson activity.
*
* Contains the class for defining mod_lesson's custom completion rules
* and fetching a lesson instance's completion statuses for a user.
*
* @package mod_lesson
* @copyright Michael Hawkins <michaelh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_completion extends activity_custom_completion {
/**
* Fetches the completion state for a given completion rule.
*
* @param string $rule The completion rule.
* @return int The completion state.
*/
public function get_state(string $rule): int {
global $DB;
$this->validate_rule($rule);
switch ($rule) {
case 'completiontimespent':
$duration = $DB->get_field_sql(
"SELECT SUM(lessontime - starttime)
FROM {lesson_timer}
WHERE lessonid = :lessonid
AND userid = :userid",
['userid' => $this->userid, 'lessonid' => $this->cm->instance]);
$status = ($duration && $duration >= $this->cm->customdata['customcompletionrules']['completiontimespent']);
break;
case 'completionendreached':
$status = $DB->record_exists('lesson_timer',
['lessonid' => $this->cm->instance, 'userid' => $this->userid, 'completed' => 1]);
break;
default:
$status = false;
break;
}
return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
}
/**
* Fetch the list of custom completion rules that this module defines.
*
* @return array
*/
public static function get_defined_custom_rules(): array {
return [
'completiontimespent',
'completionendreached',
];
}
/**
* Returns an associative array of the descriptions of custom completion rules.
*
* @return array
*/
public function get_custom_rule_descriptions(): array {
$timespent = format_time($this->cm->customdata['customcompletionrules']['completiontimespent'] ?? 0);
return [
'completiontimespent' => get_string('completiondetail:timespent', 'lesson', $timespent),
'completionendreached' => get_string('completiondetail:reachend', 'lesson'),
];
}
/**
* Returns an array of all completion rules, in the order they should be displayed to users.
*
* @return array
*/
public function get_sort_order(): array {
return [
'completionview',
'completiontimespent',
'completionendreached',
'completionusegrade',
'completionpassgrade',
];
}
}
+70
View File
@@ -0,0 +1,70 @@
<?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/>.
/**
* Contains the class for fetching the important dates in mod_lesson for a given module instance and a user.
*
* @package mod_lesson
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_lesson;
use core\activity_dates;
/**
* Class for fetching the important dates in mod_lesson for a given module instance and a user.
*
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates extends activity_dates {
/**
* Returns a list of important dates in mod_lesson
*
* @return array
*/
protected function get_dates(): array {
$timeopen = $this->cm->customdata['available'] ?? null;
$timeclose = $this->cm->customdata['deadline'] ?? null;
$now = time();
$dates = [];
if ($timeopen) {
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
$dates[] = [
'dataid' => 'available',
'label' => get_string($openlabelid, 'course'),
'timestamp' => (int) $timeopen,
];
}
if ($timeclose) {
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
$dates[] = [
'dataid' => 'deadline',
'label' => get_string($closelabelid, 'course'),
'timestamp' => (int) $timeclose,
];
}
return $dates;
}
}
@@ -0,0 +1,93 @@
<?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_lesson content page viewed event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson content page viewed event class.
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class content_page_viewed extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_pages';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcontentpageviewed', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid, 'pageid' => $this->objectid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has viewed the content page with id '$this->objectid' in " .
"the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Make sure this class is never used without proper object details.
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_pages', 'restore' => 'lesson_page');
}
}
@@ -0,0 +1,39 @@
<?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_lesson instance list viewed event.
*
* @package mod_lesson
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson instance list viewed event class.
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @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 {
// No code required here as the parent class handles it all.
}
@@ -0,0 +1,52 @@
<?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_lesson course module viewed event.
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson course module viewed event class.
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
public static function get_objectid_mapping() {
return array('db' => 'lesson', 'restore' => 'lesson');
}
}
+115
View File
@@ -0,0 +1,115 @@
<?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_lesson essay assessed event.
*
* @package mod_lesson
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson essay assessed event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - int lessonid: The ID of the lesson.
* - int attemptid: The ID for the attempt.
* }
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class essay_assessed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'lesson_grades';
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has marked the essay with id '{$this->other['attemptid']}' and " .
"recorded a mark '$this->objectid' in the lesson with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventessayassessed', 'mod_lesson');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/essay.php', array('id' => $this->contextinstanceid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
if (!isset($this->other['attemptid'])) {
throw new \coding_exception('The \'attemptid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_grades', 'restore' => 'lesson_grade');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson');
$othermapped['attemptid'] = array('db' => 'lesson_attempts', 'restore' => 'lesson_attept');
return $othermapped;
}
}
@@ -0,0 +1,94 @@
<?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_lesson essay attempt viewed event.
*
* @package mod_lesson
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson essay attempt viewed event class.
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class essay_attempt_viewed extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_attempts';
$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('eventessayattemptviewed', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/essay.php', array('id' => $this->contextinstanceid,
'mode' => 'grade', 'attemptid' => $this->objectid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the essay grade for the user with id '$this->relateduserid' for " .
"the attempt with id '$this->objectid' for the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_attempts', 'restore' => 'lesson_attempt');
}
}
@@ -0,0 +1,112 @@
<?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_lesson group override created event.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson group override created event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int lessonid: the id of the lesson.
* - int groupid: the id of the group.
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_override_created extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_overrides';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridecreated', 'mod_lesson');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' created the override with id '$this->objectid' for the lesson with " .
"course module id '$this->contextinstanceid' for the group with id '{$this->other['groupid']}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_overrides', 'restore' => 'lesson_override');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -0,0 +1,111 @@
<?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_lesson group override deleted event.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson group override deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int lessonid: the id of the lesson.
* - int groupid: the id of the group.
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Jean-Michel vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_override_deleted extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_overrides';
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridedeleted', 'mod_lesson');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted the override with id '$this->objectid' for the lesson with " .
"course module id '$this->contextinstanceid' for the group with id '{$this->other['groupid']}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/overrides.php', array('cmid' => $this->contextinstanceid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_overrides', 'restore' => 'lesson_override');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -0,0 +1,111 @@
<?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_lesson group override updated event.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson group override updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int lessonid: the id of the lesson.
* - int groupid: the id of the group.
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_override_updated extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_overrides';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverrideupdated', 'mod_lesson');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated the override with id '$this->objectid' for the lesson with " .
"course module id '$this->contextinstanceid' for the group with id '{$this->other['groupid']}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_overrides', 'restore' => 'lesson_override');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -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_lesson highscore added event.
*
* @package mod_lesson
* @deprecated since Moodle 3.0
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
debugging('mod_lesson\event\highscore_added has been deprecated. Since the functionality no longer resides in the lesson module.',
DEBUG_DEVELOPER);
/**
* The mod_lesson highscore added event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int lessonid: the id of the lesson in the lesson table.
* - string nickname: the user's nickname.
* }
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class highscore_added extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_high_scores';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventhighscoreadded', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/highscores.php', array('id' => $this->contextinstanceid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' added a new highscore to the lesson activity with course module " .
"id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
if (!isset($this->other['nickname'])) {
throw new \coding_exception('The \'nickname\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
// The 'highscore' functionality was removed from core.
return false;
}
public static function get_other_mapping() {
// The 'highscore' functionality was removed from core.
return false;
}
}
@@ -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_lesson highscores viewed.
*
* @package mod_lesson
* @deprecated since Moodle 3.0
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
debugging('mod_lesson\event\highscores_viewed has been deprecated. Since the functionality no longer resides in the lesson module.',
DEBUG_DEVELOPER);
/**
* The mod_lesson highscores viewed class.
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class highscores_viewed extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventhighscoresviewed', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/highscores.php', array('id' => $this->contextinstanceid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the highscores for the lesson activity with course module " .
"id '$this->contextinstanceid'.";
}
public static function get_objectid_mapping() {
// The 'highscore' functionality was removed from core.
return false;
}
public static function get_other_mapping() {
// The 'highscore' functionality was removed from core.
return false;
}
}
+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/>.
/**
* The mod_lesson lesson ended event.
*
* @package mod_lesson
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson lesson ended event class.
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class lesson_ended extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventlessonended', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' ended the lesson with course module id '$this->contextinstanceid'.";
}
public static function get_objectid_mapping() {
return array('db' => 'lesson', 'restore' => 'lesson');
}
}
@@ -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/>.
/**
* The mod_lesson lesson restarted event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson lesson restarted event class
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class lesson_restarted extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventlessonrestarted', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' abandoned their previous incomplete attempt ".
"and started a new attempt on the lesson with course module id '$this->contextinstanceid'.";
}
public static function get_objectid_mapping() {
return array('db' => 'lesson', 'restore' => 'lesson');
}
}
@@ -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/>.
/**
* The mod_lesson lesson resumed event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson lesson resumed event class
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class lesson_resumed extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventlessonresumed', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' resumed their previous incomplete attempt on".
" the lesson with course module id '$this->contextinstanceid'.";
}
public static function get_objectid_mapping() {
return array('db' => 'lesson', 'restore' => 'lesson');
}
}
@@ -0,0 +1,78 @@
<?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_lesson lesson started event.
*
* @package mod_lesson
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson lesson started event class.
*
* @package mod_lesson
* @since Moodle 2.7
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class lesson_started extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventlessonstarted', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' started the lesson with course module id '$this->contextinstanceid'.";
}
public static function get_objectid_mapping() {
return array('db' => 'lesson', 'restore' => 'lesson');
}
}
+107
View File
@@ -0,0 +1,107 @@
<?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_lesson page_added event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson page_created event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string pagetype: the name of the pagetype as defined in the individual page class
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class page_created extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_pages';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpagecreated', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid, 'pageid' => $this->objectid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has created a ".$this->other['pagetype']." page with the ".
"id '$this->objectid' in the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Make sure this class is never used without proper object details.
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
if (!isset($this->other['pagetype'])) {
throw new \coding_exception('The \'pagetype\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_pages', 'restore' => 'lesson_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
+107
View File
@@ -0,0 +1,107 @@
<?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_lesson page_added event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson page_deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string pagetype: the name of the pagetype as defined in the individual page class
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class page_deleted extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_pages';
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpagedeleted', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has deleted the ".$this->other['pagetype']." page with the ".
"id '$this->objectid' in the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Make sure this class is never used without proper object details.
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
if (!isset($this->other['pagetype'])) {
throw new \coding_exception('The \'pagetype\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_pages', 'restore' => 'lesson_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
+120
View File
@@ -0,0 +1,120 @@
<?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_lesson page_moved event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson page_moved event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string pagetype: the name of the pagetype as defined in the individual page class
* - int prevpageid: the id of the previous lesson page
* - int nextpageid: the id of the next lesson page
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class page_moved extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_pages';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpagemoved', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid, 'pageid' => $this->objectid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has moved a ".$this->other['pagetype']." page with the ".
"id '$this->objectid' to the slot after the page with the id '".$this->other['prevpageid'].
"' and before the page with the id '".$this->other['nextpageid'].
"' in the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Make sure this class is never used without proper object details.
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
if (!isset($this->other['pagetype'])) {
throw new \coding_exception('The \'pagetype\' value must be set in other.');
}
if (!isset($this->other['prevpageid'])) {
throw new \coding_exception('The \'prevpageid\' value must be set in other.');
}
if (!isset($this->other['nextpageid'])) {
throw new \coding_exception('The \'nextpageid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_pages', 'restore' => 'lesson_page');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['prevpageid'] = array('db' => 'lesson_pages', 'restore' => 'lesson_page');
$othermapped['nextpageid'] = array('db' => 'lesson_pages', 'restore' => 'lesson_page');
return $othermapped;
}
}
+126
View File
@@ -0,0 +1,126 @@
<?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_lesson page_added event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson page_updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string pagetype: the name of the pagetype as defined in the individual page class
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class page_updated extends \core\event\base {
/**
* Create instance of event.
*
* @param \lesson_page $lessonpage
* @param \context_module $context
* @return page_updated
*/
public static function create_from_lesson_page(\lesson_page $lessonpage, \context_module $context) {
$data = array(
'context' => $context,
'objectid' => $lessonpage->properties()->id,
'other' => array(
'pagetype' => $lessonpage->get_typestring()
)
);
return self::create($data);
}
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_pages';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpageupdated', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid, 'pageid' => $this->objectid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has updated the ".$this->other['pagetype']." page with the ".
"id '$this->objectid' in the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Make sure this class is never used without proper object details.
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
if (!isset($this->other['pagetype'])) {
throw new \coding_exception('The \'pagetype\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_pages', 'restore' => 'lesson_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
@@ -0,0 +1,107 @@
<?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_lesson true / false question answered event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson question answered event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string pagetype: the name of the pagetype as defined in the individual page class
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class question_answered extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_pages';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventquestionanswered', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid, 'pageid' => $this->objectid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has answered the ".$this->other['pagetype'] .
" question with id '$this->objectid' in the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Make sure this class is never used without proper object details.
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
if (!isset($this->other['pagetype'])) {
throw new \coding_exception('The \'pagetype\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_pages', 'restore' => 'lesson_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
@@ -0,0 +1,107 @@
<?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_lesson true / false question viewed event class.
*
* @package mod_lesson
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson question viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string pagetype: the name of the pagetype as defined in the individual page class
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class question_viewed extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_pages';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventquestionviewed', 'mod_lesson');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/view.php', array('id' => $this->contextinstanceid, 'pageid' => $this->objectid));
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has viewed the ".$this->other['pagetype'] .
" question with id '$this->objectid' in the lesson activity with course module id '$this->contextinstanceid'.";
}
/**
* Custom validations.
*
* @throws \coding_exception when validation fails.
* @return void
*/
protected function validate_data() {
parent::validate_data();
// Make sure this class is never used without proper object details.
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
if (!isset($this->other['pagetype'])) {
throw new \coding_exception('The \'pagetype\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_pages', 'restore' => 'lesson_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
@@ -0,0 +1,109 @@
<?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_lesson user override created event.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson user override created event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int lessonid: the id of the lesson.
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_override_created extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_overrides';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridecreated', 'mod_lesson');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' created the override with id '$this->objectid' for the lesson with " .
"course module id '$this->contextinstanceid' for the user with id '{$this->relateduserid}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_overrides', 'restore' => 'lesson_override');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson');
return $othermapped;
}
}
@@ -0,0 +1,109 @@
<?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_lesson user override deleted event.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson user override deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int lessonid: the id of the lesson.
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_override_deleted extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_overrides';
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridedeleted', 'mod_lesson');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted the override with id '$this->objectid' for the lesson with " .
"course module id '$this->contextinstanceid' for the user with id '{$this->relateduserid}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/overrides.php', array('cmid' => $this->contextinstanceid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_overrides', 'restore' => 'lesson_override');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson');
return $othermapped;
}
}
@@ -0,0 +1,110 @@
<?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_lesson user override updated event.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_lesson user override updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int lessonid: the id of the lesson.
* }
*
* @package mod_lesson
* @since Moodle 2.9
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_override_updated extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'lesson_overrides';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverrideupdated', 'mod_lesson');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated the override with id '$this->objectid' for the lesson with " .
"course module id '$this->contextinstanceid' for the user with id '{$this->relateduserid}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/lesson/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['lessonid'])) {
throw new \coding_exception('The \'lessonid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'lesson_overrides', 'restore' => 'lesson_override');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson');
return $othermapped;
}
}
File diff suppressed because it is too large Load Diff
+312
View File
@@ -0,0 +1,312 @@
<?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/>.
/**
* Class for exporting partial lesson data.
*
* @package mod_lesson
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use core_external\external_files;
use core_external\util as external_util;
/**
* Class for exporting partial lesson data (some fields are only viewable by admins).
*
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class lesson_summary_exporter extends exporter {
protected static function define_properties() {
return array(
'id' => array(
'type' => PARAM_INT,
'description' => 'Standard Moodle primary key.'
),
'course' => array(
'type' => PARAM_INT,
'description' => 'Foreign key reference to the course this lesson is part of.'
),
'coursemodule' => array(
'type' => PARAM_INT,
'description' => 'Course module id.'
),
'name' => array(
'type' => PARAM_RAW,
'description' => 'Lesson name.'
),
'intro' => array(
'type' => PARAM_RAW,
'description' => 'Lesson introduction text.',
'optional' => true,
),
'introformat' => array(
'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
'type' => PARAM_INT,
'default' => FORMAT_MOODLE
),
'lang' => array(
'type' => PARAM_LANG,
'description' => 'Forced activity language',
'null' => NULL_ALLOWED,
),
'practice' => array(
'type' => PARAM_BOOL,
'description' => 'Practice lesson?',
'optional' => true,
),
'modattempts' => array(
'type' => PARAM_BOOL,
'description' => 'Allow student review?',
'optional' => true,
),
'usepassword' => array(
'type' => PARAM_BOOL,
'description' => 'Password protected lesson?',
'optional' => true,
),
'password' => array(
'type' => PARAM_RAW,
'description' => 'Password',
'optional' => true,
),
'dependency' => array(
'type' => PARAM_INT,
'description' => 'Dependent on (another lesson id)',
'optional' => true,
),
'conditions' => array(
'type' => PARAM_RAW,
'description' => 'Conditions to enable the lesson',
'optional' => true,
),
'grade' => array(
'type' => PARAM_INT,
'description' => 'The total that the grade is scaled to be out of',
'optional' => true,
),
'custom' => array(
'type' => PARAM_BOOL,
'description' => 'Custom scoring?',
'optional' => true,
),
'ongoing' => array(
'type' => PARAM_BOOL,
'description' => 'Display ongoing score?',
'optional' => true,
),
'usemaxgrade' => array(
'type' => PARAM_INT,
'description' => 'How to calculate the final grade',
'optional' => true,
),
'maxanswers' => array(
'type' => PARAM_INT,
'description' => 'Maximum answers per page',
'optional' => true,
),
'maxattempts' => array(
'type' => PARAM_INT,
'description' => 'Maximum attempts',
'optional' => true,
),
'review' => array(
'type' => PARAM_BOOL,
'description' => 'Provide option to try a question again',
'optional' => true,
),
'nextpagedefault' => array(
'type' => PARAM_INT,
'description' => 'Action for a correct answer',
'optional' => true,
),
'feedback' => array(
'type' => PARAM_BOOL,
'description' => 'Display default feedback',
'optional' => true,
),
'minquestions' => array(
'type' => PARAM_INT,
'description' => 'Minimum number of questions',
'optional' => true,
),
'maxpages' => array(
'type' => PARAM_INT,
'description' => 'Number of pages to show',
'optional' => true,
),
'timelimit' => array(
'type' => PARAM_INT,
'description' => 'Time limit',
'optional' => true,
),
'retake' => array(
'type' => PARAM_BOOL,
'description' => 'Re-takes allowed',
'optional' => true,
),
'activitylink' => array(
'type' => PARAM_INT,
'description' => 'Id of the next activity to be linked once the lesson is completed',
'optional' => true,
),
'mediafile' => array(
'type' => PARAM_RAW,
'description' => 'Local file path or full external URL',
'optional' => true,
),
'mediaheight' => array(
'type' => PARAM_INT,
'description' => 'Popup for media file height',
'optional' => true,
),
'mediawidth' => array(
'type' => PARAM_INT,
'description' => 'Popup for media with',
'optional' => true,
),
'mediaclose' => array(
'type' => PARAM_INT,
'description' => 'Display a close button in the popup?',
'optional' => true,
),
'slideshow' => array(
'type' => PARAM_BOOL,
'description' => 'Display lesson as slideshow',
'optional' => true,
),
'width' => array(
'type' => PARAM_INT,
'description' => 'Slideshow width',
'optional' => true,
),
'height' => array(
'type' => PARAM_INT,
'description' => 'Slideshow height',
'optional' => true,
),
'bgcolor' => array(
'type' => PARAM_TEXT,
'description' => 'Slideshow bgcolor',
'optional' => true,
),
'displayleft' => array(
'type' => PARAM_BOOL,
'description' => 'Display left pages menu?',
'optional' => true,
),
'displayleftif' => array(
'type' => PARAM_INT,
'description' => 'Minimum grade to display menu',
'optional' => true,
),
'progressbar' => array(
'type' => PARAM_BOOL,
'description' => 'Display progress bar?',
'optional' => true,
),
'available' => array(
'type' => PARAM_INT,
'description' => 'Available from',
'optional' => true,
),
'deadline' => array(
'type' => PARAM_INT,
'description' => 'Available until',
'optional' => true,
),
'timemodified' => array(
'type' => PARAM_INT,
'description' => 'Last time settings were updated',
'optional' => true,
),
'completionendreached' => array(
'type' => PARAM_INT,
'description' => 'Require end reached for completion?',
'optional' => true,
),
'completiontimespent' => array(
'type' => PARAM_INT,
'description' => 'Student must do this activity at least for',
'optional' => true,
),
'allowofflineattempts' => array(
'type' => PARAM_BOOL,
'description' => 'Whether to allow the lesson to be attempted offline in the mobile app',
),
);
}
protected static function define_related() {
return array(
'context' => 'context'
);
}
protected static function define_other_properties() {
return array(
'coursemodule' => array(
'type' => PARAM_INT
),
'introfiles' => array(
'type' => external_files::get_properties_for_exporter(),
'multiple' => true,
'optional' => true,
),
'mediafiles' => array(
'type' => external_files::get_properties_for_exporter(),
'multiple' => true,
'optional' => true,
),
);
}
protected function get_other_values(renderer_base $output) {
$context = $this->related['context'];
$values = array(
'coursemodule' => $context->instanceid,
);
if (isset($this->data->intro)) {
$values['introfiles'] = external_util::get_area_files($context->id, 'mod_lesson', 'intro', false, false);
$values['mediafiles'] = external_util::get_area_files($context->id, 'mod_lesson', 'mediafile', 0);
}
return $values;
}
/**
* Get the formatting parameters for the intro.
*
* @return array
*/
protected function get_format_parameters_for_intro() {
return [
'component' => 'mod_lesson',
'filearea' => 'intro',
'options' => array('noclean' => true),
];
}
}
+194
View File
@@ -0,0 +1,194 @@
<?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/>.
/**
* File browsing support.
*
* @package mod_lesson
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* File browsing support class.
*
* @package mod_lesson
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lesson_file_info extends file_info {
/** @var stdClass Course object */
protected $course;
/** @var stdClass Course module object */
protected $cm;
/** @var array Available file areas */
protected $areas;
/** @var string File area to browse */
protected $filearea;
/**
* Constructor
*
* @param file_browser $browser file_browser instance
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context module context
* @param array $areas available file areas
* @param string $filearea file area to browse
*/
public function __construct($browser, $course, $cm, $context, $areas, $filearea) {
parent::__construct($browser, $context);
$this->course = $course;
$this->cm = $cm;
$this->areas = $areas;
$this->filearea = $filearea;
}
/**
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
* @return array with keys contextid, filearea, itemid, filepath and filename
*/
public function get_params() {
return array('contextid' => $this->context->id,
'component' => 'mod_lesson',
'filearea' => $this->filearea,
'itemid' => null,
'filepath' => null,
'filename' => null);
}
/**
* Returns localised visible name.
* @return string
*/
public function get_visible_name() {
return $this->areas[$this->filearea];
}
/**
* Can I add new files or directories?
* @return bool
*/
public function is_writable() {
return false;
}
/**
* Is directory?
* @return bool
*/
public function is_directory() {
return true;
}
/**
* Returns list of children.
* @return array of file_info instances
*/
public function get_children() {
return $this->get_filtered_children('*', false, true);
}
/**
* Help function to return files matching extensions or their count
*
* @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
* @param bool|int $countonly if false returns the children, if an int returns just the
* count of children but stops counting when $countonly number of children is reached
* @param bool $returnemptyfolders if true returns items that don't have matching files inside
* @return array|int array of file_info instances or the count
*/
private function get_filtered_children($extensions = '*', $countonly = false, $returnemptyfolders = false) {
global $DB;
$params = array(
'contextid' => $this->context->id,
'component' => 'mod_lesson',
'filearea' => $this->filearea
);
$sql = 'SELECT DISTINCT itemid
FROM {files}
WHERE contextid = :contextid
AND component = :component
AND filearea = :filearea';
if (!$returnemptyfolders) {
$sql .= ' AND filename <> :emptyfilename';
$params['emptyfilename'] = '.';
}
list($sql2, $params2) = $this->build_search_files_sql($extensions);
$sql .= ' ' . $sql2;
$params = array_merge($params, $params2);
if ($countonly !== false) {
$sql .= ' ORDER BY itemid DESC';
}
$rs = $DB->get_recordset_sql($sql, $params);
$children = array();
foreach ($rs as $record) {
if (($child = $this->browser->get_file_info($this->context, 'mod_lesson', $this->filearea, $record->itemid))
&& ($returnemptyfolders || $child->count_non_empty_children($extensions))) {
$children[] = $child;
}
if ($countonly !== false && count($children) >= $countonly) {
break;
}
}
$rs->close();
if ($countonly !== false) {
return count($children);
}
return $children;
}
/**
* Returns list of children which are either files matching the specified extensions
* or folders that contain at least one such file.
*
* @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
* @return array of file_info instances
*/
public function get_non_empty_children($extensions = '*') {
return $this->get_filtered_children($extensions, false);
}
/**
* Returns the number of children which are either files matching the specified extensions
* or folders containing at least one such file.
*
* @param string|array $extensions, for example '*' or array('.gif','.jpg')
* @param int $limit stop counting after at least $limit non-empty children are found
* @return int
*/
public function count_non_empty_children($extensions = '*', $limit = 1) {
return $this->get_filtered_children($extensions, $limit);
}
/**
* Returns parent file_info instance
* @return file_info or null for root
*/
public function get_parent() {
return $this->browser->get_file_info($this->context);
}
}
+85
View File
@@ -0,0 +1,85 @@
<?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/>.
/**
* Group observers.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/lesson/locallib.php');
/**
* Group observers class.
*
* @package mod_lesson
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_observers {
/**
* Flag whether a course reset is in progress or not.
*
* @var int The course ID.
*/
protected static $resetinprogress = false;
/**
* A course reset has started.
*
* @param \core\event\base $event The event.
* @return void
*/
public static function course_reset_started($event) {
self::$resetinprogress = $event->courseid;
}
/**
* A course reset has ended.
*
* @param \core\event\base $event The event.
* @return void
*/
public static function course_reset_ended($event) {
if (!empty(self::$resetinprogress)) {
if (!empty($event->other['reset_options']['reset_groups_remove'])) {
lesson_process_group_deleted_in_course($event->courseid);
}
}
self::$resetinprogress = null;
}
/**
* A group was deleted.
*
* @param \core\event\base $event The event.
* @return void
*/
public static function group_deleted($event) {
if (!empty(self::$resetinprogress)) {
// We will take care of that once the course reset ends.
return;
}
lesson_process_group_deleted_in_course($event->courseid, $event->objectid);
}
}
@@ -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/>.
/**
* Lesson's numeric helper lib.
*
* Contains any helper functions for the numeric pagetyep
*
* @package mod_lesson
* @copyright 2020 Peter Dias <peter@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\local\numeric;
/**
* Lesson numeric page helper
*
* @copyright 2020 Peter Dias<peter@moodle.com>
* @package core_lesson
*/
class helper {
/**
* Helper function to unformat a given numeric value from locale specific values with n:n signifying ranges to standards
* with decimal point numbers/ranges
*
* @param string $value The value to be formatted
* @return string|float|bool $formattedvalue unformatted value
* String - If it is a range it will return a value e.g. 2:4
* Float - if it's a properly formatted float
* Null - If empty and could not be converted
*/
public static function lesson_unformat_numeric_value(string $value) {
if (strpos($value, ':')) {
list($min, $max) = explode(':', $value);
$formattedvalue = unformat_float($min) . ':' . unformat_float($max);
} else {
$formattedvalue = unformat_float($value);
}
return $formattedvalue;
}
/**
* Helper function to format a given value into locale specific values with n:n signifying ranges
*
* @param string|number $value The value to be formatted
* @return string $formattedvalue Formatted value OR $value if not numeric
*/
public static function lesson_format_numeric_value($value): string {
$formattedvalue = $value;
if (strpos($value, ':')) {
list($min, $max) = explode(':', $value);
$formattedvalue = $min . ':' . $max;
if (is_numeric($min) && is_numeric($max)) {
$formattedvalue = format_float($min, strlen($min), true, true) . ':'
. format_float($max, strlen($max), true, true);
}
} else {
$formattedvalue = is_numeric($value) ? format_float($value, strlen($value), true, true) : $value;
}
return $formattedvalue;
}
}
@@ -0,0 +1,87 @@
<?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/>.
/**
* Output the actionbar for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\output;
use moodle_url;
use templatable;
use renderable;
/**
* Output the actionbar for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_action_area implements templatable, renderable {
/** @var int The course module ID. */
protected $cmid;
/** @var moodle_url The current url for the page. */
protected $currenturl;
/**
* Constructor for this object.
*
* @param int $cmid The course module ID.
* @param moodle_url $currenturl The current url for the page.
*/
public function __construct(int $cmid, moodle_url $currenturl) {
$this->cmid = $cmid;
$this->currenturl = $currenturl;
}
/**
* Data for use with a template.
*
* @param \renderer_base $output render base output.
* @return array Said data.
*/
public function export_for_template(\renderer_base $output): array {
global $PAGE;
$viewurl = new moodle_url('/mod/lesson/edit.php', ['id' => $this->cmid, 'mode' => 'collapsed']);
$fullviewurl = new moodle_url('/mod/lesson/edit.php', ['id' => $this->cmid, 'mode' => 'full']);
$menu = [
$viewurl->out(false) => get_string('collapsed', 'mod_lesson'),
$fullviewurl->out(false) => get_string('full', 'mod_lesson')
];
$selectmenu = new \url_select($menu, $this->currenturl->out(false), null, 'mod_lesson_navigation_select');
$selectmenu->label = get_string('displaymode', 'mod_lesson');
$selectmenu->labelattributes = ['class' => 'sr-only'];
$headinglevel = $PAGE->activityheader->get_heading_level();
return [
'back' => [
'text' => get_string('back', 'core'),
'link' => (new moodle_url('/mod/lesson/view.php', ['id' => $this->cmid]))->out(false)
],
'viewselect' => $selectmenu->export_for_template($output),
'heading' => get_string('editinglesson', 'mod_lesson'),
'headinglevel' => $headinglevel,
];
}
}
@@ -0,0 +1,113 @@
<?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/>.
/**
* Output the action buttons for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\output;
use core\output\notification;
use moodle_url;
use templatable;
use renderable;
use single_button;
/**
* Output the action buttons for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_action_buttons implements templatable, renderable {
/** @var \lesson The lesson object. */
protected $lesson;
/** @var int The currently viewed lesson page id. */
protected $currentpage;
/**
* Constructor for this object.
*
* @param \lesson $lesson The lesson object.
* @param int|null $currentpage The current lesson page that is being viewed
*/
public function __construct(\lesson $lesson, ?int $currentpage = null) {
$this->lesson = $lesson;
$this->currentpage = $currentpage;
}
/**
* Sets the current page being viewed.
*
* @param int|null $page
*/
public function set_currentpage(?int $page) {
$this->currentpage = $page;
}
/**
* Data for use with a template.
*
* @param \renderer_base $output Renderer information.
* @return array Said data.
*/
public function export_for_template(\renderer_base $output) {
global $PAGE;
$data = [];
// A shortcut to edit the lesson's question page.
if (has_capability('mod/lesson:edit', $this->lesson->context) &&
!empty($this->currentpage) && $this->currentpage != LESSON_EOL) {
$url = new moodle_url('/mod/lesson/editpage.php', [
'id' => $this->lesson->get_cm()->id,
'pageid' => $this->currentpage,
'edit' => 1,
'returnto' => $PAGE->url->out_as_local_url(false)
]);
$editcontent = new single_button($url, get_string('editpagecontent', 'lesson'));
$data['editcontents']['button'] = $editcontent->export_for_template($output);
}
if ($this->lesson->can_manage()) {
$url = new moodle_url('/mod/lesson/edit.php', ['id' => $this->lesson->get_cm()->id]);
$editbutton = new single_button($url, get_string('editlesson', 'mod_lesson'), 'get', single_button::BUTTON_PRIMARY);
$url = new moodle_url('/mod/lesson/essay.php', ['id' => $this->lesson->get_cm()->id]);
$essaybutton = new single_button($url, get_string('manualgrading', 'mod_lesson'), 'get');
$data += [
'edit' => [
'button' => $editbutton->export_for_template($output),
],
'gradeessays' => [
'button' => $essaybutton->export_for_template($output),
]
];
}
// Standard notification to indicate the lesson is being previewed.
if ($data) {
$message = new notification(get_string('lessonbeingpreviewed', 'mod_lesson'), notification::NOTIFY_INFO);
$data['notification'] = $message->export_for_template($output);
}
return $data;
}
}
@@ -0,0 +1,111 @@
<?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/>.
/**
* Output the override action menu for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\output;
use moodle_url;
use templatable;
use renderable;
/**
* Output the override action menu for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class override_action_menu implements templatable, renderable {
/** @var int The course module ID. */
protected $cmid;
/** @var moodle_url The current url for the page. */
protected $currenturl;
/** @var bool Whether can add user or group override (depending on the override type). */
protected $canoverride;
/**
* Constructor for this object.
*
* @param int $cmid The course module ID.
* @param moodle_url $currenturl The current url for the page.
* @param bool $canoverride Whether can add user or group override (depending on the override type).
*/
public function __construct(int $cmid, moodle_url $currenturl, bool $canoverride = false) {
$this->cmid = $cmid;
$this->currenturl = $currenturl;
$this->canoverride = $canoverride;
}
/**
* Creates a select menu for the override options.
*
* @return \url_select The override select.
*/
protected function create_override_select_menu(): \url_select {
$userlink = new moodle_url('/mod/lesson/overrides.php', ['cmid' => $this->cmid, 'mode' => 'user']);
$grouplink = new moodle_url('/mod/lesson/overrides.php', ['cmid' => $this->cmid, 'mode' => 'group']);
$menu = [
$userlink->out(false) => get_string('useroverrides', 'mod_lesson'),
$grouplink->out(false) => get_string('groupoverrides', 'mod_lesson'),
];
$selectmenu = new \url_select($menu, $this->currenturl->out(false), null, 'mod_lesson_override_select');
$selectmenu->label = get_string('manageoverrides', 'mod_lesson');
$selectmenu->labelattributes = ['class' => 'sr-only'];
return $selectmenu;
}
/**
* Data for use with a template.
*
* @param \renderer_base $output renderer base output.
* @return array Said data.
*/
public function export_for_template(\renderer_base $output): array {
global $PAGE;
$type = $this->currenturl->get_param('mode');
if ($type == 'user') {
$text = get_string('addnewuseroverride', 'mod_lesson');
} else {
$text = get_string('addnewgroupoverride', 'mod_lesson');
}
$action = ($type == 'user') ? 'adduser' : 'addgroup';
$urlselect = $this->create_override_select_menu();
$data = [
'urlselect' => $urlselect->export_for_template($output)
];
if ($this->canoverride) {
$data['addoverride'] = [
'text' => $text,
'link' => (new moodle_url('/mod/lesson/overrideedit.php', [
'cmid' => $this->currenturl->get_param('cmid'),
'action' => $action
]))->out(false)
];
}
$data['heading'] = get_string($type == 'user' ? 'useroverrides' : 'groupoverrides', 'mod_lesson');
$data['headinglevel'] = $PAGE->activityheader->get_heading_level();
return $data;
}
}
@@ -0,0 +1,82 @@
<?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/>.
/**
* Output the report action menu for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\output;
use moodle_url;
use templatable;
use renderable;
/**
* Output the report action menu for this activity.
*
* @package mod_lesson
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_action_menu implements templatable, renderable {
/** int The lesson id. */
protected $lessonid;
/** moodle_url The url for this page. */
protected $url;
/**
* Constructor for this object.
*
* @param int $lessonid The lessonid.
* @param moodle_url $url The url for this page.
*/
public function __construct(int $lessonid, moodle_url $url) {
$this->lessonid = $lessonid;
$this->url = $url;
}
/**
* Export this url select menu for navigating between reports.
*
* @param \renderer_base $output Renderer output.
* @return array The data for the template.
*/
public function export_for_template(\renderer_base $output): array {
global $PAGE;
$overviewlink = new moodle_url('/mod/lesson/report.php', ['id' => $this->lessonid, 'action' => 'reportoverview']);
$fulllink = new moodle_url('/mod/lesson/report.php', ['id' => $this->lessonid, 'action' => 'reportdetail']);
$menu = [
$overviewlink->out(false) => get_string('overview', 'mod_lesson'),
$fulllink->out(false) => get_string('detailedstats', 'mod_lesson')
];
$reportselect = new \url_select($menu, $this->url->out(false), null, 'lesson-report-select');
$reportselect->label = get_string('selectreport', 'mod_lesson');
$reportselect->labelattributes = ['class' => 'sr-only'];
$data = [
'reportselect' => $reportselect->export_for_template($output),
'heading' => $menu[$reportselect->selected] ?? '',
'headinglevel' => $PAGE->activityheader->get_heading_level(),
];
return $data;
}
}
+698
View File
@@ -0,0 +1,698 @@
<?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/>.
/**
* Data provider.
*
* @package mod_lesson
* @copyright 2018 Frédéric Massart
* @author Frédéric Massart <fred@branchup.tech>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\privacy;
defined('MOODLE_INTERNAL') || die();
use context;
use context_helper;
use context_module;
use stdClass;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\approved_userlist;
use core_privacy\local\request\helper;
use core_privacy\local\request\transform;
use core_privacy\local\request\userlist;
use core_privacy\local\request\writer;
require_once($CFG->dirroot . '/mod/lesson/locallib.php');
require_once($CFG->dirroot . '/mod/lesson/pagetypes/essay.php');
require_once($CFG->dirroot . '/mod/lesson/pagetypes/matching.php');
require_once($CFG->dirroot . '/mod/lesson/pagetypes/multichoice.php');
/**
* Data provider class.
*
* @package mod_lesson
* @copyright 2018 Frédéric Massart
* @author Frédéric Massart <fred@branchup.tech>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider,
\core_privacy\local\request\user_preference_provider {
/**
* Returns metadata.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
$collection->add_database_table('lesson_attempts', [
'userid' => 'privacy:metadata:attempts:userid',
'pageid' => 'privacy:metadata:attempts:pageid',
'answerid' => 'privacy:metadata:attempts:answerid',
'retry' => 'privacy:metadata:attempts:retry',
'correct' => 'privacy:metadata:attempts:correct',
'useranswer' => 'privacy:metadata:attempts:useranswer',
'timeseen' => 'privacy:metadata:attempts:timeseen',
], 'privacy:metadata:attempts');
$collection->add_database_table('lesson_grades', [
'userid' => 'privacy:metadata:grades:userid',
'grade' => 'privacy:metadata:grades:grade',
'completed' => 'privacy:metadata:grades:completed',
// The column late is not used.
], 'privacy:metadata:grades');
$collection->add_database_table('lesson_timer', [
'userid' => 'privacy:metadata:timer:userid',
'starttime' => 'privacy:metadata:timer:starttime',
'lessontime' => 'privacy:metadata:timer:lessontime',
'completed' => 'privacy:metadata:timer:completed',
'timemodifiedoffline' => 'privacy:metadata:timer:timemodifiedoffline',
], 'privacy:metadata:timer');
$collection->add_database_table('lesson_branch', [
'userid' => 'privacy:metadata:branch:userid',
'pageid' => 'privacy:metadata:branch:pageid',
'retry' => 'privacy:metadata:branch:retry',
'flag' => 'privacy:metadata:branch:flag',
'timeseen' => 'privacy:metadata:branch:timeseen',
'nextpageid' => 'privacy:metadata:branch:nextpageid',
], 'privacy:metadata:branch');
$collection->add_database_table('lesson_overrides', [
'userid' => 'privacy:metadata:overrides:userid',
'available' => 'privacy:metadata:overrides:available',
'deadline' => 'privacy:metadata:overrides:deadline',
'timelimit' => 'privacy:metadata:overrides:timelimit',
'review' => 'privacy:metadata:overrides:review',
'maxattempts' => 'privacy:metadata:overrides:maxattempts',
'retake' => 'privacy:metadata:overrides:retake',
'password' => 'privacy:metadata:overrides:password',
], 'privacy:metadata:overrides');
$collection->add_user_preference('lesson_view', 'privacy:metadata:userpref:lessonview');
return $collection;
}
/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid): \core_privacy\local\request\contextlist {
$contextlist = new \core_privacy\local\request\contextlist();
$sql = "
SELECT DISTINCT ctx.id
FROM {lesson} l
JOIN {modules} m
ON m.name = :lesson
JOIN {course_modules} cm
ON cm.instance = l.id
AND cm.module = m.id
JOIN {context} ctx
ON ctx.instanceid = cm.id
AND ctx.contextlevel = :modulelevel
LEFT JOIN {lesson_attempts} la
ON la.lessonid = l.id
AND la.userid = :userid1
LEFT JOIN {lesson_branch} lb
ON lb.lessonid = l.id
AND lb.userid = :userid2
LEFT JOIN {lesson_grades} lg
ON lg.lessonid = l.id
AND lg.userid = :userid3
LEFT JOIN {lesson_overrides} lo
ON lo.lessonid = l.id
AND lo.userid = :userid4
LEFT JOIN {lesson_timer} lt
ON lt.lessonid = l.id
AND lt.userid = :userid5
WHERE la.id IS NOT NULL
OR lb.id IS NOT NULL
OR lg.id IS NOT NULL
OR lo.id IS NOT NULL
OR lt.id IS NOT NULL";
$params = [
'lesson' => 'lesson',
'modulelevel' => CONTEXT_MODULE,
'userid1' => $userid,
'userid2' => $userid,
'userid3' => $userid,
'userid4' => $userid,
'userid5' => $userid,
];
$contextlist->add_from_sql($sql, $params);
return $contextlist;
}
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
if (!is_a($context, \context_module::class)) {
return;
}
$params = [
'lesson' => 'lesson',
'modulelevel' => CONTEXT_MODULE,
'contextid' => $context->id,
];
// Mapping of lesson tables which may contain user data.
$joins = [
'lesson_attempts',
'lesson_branch',
'lesson_grades',
'lesson_overrides',
'lesson_timer',
];
foreach ($joins as $join) {
$sql = "
SELECT lx.userid
FROM {lesson} l
JOIN {modules} m
ON m.name = :lesson
JOIN {course_modules} cm
ON cm.instance = l.id
AND cm.module = m.id
JOIN {context} ctx
ON ctx.instanceid = cm.id
AND ctx.contextlevel = :modulelevel
JOIN {{$join}} lx
ON lx.lessonid = l.id
WHERE ctx.id = :contextid";
$userlist->add_from_sql('userid', $sql, $params);
}
}
/**
* Export all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts to export information for.
*/
public static function export_user_data(approved_contextlist $contextlist) {
global $DB;
$user = $contextlist->get_user();
$userid = $user->id;
$cmids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_MODULE) {
$carry[] = $context->instanceid;
}
return $carry;
}, []);
if (empty($cmids)) {
return;
}
// If the context export was requested, then let's at least describe the lesson.
foreach ($cmids as $cmid) {
$context = context_module::instance($cmid);
$contextdata = helper::get_context_data($context, $user);
helper::export_context_files($context, $user);
writer::with_context($context)->export_data([], $contextdata);
}
// Find the lesson IDs.
$lessonidstocmids = static::get_lesson_ids_to_cmids_from_cmids($cmids);
// Prepare the common SQL fragments.
list($inlessonsql, $inlessonparams) = $DB->get_in_or_equal(array_keys($lessonidstocmids), SQL_PARAMS_NAMED);
$sqluserlesson = "userid = :userid AND lessonid $inlessonsql";
$paramsuserlesson = array_merge($inlessonparams, ['userid' => $userid]);
// Export the overrides.
$recordset = $DB->get_recordset_select('lesson_overrides', $sqluserlesson, $paramsuserlesson);
static::recordset_loop_and_export($recordset, 'lessonid', null, function($carry, $record) {
// We know that there is only one row per lesson, so no need to use $carry.
return (object) [
'available' => $record->available !== null ? transform::datetime($record->available) : null,
'deadline' => $record->deadline !== null ? transform::datetime($record->deadline) : null,
'timelimit' => $record->timelimit !== null ? format_time($record->timelimit) : null,
'review' => $record->review !== null ? transform::yesno($record->review) : null,
'maxattempts' => $record->maxattempts,
'retake' => $record->retake !== null ? transform::yesno($record->retake) : null,
'password' => $record->password,
];
}, function($lessonid, $data) use ($lessonidstocmids) {
$context = context_module::instance($lessonidstocmids[$lessonid]);
writer::with_context($context)->export_related_data([], 'overrides', $data);
});
// Export the grades.
$recordset = $DB->get_recordset_select('lesson_grades', $sqluserlesson, $paramsuserlesson, 'lessonid, completed');
static::recordset_loop_and_export($recordset, 'lessonid', [], function($carry, $record) {
$carry[] = (object) [
'grade' => $record->grade,
'completed' => transform::datetime($record->completed),
];
return $carry;
}, function($lessonid, $data) use ($lessonidstocmids) {
$context = context_module::instance($lessonidstocmids[$lessonid]);
writer::with_context($context)->export_related_data([], 'grades', (object) ['grades' => $data]);
});
// Export the timers.
$recordset = $DB->get_recordset_select('lesson_timer', $sqluserlesson, $paramsuserlesson, 'lessonid, starttime');
static::recordset_loop_and_export($recordset, 'lessonid', [], function($carry, $record) {
$carry[] = (object) [
'starttime' => transform::datetime($record->starttime),
'lastactivity' => transform::datetime($record->lessontime),
'completed' => transform::yesno($record->completed),
'timemodifiedoffline' => $record->timemodifiedoffline ? transform::datetime($record->timemodifiedoffline) : null,
];
return $carry;
}, function($lessonid, $data) use ($lessonidstocmids) {
$context = context_module::instance($lessonidstocmids[$lessonid]);
writer::with_context($context)->export_related_data([], 'timers', (object) ['timers' => $data]);
});
// Export the attempts and branches.
$sql = "
SELECT " . $DB->sql_concat('lp.id', "':'", 'COALESCE(la.id, 0)', "':'", 'COALESCE(lb.id, 0)') . " AS uniqid,
lp.lessonid,
lp.id AS page_id,
lp.qtype AS page_qtype,
lp.qoption AS page_qoption,
lp.title AS page_title,
lp.contents AS page_contents,
lp.contentsformat AS page_contentsformat,
la.id AS attempt_id,
la.retry AS attempt_retry,
la.correct AS attempt_correct,
la.useranswer AS attempt_useranswer,
la.timeseen AS attempt_timeseen,
lb.id AS branch_id,
lb.retry AS branch_retry,
lb.timeseen AS branch_timeseen,
lpb.id AS nextpage_id,
lpb.title AS nextpage_title
FROM {lesson_pages} lp
LEFT JOIN {lesson_attempts} la
ON la.pageid = lp.id
AND la.userid = :userid1
LEFT JOIN {lesson_branch} lb
ON lb.pageid = lp.id
AND lb.userid = :userid2
LEFT JOIN {lesson_pages} lpb
ON lpb.id = lb.nextpageid
WHERE lp.lessonid $inlessonsql
AND (la.id IS NOT NULL OR lb.id IS NOT NULL)
ORDER BY lp.lessonid, lp.id, la.retry, lb.retry, la.id, lb.id";
$params = array_merge($inlessonparams, ['userid1' => $userid, 'userid2' => $userid]);
$recordset = $DB->get_recordset_sql($sql, $params);
static::recordset_loop_and_export($recordset, 'lessonid', [], function($carry, $record) use ($lessonidstocmids) {
$context = context_module::instance($lessonidstocmids[$record->lessonid]);
$options = ['context' => $context];
$take = isset($record->attempt_retry) ? $record->attempt_retry : $record->branch_retry;
if (!isset($carry[$take])) {
$carry[$take] = (object) [
'number' => $take + 1,
'answers' => [],
'jumps' => []
];
}
$pagefilespath = [get_string('privacy:path:pages', 'mod_lesson'), $record->page_id];
writer::with_context($context)->export_area_files($pagefilespath, 'mod_lesson', 'page_contents', $record->page_id);
$pagecontents = format_text(
writer::with_context($context)->rewrite_pluginfile_urls(
$pagefilespath,
'mod_lesson',
'page_contents',
$record->page_id,
$record->page_contents
),
$record->page_contentsformat,
$options
);
$pagebase = [
'id' => $record->page_id,
'page' => $record->page_title,
'contents' => $pagecontents,
'contents_files_folder' => implode('/', $pagefilespath)
];
if (isset($record->attempt_id)) {
$carry[$take]->answers[] = array_merge($pagebase, static::transform_attempt($record, $context));
} else if (isset($record->branch_id)) {
if (!empty($record->nextpage_id)) {
$wentto = $record->nextpage_title . " (id: {$record->nextpage_id})";
} else {
$wentto = get_string('endoflesson', 'mod_lesson');
}
$carry[$take]->jumps[] = array_merge($pagebase, [
'went_to' => $wentto,
'timeseen' => transform::datetime($record->attempt_timeseen)
]);
}
return $carry;
}, function($lessonid, $data) use ($lessonidstocmids) {
$context = context_module::instance($lessonidstocmids[$lessonid]);
writer::with_context($context)->export_related_data([], 'attempts', (object) [
'attempts' => array_values($data)
]);
});
}
/**
* Export all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$lessonview = get_user_preferences('lesson_view', null, $userid);
if ($lessonview !== null) {
$value = $lessonview;
// The code seems to indicate that there also is the option 'simple', but it's not
// described nor accessible from anywhere so we won't describe it more than being 'simple'.
if ($lessonview == 'full') {
$value = get_string('full', 'mod_lesson');
} else if ($lessonview == 'collapsed') {
$value = get_string('collapsed', 'mod_lesson');
}
writer::export_user_preference('mod_lesson', 'lesson_view', $lessonview,
get_string('privacy:metadata:userpref:lessonview', 'mod_lesson'));
}
}
/**
* Delete all data for all users in the specified context.
*
* @param context $context The specific context to delete data for.
*/
public static function delete_data_for_all_users_in_context(context $context) {
global $DB;
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
if (!$lessonid = static::get_lesson_id_from_context($context)) {
return;
}
$DB->delete_records('lesson_attempts', ['lessonid' => $lessonid]);
$DB->delete_records('lesson_branch', ['lessonid' => $lessonid]);
$DB->delete_records('lesson_grades', ['lessonid' => $lessonid]);
$DB->delete_records('lesson_timer', ['lessonid' => $lessonid]);
$DB->delete_records_select('lesson_overrides', 'lessonid = :id AND userid IS NOT NULL', ['id' => $lessonid]);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses');
$fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers');
}
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
global $DB;
$userid = $contextlist->get_user()->id;
$cmids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_MODULE) {
$carry[] = $context->instanceid;
}
return $carry;
}, []);
if (empty($cmids)) {
return;
}
// Find the lesson IDs.
$lessonidstocmids = static::get_lesson_ids_to_cmids_from_cmids($cmids);
$lessonids = array_keys($lessonidstocmids);
if (empty($lessonids)) {
return;
}
// Prepare the SQL we'll need below.
list($insql, $inparams) = $DB->get_in_or_equal($lessonids, SQL_PARAMS_NAMED);
$sql = "lessonid $insql AND userid = :userid";
$params = array_merge($inparams, ['userid' => $userid]);
// Delete the attempt files.
$fs = get_file_storage();
$recordset = $DB->get_recordset_select('lesson_attempts', $sql, $params, '', 'id, lessonid');
foreach ($recordset as $record) {
$cmid = $lessonidstocmids[$record->lessonid];
$context = context_module::instance($cmid);
$fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses', $record->id);
$fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers', $record->id);
}
$recordset->close();
// Delete all the things.
$DB->delete_records_select('lesson_attempts', $sql, $params);
$DB->delete_records_select('lesson_branch', $sql, $params);
$DB->delete_records_select('lesson_grades', $sql, $params);
$DB->delete_records_select('lesson_timer', $sql, $params);
$DB->delete_records_select('lesson_overrides', $sql, $params);
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
$context = $userlist->get_context();
$lessonid = static::get_lesson_id_from_context($context);
$userids = $userlist->get_userids();
if (empty($lessonid)) {
return;
}
// Prepare the SQL we'll need below.
list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$sql = "lessonid = :lessonid AND userid {$insql}";
$params = array_merge($inparams, ['lessonid' => $lessonid]);
// Delete the attempt files.
$fs = get_file_storage();
$recordset = $DB->get_recordset_select('lesson_attempts', $sql, $params, '', 'id, lessonid');
foreach ($recordset as $record) {
$fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses', $record->id);
$fs->delete_area_files($context->id, 'mod_lesson', 'essay_answers', $record->id);
}
$recordset->close();
// Delete all the things.
$DB->delete_records_select('lesson_attempts', $sql, $params);
$DB->delete_records_select('lesson_branch', $sql, $params);
$DB->delete_records_select('lesson_grades', $sql, $params);
$DB->delete_records_select('lesson_timer', $sql, $params);
$DB->delete_records_select('lesson_overrides', $sql, $params);
}
/**
* Get a survey ID from its context.
*
* @param context_module $context The module context.
* @return int
*/
protected static function get_lesson_id_from_context(context_module $context) {
$cm = get_coursemodule_from_id('lesson', $context->instanceid);
return $cm ? (int) $cm->instance : 0;
}
/**
* Return a dict of lesson IDs mapped to their course module ID.
*
* @param array $cmids The course module IDs.
* @return array In the form of [$lessonid => $cmid].
*/
protected static function get_lesson_ids_to_cmids_from_cmids(array $cmids) {
global $DB;
list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED);
$sql = "
SELECT l.id, cm.id AS cmid
FROM {lesson} l
JOIN {modules} m
ON m.name = :lesson
JOIN {course_modules} cm
ON cm.instance = l.id
AND cm.module = m.id
WHERE cm.id $insql";
$params = array_merge($inparams, ['lesson' => 'lesson']);
return $DB->get_records_sql_menu($sql, $params);
}
/**
* Loop and export from a recordset.
*
* @param moodle_recordset $recordset The recordset.
* @param string $splitkey The record key to determine when to export.
* @param mixed $initial The initial data to reduce from.
* @param callable $reducer The function to return the dataset, receives current dataset, and the current record.
* @param callable $export The function to export the dataset, receives the last value from $splitkey and the dataset.
* @return void
*/
protected static function recordset_loop_and_export(\moodle_recordset $recordset, $splitkey, $initial,
callable $reducer, callable $export) {
$data = $initial;
$lastid = null;
foreach ($recordset as $record) {
if ($lastid && $record->{$splitkey} != $lastid) {
$export($lastid, $data);
$data = $initial;
}
$data = $reducer($data, $record);
$lastid = $record->{$splitkey};
}
$recordset->close();
if (!empty($lastid)) {
$export($lastid, $data);
}
}
/**
* Transform an attempt.
*
* @param stdClass $data Data from the database, as per the exporting method.
* @param context_module $context The module context.
* @return array
*/
protected static function transform_attempt(stdClass $data, context_module $context) {
global $DB;
$options = ['context' => $context];
$answer = $data->attempt_useranswer;
$response = null;
$responsefilesfolder = null;
if ($answer !== null) {
if ($data->page_qtype == LESSON_PAGE_ESSAY) {
// Essay questions serialise data in the answer field.
$info = \lesson_page_type_essay::extract_useranswer($answer);
$answerfilespath = [get_string('privacy:path:essayanswers', 'mod_lesson'), $data->attempt_id];
$answer = format_text(
writer::with_context($context)->rewrite_pluginfile_urls(
$answerfilespath,
'mod_lesson',
'essay_answers',
$data->attempt_id,
$info->answer
),
$info->answerformat,
$options
);
writer::with_context($context)->export_area_files($answerfilespath, 'mod_lesson',
'essay_answers', $data->page_id);
if ($info->response !== null) {
// We export the files in a subfolder to avoid conflicting files, and tell the user
// where those files were exported. That is because we are not using a subfolder for
// every single essay response.
$responsefilespath = [get_string('privacy:path:essayresponses', 'mod_lesson'), $data->attempt_id];
$responsefilesfolder = implode('/', $responsefilespath);
$response = format_text(
writer::with_context($context)->rewrite_pluginfile_urls(
$responsefilespath,
'mod_lesson',
'essay_responses',
$data->attempt_id,
$info->response
),
$info->responseformat,
$options
);
writer::with_context($context)->export_area_files($responsefilespath, 'mod_lesson',
'essay_responses', $data->page_id);
}
} else if ($data->page_qtype == LESSON_PAGE_MULTICHOICE && $data->page_qoption) {
// Multiple choice quesitons with multiple answers encode the answers.
list($insql, $inparams) = $DB->get_in_or_equal(explode(',', $answer), SQL_PARAMS_NAMED);
$orderby = 'id, ' . $DB->sql_order_by_text('answer') . ', answerformat';
$records = $DB->get_records_select('lesson_answers', "id $insql", $inparams, $orderby);
$answer = array_values(array_map(function($record) use ($options) {
return format_text($record->answer, $record->answerformat, $options);
}, empty($records) ? [] : $records));
} else if ($data->page_qtype == LESSON_PAGE_MATCHING) {
// Matching questions need sorting.
$chosen = explode(',', $answer);
$answers = $DB->get_records_select('lesson_answers', 'pageid = :pageid', ['pageid' => $data->page_id],
'id', 'id, answer, answerformat', 2); // The two first entries are not options.
$i = -1;
$answer = array_values(array_map(function($record) use (&$i, $chosen, $options) {
$i++;
return [
'label' => format_text($record->answer, $record->answerformat, $options),
'matched_with' => array_key_exists($i, $chosen) ? $chosen[$i] : null
];
}, empty($answers) ? [] : $answers));
}
}
$result = [
'answer' => $answer,
'correct' => transform::yesno($data->attempt_correct),
'timeseen' => transform::datetime($data->attempt_timeseen),
];
if ($response !== null) {
$result['response'] = $response;
$result['response_files_folder'] = $responsefilesfolder;
}
return $result;
}
}
+58
View File
@@ -0,0 +1,58 @@
<?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/>.
/**
* Search area for mod_lesson activities.
*
* @package mod_lesson
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\search;
defined('MOODLE_INTERNAL') || die();
/**
* Search area for mod_lesson activities.
*
* @package mod_lesson
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {
/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array('intro', 'page_contents'); // Fileareas.
return $fileareas;
}
}