MDL-39954 mod_workshop: Log method can return array of parameters

This commit is contained in:
Frederic Massart
2013-08-12 17:35:29 +08:00
parent 62b3b99784
commit cbf4b0e6f6
4 changed files with 155 additions and 15 deletions
@@ -0,0 +1,130 @@
<?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_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;
}
}
+2
View File
@@ -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';
+8 -2
View File
@@ -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);
}
/**
+15 -13
View File
@@ -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));
}