Merge branch 'MDL-41726-master-2nd' of git://github.com/FMCorz/moodle
Conflicts: lang/en/moodle.php
This commit is contained in:
@@ -668,6 +668,8 @@ $string['eventcoursedeleted'] = 'Course deleted';
|
||||
$string['eventcoursemodulecreated'] = 'Course module created';
|
||||
$string['eventcoursemoduledeleted'] = 'Course module deleted';
|
||||
$string['eventcoursemoduleupdated'] = 'Course module updated';
|
||||
$string['eventcourseresetended'] = 'Course reset ended';
|
||||
$string['eventcourseresetstarted'] = 'Course reset started';
|
||||
$string['eventcourserestored'] = 'Course restored';
|
||||
$string['eventcourseupdated'] = 'Course updated';
|
||||
$string['eventcoursesectionupdated'] = ' Course section updated';
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* core course reset ended event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* core course reset ended event class.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_reset_ended extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The reset of course $this->courseid has ended.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcourseresetended', 'core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/course/view.php', array('id' => $this->courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (!isset($this->other['reset_options'])) {
|
||||
throw new \coding_exception('The key reset_options must be set in $other.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* core course reset started event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* core course reset started event class.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_reset_started extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user $this->userid has started the reset of course $this->courseid.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcourseresetstarted', 'core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/course/view.php', array('id' => $this->courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (!isset($this->other['reset_options'])) {
|
||||
throw new \coding_exception('The key reset_options must be set in $other.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5168,6 +5168,16 @@ function reset_course_userdata($data) {
|
||||
$data->courseid = $data->id;
|
||||
$context = context_course::instance($data->courseid);
|
||||
|
||||
$eventparams = array(
|
||||
'context' => $context,
|
||||
'courseid' => $data->id,
|
||||
'other' => array(
|
||||
'reset_options' => (array) $data
|
||||
)
|
||||
);
|
||||
$event = \core\event\course_reset_started::create($eventparams);
|
||||
$event->trigger();
|
||||
|
||||
// Calculate the time shift of dates.
|
||||
if (!empty($data->reset_start_date)) {
|
||||
// Time part of course startdate should be zero.
|
||||
@@ -5389,6 +5399,9 @@ function reset_course_userdata($data) {
|
||||
comment::reset_course_page_comments($context);
|
||||
}
|
||||
|
||||
$event = \core\event\course_reset_ended::create($eventparams);
|
||||
$event->trigger();
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Group observers.
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_quiz;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
/**
|
||||
* Group observers class.
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @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'])) {
|
||||
quiz_process_group_deleted_in_course($event->courseid);
|
||||
}
|
||||
if (!empty($event->other['reset_options']['reset_groups_members'])) {
|
||||
quiz_update_open_attempts(array('courseid' => $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;
|
||||
}
|
||||
quiz_process_group_deleted_in_course($event->courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* A group member was removed.
|
||||
*
|
||||
* @param \core\event\base $event The event.
|
||||
* @return void
|
||||
*/
|
||||
public static function group_member_added($event) {
|
||||
quiz_update_open_attempts(array('userid' => $event->relateduserid, 'groupid' => $event->objectid));
|
||||
}
|
||||
|
||||
/**
|
||||
* A group member was deleted.
|
||||
*
|
||||
* @param \core\event\base $event The event.
|
||||
* @return void
|
||||
*/
|
||||
public static function group_member_removed($event) {
|
||||
if (!empty(self::$resetinprogress)) {
|
||||
// We will take care of that once the course reset ends.
|
||||
return;
|
||||
}
|
||||
quiz_update_open_attempts(array('userid' => $event->relateduserid, 'groupid' => $event->objectid));
|
||||
}
|
||||
|
||||
}
|
||||
+22
-18
@@ -44,28 +44,32 @@ $handlers = array(
|
||||
'schedule' => 'cron',
|
||||
),
|
||||
|
||||
// Handle group events, so that open quiz attempts with group overrides get
|
||||
// updated check times.
|
||||
'groups_member_added' => array (
|
||||
'handlerfile' => '/mod/quiz/locallib.php',
|
||||
'handlerfunction' => 'quiz_groups_member_added_handler',
|
||||
'schedule' => 'instant',
|
||||
);
|
||||
|
||||
$observers = array(
|
||||
|
||||
// Handle group events, so that open quiz attempts with group overrides get updated check times.
|
||||
array(
|
||||
'eventname' => '\core\event\course_reset_started',
|
||||
'callback' => '\mod_quiz\group_observers::course_reset_started',
|
||||
),
|
||||
'groups_member_removed' => array (
|
||||
'handlerfile' => '/mod/quiz/locallib.php',
|
||||
'handlerfunction' => 'quiz_groups_member_removed_handler',
|
||||
'schedule' => 'instant',
|
||||
array(
|
||||
'eventname' => '\core\event\course_reset_ended',
|
||||
'callback' => '\mod_quiz\group_observers::course_reset_ended',
|
||||
),
|
||||
'groups_members_removed' => array (
|
||||
'handlerfile' => '/mod/quiz/locallib.php',
|
||||
'handlerfunction' => 'quiz_groups_members_removed_handler',
|
||||
'schedule' => 'instant',
|
||||
array(
|
||||
'eventname' => '\core\event\group_deleted',
|
||||
'callback' => '\mod_quiz\group_observers::group_deleted'
|
||||
),
|
||||
'groups_group_deleted' => array (
|
||||
'handlerfile' => '/mod/quiz/locallib.php',
|
||||
'handlerfunction' => 'quiz_groups_group_deleted_handler',
|
||||
'schedule' => 'instant',
|
||||
array(
|
||||
'eventname' => '\core\event\group_member_added',
|
||||
'callback' => '\mod_quiz\group_observers::group_member_added',
|
||||
),
|
||||
array(
|
||||
'eventname' => '\core\event\group_member_removed',
|
||||
'callback' => '\mod_quiz\group_observers::group_member_removed',
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
/* List of events generated by the quiz module, with the fields on the event object.
|
||||
|
||||
+26
-3
@@ -1788,8 +1788,11 @@ function quiz_attempt_overdue_handler($event) {
|
||||
* Handle groups_member_added event
|
||||
*
|
||||
* @param object $event the event object.
|
||||
* @deprecated since 2.6, see {@link \mod_quiz\group_observers::group_member_added()}.
|
||||
*/
|
||||
function quiz_groups_member_added_handler($event) {
|
||||
debugging('quiz_groups_member_added_handler() is deprecated, please use ' .
|
||||
'\mod_quiz\group_observers::group_member_added() instead.', DEBUG_DEVELOPER);
|
||||
quiz_update_open_attempts(array('userid'=>$event->userid, 'groupid'=>$event->groupid));
|
||||
}
|
||||
|
||||
@@ -1797,8 +1800,11 @@ function quiz_groups_member_added_handler($event) {
|
||||
* Handle groups_member_removed event
|
||||
*
|
||||
* @param object $event the event object.
|
||||
* @deprecated since 2.6, see {@link \mod_quiz\group_observers::group_member_removed()}.
|
||||
*/
|
||||
function quiz_groups_member_removed_handler($event) {
|
||||
debugging('quiz_groups_member_removed_handler() is deprecated, please use ' .
|
||||
'\mod_quiz\group_observers::group_member_removed() instead.', DEBUG_DEVELOPER);
|
||||
quiz_update_open_attempts(array('userid'=>$event->userid, 'groupid'=>$event->groupid));
|
||||
}
|
||||
|
||||
@@ -1806,32 +1812,49 @@ function quiz_groups_member_removed_handler($event) {
|
||||
* Handle groups_group_deleted event
|
||||
*
|
||||
* @param object $event the event object.
|
||||
* @deprecated since 2.6, see {@link \mod_quiz\group_observers::group_deleted()}.
|
||||
*/
|
||||
function quiz_groups_group_deleted_handler($event) {
|
||||
global $DB;
|
||||
debugging('quiz_groups_group_deleted_handler() is deprecated, please use ' .
|
||||
'\mod_quiz\group_observers::group_deleted() instead.', DEBUG_DEVELOPER);
|
||||
quiz_process_group_deleted_in_course($event->courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic to happen when a/some group(s) has/have been deleted in a course.
|
||||
*
|
||||
* @param int $courseid The course ID.
|
||||
* @return void
|
||||
*/
|
||||
function quiz_process_group_deleted_in_course($courseid) {
|
||||
global $DB;
|
||||
|
||||
// It would be nice if we got the groupid that was deleted.
|
||||
// Instead, we just update all quizzes with orphaned group overrides
|
||||
// Instead, we just update all quizzes with orphaned group overrides.
|
||||
$sql = "SELECT o.id, o.quiz
|
||||
FROM {quiz_overrides} o
|
||||
JOIN {quiz} quiz ON quiz.id = o.quiz
|
||||
LEFT JOIN {groups} grp ON grp.id = o.groupid
|
||||
WHERE quiz.course = :courseid AND grp.id IS NULL";
|
||||
$params = array('courseid'=>$event->courseid);
|
||||
$params = array('courseid' => $courseid);
|
||||
$records = $DB->get_records_sql_menu($sql, $params);
|
||||
if (!$records) {
|
||||
return; // Nothing to do.
|
||||
}
|
||||
$DB->delete_records_list('quiz_overrides', 'id', array_keys($records));
|
||||
quiz_update_open_attempts(array('quizid'=>array_unique(array_values($records))));
|
||||
quiz_update_open_attempts(array('quizid' => array_unique(array_values($records))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle groups_members_removed event
|
||||
*
|
||||
* @param object $event the event object.
|
||||
* @deprecated since 2.6, see {@link \mod_quiz\group_observers::group_member_removed()}.
|
||||
*/
|
||||
function quiz_groups_members_removed_handler($event) {
|
||||
debugging('quiz_groups_members_removed_handler() is deprecated, please use ' .
|
||||
'\mod_quiz\group_observers::group_member_removed() instead.', DEBUG_DEVELOPER);
|
||||
if ($event->userid == 0) {
|
||||
quiz_update_open_attempts(array('courseid'=>$event->courseid));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user