MDL-40055 mod_assign: Replace add_to_log 'grant extension'

This commit is contained in:
Frederic Massart
2013-08-26 14:17:17 +08:00
parent a65b53036e
commit 76e77b05eb
4 changed files with 155 additions and 1 deletions
@@ -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/>.
/**
* mod_assign extension granted event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* mod_assign extension granted event class.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class extension_granted extends \core\event\base {
/**
* Legacy log data.
*
* @var array
*/
protected $legacylogdata;
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} has granted an extension to {$this->relateduserid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
public function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return \lang_string
*/
public static function get_name() {
return new \lang_string('event_extension_granted', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['level'] = 50; // TODO MDL-37658.
$this->data['objecttable'] = 'assign';
}
/**
* Sets the legacy event log data.
*
* @param stdClass $legacylogdata legacy log data.
* @return void
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
}
/**
* Custom validation.
*
* @throws coding_exception
* @return void
*/
protected function validate_data() {
if (!isset($this->relateduserid)) {
throw new coding_exception('relateduserid is a mandatory property.');
}
}
}
+1
View File
@@ -142,6 +142,7 @@ $string['editingstatus'] = 'Editing status';
$string['editaction'] = 'Actions...';
$string['event_assessable_submitted'] = 'A submission has been submitted.';
$string['event_all_submissions_downloaded'] = 'All the submissions are being downloaded.';
$string['event_extension_granted'] = 'An extension has been granted.';
$string['extensionduedate'] = 'Extension due date';
$string['extensionnotafterduedate'] = 'Extension date must be after the due date';
$string['extensionnotafterfromdate'] = 'Extension date must be after the allow submissions from date';
+9 -1
View File
@@ -4552,7 +4552,15 @@ class assign {
$result = $this->update_user_flags($flags);
if ($result) {
$this->add_to_log('grant extension', $userid);
$addtolog = $this->add_to_log('grant extension', $userid, '', true);
$params = array(
'context' => $this->context,
'objectid' => $flags->assignment,
'relateduserid' => $userid
);
$event = \mod_assign\event\extension_granted::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
}
return $result;
}
+32
View File
@@ -940,5 +940,37 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
$output = $assign->get_renderer()->render($gradingtable);
$this->assertNotEquals(true, strpos($output, $this->students[0]->lastname));
}
public function test_extension_granted_event() {
$this->setUser($this->editingteachers[0]);
$tomorrow = time() + 24*60*60;
$yesterday = time() - 24*60*60;
$assign = $this->create_instance(array('duedate' => $yesterday, 'cutoffdate' => $yesterday));
$sink = $this->redirectEvents();
$assign->testable_save_user_extension($this->students[0]->id, $tomorrow);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\extension_granted', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grant extension',
'view.php?id=' . $assign->get_course_module()->id,
$this->students[0]->id,
$assign->get_course_module()->id,
$this->editingteachers[0]->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
}