diff --git a/mod/assign/classes/event/submission_unlocked.php b/mod/assign/classes/event/submission_unlocked.php new file mode 100644 index 00000000000..e17841cef61 --- /dev/null +++ b/mod/assign/classes/event/submission_unlocked.php @@ -0,0 +1,113 @@ +. + +/** + * mod_assign submission unlocked 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 unlocked 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_unlocked 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} unlocked the submission for user {$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_submission_unlocked', '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.'); + } + } +} diff --git a/mod/assign/lang/en/assign.php b/mod/assign/lang/en/assign.php index 26e0c9a1439..f590ab98541 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -149,6 +149,7 @@ $string['event_statement_accepted'] = 'The user has accepted the statement of th $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_submission_unlocked'] = 'The submissions have been unlocked for a user.'; $string['event_submission_updated'] = 'The user has saved a submission.'; $string['event_workflow_state_updated'] = 'The state of the workflow has been updated.'; $string['extensionduedate'] = 'Extension due date'; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 99201b479a8..4355b0f3ae7 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -5886,7 +5886,15 @@ class assign { $logmessage = get_string('unlocksubmissionforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user))); - $this->add_to_log('unlock submission', $logmessage); + $addtolog = $this->add_to_log('unlock submission', $logmessage, '', true); + $params = array( + 'context' => $this->context, + 'objectid' => $flags->assignment, + 'relateduserid' => $user->id + ); + $event = \mod_assign\event\submission_unlocked::create($params); + $event->set_legacy_logdata($addtolog); + $event->trigger(); } /** diff --git a/mod/assign/tests/base_test.php b/mod/assign/tests/base_test.php index ff01dbdb85e..17db4f23a0d 100644 --- a/mod/assign/tests/base_test.php +++ b/mod/assign/tests/base_test.php @@ -263,6 +263,10 @@ class testable_assign extends assign { return parent::process_lock($userid); } + public function testable_process_unlock($userid = 0) { + return parent::process_unlock($userid); + } + public function testable_process_copy_previous_attempt(&$notices) { return parent::process_copy_previous_attempt($notices); } diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 587e64bcf2a..494a271f3c2 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -1177,5 +1177,38 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase { $sink->close(); } + public function test_submission_unlocked_event() { + $this->editingteachers[0]->ignoresesskey = true; + $this->setUser($this->editingteachers[0]); + + $assign = $this->create_instance(); + $sink = $this->redirectEvents(); + + $assign->testable_process_unlock($this->students[0]->id); + + $events = $sink->get_events(); + $this->assertCount(1, $events); + $event = reset($events); + $this->assertInstanceOf('\mod_assign\event\submission_unlocked', $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', + 'unlock submission', + 'view.php?id=' . $assign->get_course_module()->id, + get_string('unlocksubmissionforstudent', '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; + } + }