Skip to content

Commit

Permalink
Merge branch 'MDL-29795_master' of https://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Nov 7, 2016
2 parents 741c0e6 + 325ac74 commit cf4019c
Show file tree
Hide file tree
Showing 33 changed files with 3,340 additions and 15 deletions.
15 changes: 15 additions & 0 deletions mod/assign/backup/moodle2/backup_assign_stepslib.php
Expand Up @@ -130,6 +130,10 @@ protected function define_structure() {
'name',
'value'));

$overrides = new backup_nested_element('overrides');
$override = new backup_nested_element('override', array('id'), array(
'groupid', 'userid', 'allowsubmissionsfromdate', 'duedate', 'cutoffdate'));

// Build the tree.
$assign->add_child($userflags);
$userflags->add_child($userflag);
Expand All @@ -139,12 +143,17 @@ protected function define_structure() {
$grades->add_child($grade);
$assign->add_child($pluginconfigs);
$pluginconfigs->add_child($pluginconfig);
$assign->add_child($overrides);
$overrides->add_child($override);

// Define sources.
$assign->set_source_table('assign', array('id' => backup::VAR_ACTIVITYID));
$pluginconfig->set_source_table('assign_plugin_config',
array('assignment' => backup::VAR_PARENTID));

// Assign overrides to backup are different depending of user info.
$overrideparams = array('assignid' => backup::VAR_PARENTID);

if ($userinfo) {
$userflag->set_source_table('assign_user_flags',
array('assignment' => backup::VAR_PARENTID));
Expand All @@ -158,8 +167,12 @@ protected function define_structure() {
// Support 2 types of subplugins.
$this->add_subplugin_structure('assignsubmission', $submission, true);
$this->add_subplugin_structure('assignfeedback', $grade, true);
} else {
$overrideparams['userid'] = backup_helper::is_sqlparam(null); // Without userinfo, skip user overrides.
}

$override->set_source_table('assign_overrides', $overrideparams);

// Define id annotations.
$userflag->annotate_ids('user', 'userid');
$userflag->annotate_ids('user', 'allocatedmarker');
Expand All @@ -168,6 +181,8 @@ protected function define_structure() {
$grade->annotate_ids('user', 'userid');
$grade->annotate_ids('user', 'grader');
$assign->annotate_ids('grouping', 'teamsubmissiongroupingid');
$override->annotate_ids('user', 'userid');
$override->annotate_ids('group', 'groupid');

// Define file annotations.
// These file areas don't have an itemid.
Expand Down
39 changes: 39 additions & 0 deletions mod/assign/backup/moodle2/restore_assign_stepslib.php
Expand Up @@ -65,6 +65,7 @@ protected function define_structure() {
$userflag = new restore_path_element('assign_userflag',
'/activity/assign/userflags/userflag');
$paths[] = $userflag;
$paths[] = new restore_path_element('assign_override', '/activity/assign/overrides/override');
}
$paths[] = new restore_path_element('assign_plugin_config',
'/activity/assign/plugin_configs/plugin_config');
Expand Down Expand Up @@ -359,6 +360,44 @@ protected function add_plugin_config_files($subtype) {
}
}

/**
* Process a assign override restore
* @param object $data The data in object form
* @return void
*/
protected function process_assign_override($data) {
global $DB;

$data = (object)$data;
$oldid = $data->id;

// Based on userinfo, we'll restore user overides or no.
$userinfo = $this->get_setting_value('userinfo');

// Skip user overrides if we are not restoring userinfo.
if (!$userinfo && !is_null($data->userid)) {
return;
}

$data->assignid = $this->get_new_parentid('assign');

if (!is_null($data->userid)) {
$data->userid = $this->get_mappingid('user', $data->userid);
}
if (!is_null($data->groupid)) {
$data->groupid = $this->get_mappingid('group', $data->groupid);
}

$data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate);
$data->duedate = $this->apply_date_offset($data->duedate);
$data->cutoffdate = $this->apply_date_offset($data->cutoffdate);

$newitemid = $DB->insert_record('assign_overrides', $data);

// Add mapping, restore of logs needs it.
$this->set_mapping('assign_override', $oldid, $newitemid);
}

/**
* Once the database tables have been fully restored, restore the files
* @return void
Expand Down
118 changes: 118 additions & 0 deletions mod/assign/classes/event/group_override_created.php
@@ -0,0 +1,118 @@
<?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_assign group override created event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_assign\event;

defined('MOODLE_INTERNAL') || die();

/**
* The mod_assign group override created event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* - int groupid: the id of the group.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @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'] = 'assign_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_assign');
}

/**
* 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 assign 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/assign/overrideedit.php', array('id' => $this->objectid));
}

/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();

if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}

if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}

/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}

/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');

return $othermapped;
}
}
117 changes: 117 additions & 0 deletions mod/assign/classes/event/group_override_deleted.php
@@ -0,0 +1,117 @@
<?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_assign group override deleted event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;

defined('MOODLE_INTERNAL') || die();

/**
* The mod_assign group override deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* - int groupid: the id of the group.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @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'] = 'assign_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_assign');
}

/**
* 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 assign 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/assign/overrides.php', array('cmid' => $this->contextinstanceid));
}

/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();

if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}

if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}

/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}

/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');

return $othermapped;
}
}

0 comments on commit cf4019c

Please sign in to comment.