mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-40055 mod_assign: Replace add_to_log 'revert submission to draft'
This commit is contained in:
parent
ad10ad1415
commit
159b7f4024
113
mod/assign/classes/event/submission_status_updated.php
Normal file
113
mod/assign/classes/event/submission_status_updated.php
Normal file
@ -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 submission status updated 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 submission status updated 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 submission_status_updated 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 updated the status of the submission {$this->objectid} to {$this->other['newstatus']}.";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_submission_status_updated', '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_submission';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->other['newstatus'])) {
|
||||
throw new coding_exception('newstatus must be set in $other.');
|
||||
}
|
||||
}
|
||||
}
|
@ -145,6 +145,7 @@ $string['event_all_submissions_downloaded'] = 'All the submissions are being dow
|
||||
$string['event_extension_granted'] = 'An extension has been granted.';
|
||||
$string['event_identities_revealed'] = 'The identities have been revealed.';
|
||||
$string['event_submission_locked'] = 'The submissions have been locked for a user.';
|
||||
$string['event_submission_status_updated'] = 'The status of the submission has been updated.';
|
||||
$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';
|
||||
|
@ -5655,7 +5655,18 @@ class assign {
|
||||
$logmessage = get_string('reverttodraftforstudent',
|
||||
'assign',
|
||||
array('id'=>$user->id, 'fullname'=>fullname($user)));
|
||||
$this->add_to_log('revert submission to draft', $logmessage);
|
||||
$addtolog = $this->add_to_log('revert submission to draft', $logmessage, '', true);
|
||||
$params = array(
|
||||
'context' => $this->context,
|
||||
'objectid' => $submission->id,
|
||||
'relateduserid' => ($this->get_instance()->teamsubmission) ? null : $userid,
|
||||
'other' => array(
|
||||
'newstatus' => $submission->status
|
||||
)
|
||||
);
|
||||
$event = \mod_assign\event\submission_status_updated::create($params);
|
||||
$event->set_legacy_logdata($addtolog);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -259,6 +259,10 @@ class testable_assign extends assign {
|
||||
return parent::process_lock($userid);
|
||||
}
|
||||
|
||||
public function testable_process_revert_to_draft($userid = 0) {
|
||||
return parent::process_revert_to_draft($userid);
|
||||
}
|
||||
|
||||
public function testable_submissions_open($userid = 0) {
|
||||
return parent::submissions_open($userid);
|
||||
}
|
||||
|
@ -1036,5 +1036,42 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
|
||||
$this->editingteachers[0]->ignoresesskey = false;
|
||||
}
|
||||
|
||||
public function test_submission_status_updated_event() {
|
||||
$this->editingteachers[0]->ignoresesskey = true;
|
||||
$this->setUser($this->editingteachers[0]);
|
||||
|
||||
$assign = $this->create_instance();
|
||||
$submission = $assign->get_user_submission($this->students[0]->id, true);
|
||||
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
|
||||
$assign->testable_update_submission($submission, $this->students[0]->id, true, false);
|
||||
|
||||
$sink = $this->redirectEvents();
|
||||
$assign->testable_process_revert_to_draft($this->students[0]->id);
|
||||
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
$this->assertInstanceOf('\mod_assign\event\submission_status_updated', $event);
|
||||
$this->assertEquals($assign->get_context(), $event->get_context());
|
||||
$this->assertEquals($submission->id, $event->objectid);
|
||||
$this->assertEquals($this->students[0]->id, $event->relateduserid);
|
||||
$this->assertEquals(ASSIGN_SUBMISSION_STATUS_DRAFT, $event->other['newstatus']);
|
||||
$expected = array(
|
||||
$assign->get_course()->id,
|
||||
'assign',
|
||||
'revert submission to draft',
|
||||
'view.php?id=' . $assign->get_course_module()->id,
|
||||
get_string('reverttodraftforstudent', 'assign', array('id' => $this->students[0]->id,
|
||||
'fullname' => fullname($this->students[0]))),
|
||||
$assign->get_course_module()->id,
|
||||
$this->editingteachers[0]->id
|
||||
);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
$sink->close();
|
||||
|
||||
// Revert to defaults.
|
||||
$this->editingteachers[0]->ignoresesskey = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user