Skip to content

Commit

Permalink
Merge branch 'MDL-41726-master-2nd' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	lang/en/moodle.php
  • Loading branch information
stronk7 committed Sep 24, 2013
2 parents 394372b + 11b0c8e commit 18ccaca
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 21 deletions.
2 changes: 2 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@
$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';
Expand Down
86 changes: 86 additions & 0 deletions lib/classes/event/course_reset_ended.php
Original file line number Diff line number Diff line change
@@ -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.');
}
}

}
86 changes: 86 additions & 0 deletions lib/classes/event/course_reset_started.php
Original file line number Diff line number Diff line change
@@ -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.');
}
}

}
13 changes: 13 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
113 changes: 113 additions & 0 deletions mod/quiz/classes/group_observers.php
Original file line number Diff line number Diff line change
@@ -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));
}

}
40 changes: 22 additions & 18 deletions mod/quiz/db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,32 @@
'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.
Expand Down
Loading

0 comments on commit 18ccaca

Please sign in to comment.