diff --git a/mod/workshop/classes/event/assessable_uploaded.php b/mod/workshop/classes/event/assessable_uploaded.php new file mode 100644 index 00000000000..df889c5a959 --- /dev/null +++ b/mod/workshop/classes/event/assessable_uploaded.php @@ -0,0 +1,130 @@ +. + +/** + * mod_workshop assessable uploaded event. + * + * @package mod_workshop + * @copyright 2013 Frédéric Massart + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop assessable uploaded event class. + * + * @package mod_workshop + * @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 log data. + * + * @var array + */ + protected $legacylogdata = null; + + /** + * Returns localised description of what happened. + * + * @return \lang_string + */ + public function get_description() { + return new \lang_string('event_assessable_uploaded_desc', 'mod_workshop', $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 = 'workshop'; + $eventdata->cmid = $this->context->instanceid; + $eventdata->itemid = $this->objectid; + $eventdata->courseid = $this->courseid; + $eventdata->userid = $this->userid; + $eventdata->content = $this->other['content']; + if ($this->other['pathnamehashes']) { + $eventdata->pathnamehashes = $this->other['pathnamehashes']; + } + return $eventdata; + } + + /** + * Return the legacy event name. + * + * @return string + */ + protected function get_legacy_eventname() { + return 'assessable_content_uploaded'; + } + + /** + * Return the legacy log data. + * + * @return array + */ + protected function get_legacy_logdata() { + return $this->legacylogdata; + } + + /** + * Return localised event name. + * + * @return \lang_string + */ + public static function get_name() { + return new \lang_string('event_assessable_uploaded', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/submission.php', + array('cmid' => $this->context->instanceid, 'id' => $this->objectid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + parent::init(); + $this->data['objecttable'] = 'workshop_submissions'; + } + + /** + * Set the legacy log data. + * + * @param array $legacylogdata + * @return void + */ + public function set_legacy_logdata($legacylogdata) { + $this->legacylogdata = $legacylogdata; + } + +} diff --git a/mod/workshop/lang/en/workshop.php b/mod/workshop/lang/en/workshop.php index 73fd955c8a4..8931e40a342 100644 --- a/mod/workshop/lang/en/workshop.php +++ b/mod/workshop/lang/en/workshop.php @@ -106,6 +106,8 @@ $string['evaluation'] = 'Grading evaluation'; $string['evaluationmethod'] = 'Grading evaluation method'; $string['evaluationmethod_help'] = 'The grading evaluation method determines how the grade for assessment is calculated. You can let it re-calculate grades repeatedly with different settings unless you are happy with the result.'; $string['evaluationsettings'] = 'Grading evaluation settings'; +$string['event_assessable_uploaded'] = 'A submission has been uploaded.'; +$string['event_assessable_uploaded_desc'] = 'User {$a->userid} has uploaded the submission {$a->objectid}.'; $string['example'] = 'Example submission'; $string['exampleadd'] = 'Add example submission'; $string['exampleassess'] = 'Assess example submission'; diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index c377cf0a00e..53f3b58c526 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -1510,8 +1510,10 @@ class workshop { * @param string $action to be logged * @param moodle_url $url absolute url as returned by {@see workshop::submission_url()} and friends * @param mixed $info additional info, usually id in a table + * @param bool $return true to return the arguments for add_to_log. + * @return void|array array of arguments for add_to_log if $return is true */ - public function log($action, moodle_url $url = null, $info = null) { + public function log($action, moodle_url $url = null, $info = null, $return = false) { if (is_null($url)) { $url = $this->view_url(); @@ -1522,7 +1524,11 @@ class workshop { } $logurl = $this->log_convert_url($url); - add_to_log($this->course->id, 'workshop', $action, $logurl, $info, $this->cm->id); + $args = array($this->course->id, 'workshop', $action, $logurl, $info, $this->cm->id); + if ($return) { + return $args; + } + call_user_func_array('add_to_log', $args); } /** diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php index 3d56078d02e..183889ce6c8 100644 --- a/mod/workshop/submission.php +++ b/mod/workshop/submission.php @@ -187,11 +187,12 @@ if ($edit) { if ($workshop->phase == workshop::PHASE_ASSESSMENT) { $formdata->late = $formdata->late | 0x2; } + $logdata = null; if (is_null($submission->id)) { $submission->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata); - $workshop->log('add submission', $workshop->submission_url($submission->id), $submission->id); + $logdata = $workshop->log('add submission', $workshop->submission_url($submission->id), $submission->id, true); } else { - $workshop->log('update submission', $workshop->submission_url($submission->id), $submission->id); + $logdata = $workshop->log('update submission', $workshop->submission_url($submission->id), $submission->id, true); if (empty($formdata->id) or empty($submission->id) or ($formdata->id != $submission->id)) { throw new moodle_exception('err_submissionid', 'workshop'); } @@ -211,17 +212,18 @@ if ($edit) { // send submitted content for plagiarism detection $fs = get_file_storage(); $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id); - $eventdata = new stdClass(); - $eventdata->modulename = 'workshop'; - $eventdata->cmid = $cm->id; - $eventdata->itemid = $submission->id; - $eventdata->courseid = $course->id; - $eventdata->userid = $USER->id; - $eventdata->content = $formdata->content; - if ($files) { - $eventdata->pathnamehashes = array_keys($files); - } - events_trigger('assessable_content_uploaded', $eventdata); + + $params = array( + 'context' => $workshop->context, + 'objectid' => $submission->id, + 'other' => array( + 'content' => $formdata->content, + 'files' => array_keys($files) + ) + ); + $event = \mod_workshop\event\assessable_uploaded::create($params); + $event->set_legacy_logdata($logdata); + $event->trigger(); redirect($workshop->submission_url($formdata->id)); }