MDL-39954 assignment_upload: Replacing old-style event_trigger
This commit is contained in:
@@ -512,8 +512,6 @@ class assignment_upload extends assignment_base {
|
||||
$updates->numfiles = count($fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, 'sortorder', false));
|
||||
$updates->timemodified = time();
|
||||
$DB->update_record('assignment_submissions', $updates);
|
||||
add_to_log($this->course->id, 'assignment', 'upload',
|
||||
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
|
||||
$this->update_grade($submission);
|
||||
if (!$this->drafts_tracked()) {
|
||||
$this->email_teachers($submission);
|
||||
@@ -521,18 +519,21 @@ class assignment_upload extends assignment_base {
|
||||
|
||||
// send files to event system
|
||||
$files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
|
||||
|
||||
// Let Moodle know that assessable files were uploaded (eg for plagiarism detection)
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = 'assignment';
|
||||
$eventdata->cmid = $this->cm->id;
|
||||
$eventdata->itemid = $submission->id;
|
||||
$eventdata->courseid = $this->course->id;
|
||||
$eventdata->userid = $USER->id;
|
||||
if ($files) {
|
||||
$eventdata->files = $files; // This is depreceated - please use pathnamehashes instead!
|
||||
}
|
||||
$eventdata->pathnamehashes = array_keys($files);
|
||||
events_trigger('assessable_file_uploaded', $eventdata);
|
||||
$params = array(
|
||||
'context' => $this->context,
|
||||
'objectid' => $submission->id,
|
||||
'other' => array(
|
||||
'assignmentid' => $this->assignment->id,
|
||||
'content' => '',
|
||||
'pathnamehashes' => array_keys($files)
|
||||
)
|
||||
);
|
||||
$event = \assignment_upload\event\assessable_uploaded::create($params);
|
||||
$event->set_legacy_files($files);
|
||||
$event->trigger();
|
||||
|
||||
$returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id));
|
||||
redirect($returnurl);
|
||||
}
|
||||
@@ -639,14 +640,17 @@ class assignment_upload extends assignment_base {
|
||||
$this->update_grade($submission);
|
||||
$this->email_teachers($submission);
|
||||
|
||||
// Trigger assessable_files_done event to show files are complete
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = 'assignment';
|
||||
$eventdata->cmid = $this->cm->id;
|
||||
$eventdata->itemid = $submission->id;
|
||||
$eventdata->courseid = $this->course->id;
|
||||
$eventdata->userid = $userid;
|
||||
events_trigger('assessable_files_done', $eventdata);
|
||||
// Trigger assessable_submitted event to show files are complete.
|
||||
$params = array(
|
||||
'context' => $this->context,
|
||||
'objectid' => $submission->id,
|
||||
'other' => array(
|
||||
'assignmentid' => $this->assignment->id,
|
||||
'submission_editable' => false
|
||||
)
|
||||
);
|
||||
$event = \assignment_upload\event\assessable_submitted::create($params);
|
||||
$event->trigger();
|
||||
|
||||
if ($forcemode==null) {
|
||||
redirect($returnurl->out(false));
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* assignment_submitted assessable uploaded event.
|
||||
*
|
||||
* @package assignment_submitted
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace assignment_submitted\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* assignment_submitted assessable uploaded event class.
|
||||
*
|
||||
* @package assignment_submitted
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class assessable_submitted extends \core\event\assessable_submitted {
|
||||
|
||||
/**
|
||||
* Returns localised description of what happened.
|
||||
*
|
||||
* @return \lang_string
|
||||
*/
|
||||
public function get_description() {
|
||||
return new \lang_string('event_assessable_submitted_desc', 'assignment_submitted', $this->get_data());
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event data if get_legacy_eventname() is not empty.
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function get_legacy_eventdata() {
|
||||
$eventdata = new \stdClass();
|
||||
$eventdata->modulename = 'assignment';
|
||||
$eventdata->cmid = $this->context->instanceid;
|
||||
$eventdata->itemid = $this->objectid;
|
||||
$eventdata->courseid = $this->courseid;
|
||||
$eventdata->userid = $this->userid;
|
||||
return $eventdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_legacy_eventname() {
|
||||
return 'assessable_files_done';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get legacy log data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'assignment', 'upload', 'view.php?a='.$this->other['assignmentid'],
|
||||
$this->other['assignmentid'], $this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return \lang_string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return new \lang_string('event_assessable_submitted', 'assignment_submitted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/assignment/view.php', array('id' => $this->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
parent::init();
|
||||
$this->data['objecttable'] = 'assignment_submissions';
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation
|
||||
*
|
||||
* @throws coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
if (!isset($this->other['submission_editable'])) {
|
||||
throw new coding_exception('Other must contain the key submission_editable.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* assignment_upload assessable uploaded event.
|
||||
*
|
||||
* @package assignment_upload
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace assignment_upload\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* assignment_upload assessable uploaded event class.
|
||||
*
|
||||
* @package assignment_upload
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class assessable_uploaded extends \core\event\assessable_uploaded {
|
||||
|
||||
/**
|
||||
* Legacy files.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $legacyfiles;
|
||||
|
||||
/**
|
||||
* Returns localised description of what happened.
|
||||
*
|
||||
* @return \lang_string
|
||||
*/
|
||||
public function get_description() {
|
||||
return new \lang_string('event_assessable_uploaded_desc', 'assignment_upload', $this->get_data());
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event data if get_legacy_eventname() is not empty.
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function get_legacy_eventdata() {
|
||||
$eventdata = new \stdClass();
|
||||
$eventdata->modulename = 'assignment';
|
||||
$eventdata->cmid = $this->context->instanceid;
|
||||
$eventdata->itemid = $this->objectid;
|
||||
$eventdata->courseid = $this->courseid;
|
||||
$eventdata->userid = $this->userid;
|
||||
if ($this->get_legacy_files()) {
|
||||
$eventdata->files = $this->get_legacy_files(); // This is depreceated - please use pathnamehashes instead!
|
||||
}
|
||||
$eventdata->pathnamehashes = $this->other['pathnamehashes'];
|
||||
return $eventdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_legacy_eventname() {
|
||||
return 'assessable_file_uploaded';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get legacy log data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'assignment', 'upload', 'view.php?a=' . $this->other['assignmentid'],
|
||||
$this->other['assignmentid'], $this->context->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return \lang_string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return new \lang_string('event_assessable_uploaded', 'assignment_upload');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/assignment/view.php', array('id' => $this->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
parent::init();
|
||||
$this->data['objecttable'] = 'assignment_submissions';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set legacy files.
|
||||
*
|
||||
* @param array $files
|
||||
* @return void
|
||||
*/
|
||||
public function set_legacy_files($files) {
|
||||
$this->legacyfiles = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation
|
||||
*
|
||||
* @throws coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
if (!isset($this->other['triggeredfrom'])) {
|
||||
throw new coding_exception('triggeredfrom must be set in $other');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['event_assessable_submitted'] = 'An upload submission has been submitted.';
|
||||
$string['event_assessable_submitted_desc'] = 'User {$a->userid} has submitted the upload submission {$a->objectid}.';
|
||||
$string['event_assessable_uploaded'] = 'A file has been uploaded.';
|
||||
$string['event_assessable_uploaded_desc'] = 'User {$a->userid} has uploaded a file in submission {$a->objectid}.';
|
||||
$string['pluginname'] = 'Upload';
|
||||
|
||||
Reference in New Issue
Block a user