MDL-40055 mod_assign: Replace add_to_log 'submissioncopied'

This commit is contained in:
Frederic Massart
2013-08-26 14:17:18 +08:00
parent 8bb213eb60
commit 89fbc20263
5 changed files with 154 additions and 1 deletions
@@ -0,0 +1,102 @@
<?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 duplicated 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 duplicated 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_duplicated extends \core\event\base {
/**
* Legacy log data.
*
* @var array
*/
protected $legacylogdata;
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user {$this->userid} duplicated his submission {$this->objectid}.";
}
/**
* 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_duplicated', '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'] = 'c';
$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;
}
}
+1
View File
@@ -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_marker_updated'] = 'The allocated marker has been updated.';
$string['event_submission_duplicated'] = 'The user duplicated his submission.';
$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['event_workflow_state_updated'] = 'The state of the workflow has been updated.';
+8 -1
View File
@@ -5037,7 +5037,14 @@ class assign {
return false;
}
$this->add_to_log('submissioncopied', $this->format_submission_for_log($submission));
$addtolog = $this->add_to_log('submissioncopied', $this->format_submission_for_log($submission), '', true);
$params = array(
'context' => $this->context,
'objectid' => $submission->id
);
$event = \mod_assign\event\submission_duplicated::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
$complete = COMPLETION_INCOMPLETE;
if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
+8
View File
@@ -239,6 +239,10 @@ class testable_assign extends assign {
return parent::apply_grade_to_user($formdata, $userid, $attemptnumber);
}
public function testable_format_submission_for_log(stdClass $submission) {
return parent::format_submission_for_log($submission);
}
public function testable_get_grading_userid_list() {
return parent::get_grading_userid_list();
}
@@ -259,6 +263,10 @@ class testable_assign extends assign {
return parent::process_lock($userid);
}
public function testable_process_copy_previous_attempt(&$notices) {
return parent::process_copy_previous_attempt($notices);
}
public function testable_process_revert_to_draft($userid = 0) {
return parent::process_revert_to_draft($userid);
}
+35
View File
@@ -1142,5 +1142,40 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_duplicated_event() {
$this->setUser($this->students[0]);
$assign = $this->create_instance();
$submission1 = $assign->get_user_submission($this->students[0]->id, true, 0);
$submission2 = $assign->get_user_submission($this->students[0]->id, true, 1);
$submission2->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
$assign->testable_update_submission($submission2, $this->students[0]->id, time(), $assign->get_instance()->teamsubmission);
$sink = $this->redirectEvents();
$notices = null;
$assign->testable_process_copy_previous_attempt($notices);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_duplicated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission2->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->userid);
$submission2->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
$expected = array(
$assign->get_course()->id,
'assign',
'submissioncopied',
'view.php?id=' . $assign->get_course_module()->id,
$assign->testable_format_submission_for_log($submission2),
$assign->get_course_module()->id,
$this->students[0]->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
}