From 1f0132716e8d9cc0e2c427fae0184d4cde4086cc Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Fri, 24 Jan 2014 09:59:40 +0800 Subject: [PATCH] MDL-40921 mod_workshop: New events to replace add_to_log function calls. --- mod/workshop/aggregate.php | 1 - mod/workshop/assessment.php | 23 ++++- .../classes/event/assessable_uploaded.php | 2 +- .../classes/event/assessment_evaluated.php | 83 ++++++++++++++++ .../event/assessment_evaluations_reset.php | 86 +++++++++++++++++ .../classes/event/assessment_reevaluated.php | 93 ++++++++++++++++++ .../classes/event/assessments_reset.php | 86 +++++++++++++++++ .../classes/event/instances_list_viewed.php | 75 +++++++++++++++ mod/workshop/classes/event/phase_switched.php | 92 ++++++++++++++++++ .../classes/event/submission_assessed.php | 93 ++++++++++++++++++ .../classes/event/submission_created.php | 91 ++++++++++++++++++ .../classes/event/submission_reassessed.php | 94 +++++++++++++++++++ .../classes/event/submission_updated.php | 91 ++++++++++++++++++ .../classes/event/submission_viewed.php | 91 ++++++++++++++++++ mod/workshop/exassessment.php | 13 --- mod/workshop/exsubmission.php | 4 - mod/workshop/index.php | 6 +- mod/workshop/lang/en/workshop.php | 14 ++- mod/workshop/lib.php | 13 ++- mod/workshop/locallib.php | 22 ++++- mod/workshop/submission.php | 43 ++++++--- mod/workshop/toolbox.php | 12 ++- mod/workshop/view.php | 4 +- 23 files changed, 1089 insertions(+), 43 deletions(-) create mode 100644 mod/workshop/classes/event/assessment_evaluated.php create mode 100644 mod/workshop/classes/event/assessment_evaluations_reset.php create mode 100644 mod/workshop/classes/event/assessment_reevaluated.php create mode 100644 mod/workshop/classes/event/assessments_reset.php create mode 100644 mod/workshop/classes/event/instances_list_viewed.php create mode 100644 mod/workshop/classes/event/phase_switched.php create mode 100644 mod/workshop/classes/event/submission_assessed.php create mode 100644 mod/workshop/classes/event/submission_created.php create mode 100644 mod/workshop/classes/event/submission_reassessed.php create mode 100644 mod/workshop/classes/event/submission_updated.php create mode 100644 mod/workshop/classes/event/submission_viewed.php diff --git a/mod/workshop/aggregate.php b/mod/workshop/aggregate.php index ee8fb9b35ef..5bd49baaafd 100644 --- a/mod/workshop/aggregate.php +++ b/mod/workshop/aggregate.php @@ -53,7 +53,6 @@ if ($settingsdata = $settingsform->get_data()) { $workshop->aggregate_submission_grades(); // updates 'grade' in {workshop_submissions} $evaluator->update_grading_grades($settingsdata); // updates 'gradinggrade' in {workshop_assessments} $workshop->aggregate_grading_grades(); // updates 'gradinggrade' in {workshop_aggregations} - $workshop->log('update aggregate grades'); } redirect(new moodle_url($workshop->view_url(), compact('page', 'sortby', 'sorthow'))); diff --git a/mod/workshop/assessment.php b/mod/workshop/assessment.php index d120d12b29f..b40f2c2d8a6 100644 --- a/mod/workshop/assessment.php +++ b/mod/workshop/assessment.php @@ -161,11 +161,6 @@ if (is_null($assessment->grade) and !$assessmenteditable) { if ($mform->is_cancelled()) { redirect($workshop->view_url()); } elseif ($assessmenteditable and ($data = $mform->get_data())) { - if (is_null($assessment->grade)) { - $workshop->log('add assessment', $workshop->assess_url($assessment->id), $assessment->submissionid); - } else { - $workshop->log('update assessment', $workshop->assess_url($assessment->id), $assessment->submissionid); - } // Let the grading strategy subplugin save its data. $rawgrade = $strategy->save_assessment($assessment, $data); @@ -194,6 +189,24 @@ if (is_null($assessment->grade) and !$assessmenteditable) { // Update the assessment data if there is something other than just the 'id'. if (count((array)$coredata) > 1 ) { $DB->update_record('workshop_assessments', $coredata); + $params = array( + 'objectid' => $assessment->id, + 'context' => $workshop->context, + 'other' => array( + 'workshopid' => $workshop->id, + 'submissionid' => $assessment->submissionid + ) + ); + + if (is_null($assessment->grade)) { + // All workshop_assessments are created when allocations are made. The create event is of more use located here. + $event = \mod_workshop\event\submission_assessed::create($params); + $event->trigger(); + } else { + $params['other']['grade'] = $assessment->grade; + $event = \mod_workshop\event\submission_reassessed::create($params); + $event->trigger(); + } } // And finally redirect the user's browser. diff --git a/mod/workshop/classes/event/assessable_uploaded.php b/mod/workshop/classes/event/assessable_uploaded.php index 591fb6c5b8f..38de4388960 100644 --- a/mod/workshop/classes/event/assessable_uploaded.php +++ b/mod/workshop/classes/event/assessable_uploaded.php @@ -101,7 +101,7 @@ class assessable_uploaded extends \core\event\assessable_uploaded { * @return string */ public static function get_name() { - return get_string('event_assessable_uploaded', 'mod_workshop'); + return get_string('eventassessableuploaded', 'mod_workshop'); } /** diff --git a/mod/workshop/classes/event/assessment_evaluated.php b/mod/workshop/classes/event/assessment_evaluated.php new file mode 100644 index 00000000000..9341cbd7617 --- /dev/null +++ b/mod/workshop/classes/event/assessment_evaluated.php @@ -0,0 +1,83 @@ +. + +/** + * mod_workshop assessment evaluated event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop assessment evaluated event class. + * + * @property-read array $other { + * Extra information about the event. + * + * @type string currentgrade current saved grade. + * @type string finalgrade final grade. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class assessment_evaluated extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'workshop_aggregations'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'An assessment has been evaluated ' . $this->objectid . '.'; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventassessmentevaluated', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); + } +} diff --git a/mod/workshop/classes/event/assessment_evaluations_reset.php b/mod/workshop/classes/event/assessment_evaluations_reset.php new file mode 100644 index 00000000000..fd45c3806fc --- /dev/null +++ b/mod/workshop/classes/event/assessment_evaluations_reset.php @@ -0,0 +1,86 @@ +. + +/** + * mod_workshop assessment_evaluations reset event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop assessment_evaluations reset event class. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class assessment_evaluations_reset extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_TEACHING; + $this->data['objecttable'] = 'workshop_aggregations'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'The assessment evaluations have been reset ' . $this->objectid . '.'; + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'update clear aggregated grade', 'view.php?id=' . $this->contextinstanceid, + $this->objectid, $this->contextinstanceid); + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventassessmentevaluationsreset', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); + } +} diff --git a/mod/workshop/classes/event/assessment_reevaluated.php b/mod/workshop/classes/event/assessment_reevaluated.php new file mode 100644 index 00000000000..a3683ca171b --- /dev/null +++ b/mod/workshop/classes/event/assessment_reevaluated.php @@ -0,0 +1,93 @@ +. + +/** + * mod_workshop assessment_reevaluated event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop assessment_reevaluated event class. + * + * @property-read array $other { + * Extra information about the event. + * + * @type float currentgrade current saved grade. + * @type float finalgrade final grade. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class assessment_reevaluated extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'workshop_aggregations'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'The assessment has been re-evaluated ' . $this->objectid . '.'; + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'update aggregate grade', 'view.php?id=' . $this->contextinstanceid, + $this->objectid, $this->contextinstanceid); + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventassessmentreevaluated', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); + } +} diff --git a/mod/workshop/classes/event/assessments_reset.php b/mod/workshop/classes/event/assessments_reset.php new file mode 100644 index 00000000000..e0cdbbcaecf --- /dev/null +++ b/mod/workshop/classes/event/assessments_reset.php @@ -0,0 +1,86 @@ +. + +/** + * mod_workshop submission assessments reset event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop submission assessments reset event class. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class submission_assessments_reset extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_TEACHING; + $this->data['objecttable'] = 'workshop_assessments'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'The submission assessments of the workshop ' . $this->objectid . ' have been cleared.'; + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'update clear assessments', 'view.php?id=' . $this->contextinstanceid, + $this->objectid, $this->contextinstanceid); + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventsubmissionassessmentsreset', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); + } +} diff --git a/mod/workshop/classes/event/instances_list_viewed.php b/mod/workshop/classes/event/instances_list_viewed.php new file mode 100644 index 00000000000..d4a25579b41 --- /dev/null +++ b/mod/workshop/classes/event/instances_list_viewed.php @@ -0,0 +1,75 @@ +. + +/** + * mod_workshop instances list viewed event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop instances list viewed event class. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class instances_list_viewed extends \core\event\course_module_instance_list_viewed { + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User ' . $this->userid . ' viewed the list of workshop activities in the course ' . $this->courseid . '.'; + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'view all', 'index.php?id=' . $this->courseid, ''); + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventinstanceslistviewed', 'mod_workshop'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/index.php', array('id' => $this->courseid)); + } + +} diff --git a/mod/workshop/classes/event/phase_switched.php b/mod/workshop/classes/event/phase_switched.php new file mode 100644 index 00000000000..0f403a1c84a --- /dev/null +++ b/mod/workshop/classes/event/phase_switched.php @@ -0,0 +1,92 @@ +. + +/** + * mod_workshop phase switched event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop phase switched event class. + * + * @property-read array $other { + * Extra information about the event. + * + * @type int workshopphase Workshop phase. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class phase_switched extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_TEACHING; + $this->data['objecttable'] = 'workshop'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'The phase of the workshop ' . $this->objectid . ' has been switched to ' . $this->other['workshopphase']. '.'; + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'update switch phase', 'view.php?id=' . $this->contextinstanceid, + $this->other['workshopphase'], $this->contextinstanceid); + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventphaseswitched', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); + } +} diff --git a/mod/workshop/classes/event/submission_assessed.php b/mod/workshop/classes/event/submission_assessed.php new file mode 100644 index 00000000000..5964510f201 --- /dev/null +++ b/mod/workshop/classes/event/submission_assessed.php @@ -0,0 +1,93 @@ +. + +/** + * mod_workshop submission_assessed event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop submission_assessed event class. + * + * @property-read array $other { + * Extra information about the event. + * + * @type int workshopid Workshop ID. + * @type int submissionid Submission ID. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class submission_assessed extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'workshop_assessments'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'A submission has been assessed in the workshop ' . $this->other['workshopid'] . '.'; + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'add assessment ', 'assessment.php?asid=' . $this->objectid, + $this->other['submissionid'], $this->contextinstanceid); + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventsubmissionassessed', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/assessment.php', array('asid' => $this->objectid)); + } +} diff --git a/mod/workshop/classes/event/submission_created.php b/mod/workshop/classes/event/submission_created.php new file mode 100644 index 00000000000..ac0a9e6e44f --- /dev/null +++ b/mod/workshop/classes/event/submission_created.php @@ -0,0 +1,91 @@ +. + +/** + * This file contains an event for when a workshop submission is created. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a workshop submission is created. + * + * @property-read array $other { + * Extra information about the event. + * + * @type string submissiontitle Submission title. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class submission_created extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'workshop_submissions'; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'A user with an id of ' . $this->userid . ' created a workshop submission with an id of ' . $this->objectid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventsubmissioncreated', 'workshop'); + } + + /** + * Returns relevant URL. + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/submission.php', + array('cmid' => $this->contextinstanceid, 'id' => $this->objectid)); + } + + /** + * replace add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'add submission', + 'submission.php?cmid=' . $this->contextinstanceid . '&id=' . $this->objectid, + $this->objectid, $this->contextinstanceid); + } +} diff --git a/mod/workshop/classes/event/submission_reassessed.php b/mod/workshop/classes/event/submission_reassessed.php new file mode 100644 index 00000000000..bdaf0a2ea53 --- /dev/null +++ b/mod/workshop/classes/event/submission_reassessed.php @@ -0,0 +1,94 @@ +. + +/** + * mod_workshop submission_reassessed event. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_workshop submission_reassessed event class. + * + * @property-read array $other { + * Extra information about the event. + * + * @type int workshopid Workshop ID. + * @type int submissionid Submission ID. + * @type float grade Assessment grade. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class submission_reassessed extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'workshop_assessment'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'A submission was re-assessed in the workshop ' . $this->other['workshopid'] . '.'; + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'update assessment', 'assessment.php?asid=' . $this->objectid, + $this->other['submissionid'], $this->contextinstanceid); + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventsubmissionreassessed', 'mod_workshop'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/assessment.php?', array('asid' => $this->objectid)); + } +} diff --git a/mod/workshop/classes/event/submission_updated.php b/mod/workshop/classes/event/submission_updated.php new file mode 100644 index 00000000000..93946253f3f --- /dev/null +++ b/mod/workshop/classes/event/submission_updated.php @@ -0,0 +1,91 @@ +. + +/** + * This file contains an event for when a workshop submission is updated. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a workshop submission is updated. + * + * @property-read array $other { + * Extra information about the event. + * + * @type string submissiontitle Submission title. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class submission_updated extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'workshop_submissions'; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'A user with an id of ' . $this->userid . ' updated a workshop submission with an id of ' . $this->objectid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventsubmissionupdated', 'workshop'); + } + + /** + * Returns relevant URL. + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/submission.php', + array('cmid' => $this->contextinstanceid, 'id' => $this->objectid)); + } + + /** + * replace add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'update submission', + 'submission.php?cmid=' . $this->contextinstanceid . '&id=' . $this->objectid, + $this->objectid, $this->contextinstanceid); + } +} diff --git a/mod/workshop/classes/event/submission_viewed.php b/mod/workshop/classes/event/submission_viewed.php new file mode 100644 index 00000000000..3dcb92057f6 --- /dev/null +++ b/mod/workshop/classes/event/submission_viewed.php @@ -0,0 +1,91 @@ +. + +/** + * This file contains an event for when a workshop submission is viewed. + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_workshop\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a workshop submission is viewed. + * + * @property-read array $other { + * Extra information about the event. + * + * @type int workshopid workshop ID. + * } + * + * @package mod_workshop + * @category event + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class submission_viewed extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'workshop_submissions'; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'A user with an id of ' . $this->userid . ' viewed a workshop submission with an id of ' . $this->objectid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventsubmissionviewed', 'workshop'); + } + + /** + * Returns relevant URL. + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/workshop/submission.php', + array('cmid' => $this->contextinstanceid, 'id' => $this->objectid)); + } + + /** + * replace add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'workshop', 'view submission', + 'submission.php?cmid=' . $this->contextinstanceid . '&id=' . $this->objectid, + $this->objectid, $this->contextinstanceid); + } +} diff --git a/mod/workshop/exassessment.php b/mod/workshop/exassessment.php index 4515de22041..3c6175654f0 100644 --- a/mod/workshop/exassessment.php +++ b/mod/workshop/exassessment.php @@ -87,19 +87,6 @@ $mform->set_data($currentdata); if ($mform->is_cancelled()) { redirect($workshop->view_url()); } elseif ($assessmenteditable and ($data = $mform->get_data())) { - if ($canmanage) { - if (is_null($assessment->grade)) { - $workshop->log('add reference assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid); - } else { - $workshop->log('update reference assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid); - } - } else { - if (is_null($assessment->grade)) { - $workshop->log('add example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid); - } else { - $workshop->log('update example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid); - } - } // Let the grading strategy subplugin save its data. $rawgrade = $strategy->save_assessment($assessment, $data); diff --git a/mod/workshop/exsubmission.php b/mod/workshop/exsubmission.php index 3a29bdf3b03..40ae3b81819 100644 --- a/mod/workshop/exsubmission.php +++ b/mod/workshop/exsubmission.php @@ -57,8 +57,6 @@ $output = $PAGE->get_renderer('mod_workshop'); if ($id) { // example is specified $example = $workshop->get_example_by_id($id); - $workshop->log('view example', $workshop->exsubmission_url($example->id), $example->id); - } else { // no example specified - create new one require_capability('mod/workshop:manageexamples', $workshop->context); $example = new stdclass(); @@ -162,9 +160,7 @@ if ($edit and $canmanage) { $formdata->contenttrust = 0; // updated later if (is_null($example->id)) { $example->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata); - $workshop->log('add example', $workshop->exsubmission_url($example->id), $example->id); } else { - $workshop->log('update example', $workshop->exsubmission_url($example->id), $example->id); if (empty($formdata->id) or empty($example->id) or ($formdata->id != $example->id)) { throw new moodle_exception('err_examplesubmissionid', 'workshop'); } diff --git a/mod/workshop/index.php b/mod/workshop/index.php index 9fac4019a64..acf8590d70c 100644 --- a/mod/workshop/index.php +++ b/mod/workshop/index.php @@ -33,8 +33,6 @@ $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); require_course_login($course); -add_to_log($course->id, 'workshop', 'view all', "index.php?id=$course->id", ''); - $PAGE->set_pagelayout('incourse'); $PAGE->set_url('/mod/workshop/index.php', array('id' => $course->id)); $PAGE->set_title($course->fullname); @@ -45,6 +43,10 @@ $PAGE->navbar->add(get_string('modulenameplural', 'workshop')); echo $OUTPUT->header(); +$params = array('context' => context_course::instance($course->id)); +$event = \mod_workshop\event\instances_list_viewed::create($params); +$event->trigger(); + /// Get all the appropriate data if (! $workshops = get_all_instances_in_course('workshop', $course)) { diff --git a/mod/workshop/lang/en/workshop.php b/mod/workshop/lang/en/workshop.php index 9c99b1e9296..3a0b55e1fc3 100644 --- a/mod/workshop/lang/en/workshop.php +++ b/mod/workshop/lang/en/workshop.php @@ -106,6 +106,18 @@ $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['eventassessmentevaluationsreset'] = 'Assessment evaluations reset'; +$string['eventassessableuploaded'] = 'Assessable uploaded'; +$string['eventassessmentevaluated'] = 'Assessment evaluated'; +$string['eventassessmentreevaluated'] = 'Assessment re-evaluated'; +$string['eventinstanceslistviewed'] = 'Workshop instance list viewed'; +$string['eventsubmissionassessed'] = 'Submission assessed'; +$string['eventsubmissionassessmentsreset'] = 'Submission assessments cleared'; +$string['eventsubmissioncreated'] = 'Submission created'; +$string['eventsubmissionreassessed'] = 'Submission re-assessed'; +$string['eventsubmissionupdated'] = 'Submission updated'; +$string['eventsubmissionviewed'] = 'Submission viewed'; +$string['eventphaseswitched'] = 'Phase switched'; $string['event_assessable_uploaded'] = 'A submission has been uploaded.'; $string['example'] = 'Example submission'; $string['exampleadd'] = 'Add example submission'; @@ -235,8 +247,8 @@ $string['strategy_help'] = 'The grading strategy determines the assessment form * Rubric - A level assessment is given regarding specified criteria'; $string['strategyhaschanged'] = 'The workshop grading strategy has changed since the form was opened for editing.'; $string['submission'] = 'Submission'; -$string['submissionby'] = 'Submission by {$a}'; $string['submissionattachment'] = 'Attachment'; +$string['submissionby'] = 'Submission by {$a}'; $string['submissioncontent'] = 'Submission content'; $string['submissionend'] = 'Submissions deadline'; $string['submissionendbeforestart'] = 'Submissions deadline can not be specified before the open for submissions date'; diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 21bab06c09e..f8433a89626 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -938,7 +938,18 @@ function workshop_cron() { $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $workshop = new workshop($workshop, $cm, $course); $workshop->switch_phase(workshop::PHASE_ASSESSMENT); - $workshop->log('update switch phase', $workshop->view_url(), $workshop->phase); + + $params = array( + 'objectid' => $workshop->id, + 'context' => $workshop->context, + 'courseid' => $workshop->course->id, + 'other' => array( + 'workshopphase' => $workshop->phase + ) + ); + $event = \mod_workshop\event\phase_switched::create($params); + $event->trigger(); + // disable the automatic switching now so that it is not executed again by accident // if the teacher changes the phase back to the submission one $DB->set_field('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id)); diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 1ed99e03a1a..018e696cba0 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -2451,8 +2451,22 @@ class workshop { if ($count > 0) { $finalgrade = grade_floatval($sumgrades / $count); } + + // Event information. + $params = array( + 'context' => $this->context, + 'courseid' => $this->course->id, + 'relateduserid' => $reviewerid + ); + // check if the new final grade differs from the one stored in the database if (grade_floats_different($finalgrade, $current)) { + $params['other'] = array( + 'currentgrade' => $current, + 'finalgrade' => $finalgrade + ); + + // we need to save new calculation into the database if (is_null($agid)) { // no aggregation record yet @@ -2461,13 +2475,19 @@ class workshop { $record->userid = $reviewerid; $record->gradinggrade = $finalgrade; $record->timegraded = $timegraded; - $DB->insert_record('workshop_aggregations', $record); + $record->id = $DB->insert_record('workshop_aggregations', $record); + $params['objectid'] = $record->id; + $event = \mod_workshop\event\assessment_evaluated::create($params); + $event->trigger(); } else { $record = new stdclass(); $record->id = $agid; $record->gradinggrade = $finalgrade; $record->timegraded = $timegraded; $DB->update_record('workshop_aggregations', $record); + $params['objectid'] = $agid; + $event = \mod_workshop\event\assessment_reevaluated::create($params); + $event->trigger(); } } } diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php index 93b5ee386a8..47223a869cc 100644 --- a/mod/workshop/submission.php +++ b/mod/workshop/submission.php @@ -52,7 +52,19 @@ if ($edit) { if ($id) { // submission is specified $submission = $workshop->get_submission_by_id($id); - $workshop->log('view submission', $workshop->submission_url($submission->id), $submission->id); + + $params = array( + 'objectid' => $submission->id, + 'context' => $workshop->context, + 'courseid' => $workshop->course->id, + 'relateduserid' => $submission->authorid, + 'other' => array( + 'workshopid' => $workshop->id + ) + ); + + $event = \mod_workshop\event\submission_viewed::create($params); + $event->trigger(); } else { // no submission specified if (!$submission = $workshop->get_submission_by_author($USER->id)) { @@ -188,16 +200,27 @@ if ($edit) { if ($workshop->phase == workshop::PHASE_ASSESSMENT) { $formdata->late = $formdata->late | 0x2; } + + // Event information. + $params = array( + 'context' => $workshop->context, + 'courseid' => $workshop->course->id, + 'other' => array( + 'submissiontitle' => $formdata->title + ) + ); $logdata = null; if (is_null($submission->id)) { $submission->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata); - $logdata = $workshop->log('add submission', $workshop->submission_url($submission->id), $submission->id, true); + $params['objectid'] = $submission->id; + $event = \mod_workshop\event\submission_created::create($params); + $event->trigger(); } else { - $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'); } } + $params['objectid'] = $submission->id; // save and relink embedded images and save attachments $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context, 'mod_workshop', 'submission_content', $submission->id); @@ -209,19 +232,17 @@ if ($edit) { } // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten) $DB->update_record('workshop_submissions', $formdata); + $event = \mod_workshop\event\submission_updated::create($params); + $event->add_record_snapshot('workshop_submissions', $formdata); + $event->trigger(); // send submitted content for plagiarism detection $fs = get_file_storage(); $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id); - $params = array( - 'context' => $workshop->context, - 'objectid' => $submission->id, - 'other' => array( - 'content' => $formdata->content, - 'pathnamehashes' => array_keys($files) - ) - ); + $params['other']['content'] = $formdata->content; + $params['other']['pathnamehashes'] = array_keys($files); + $event = \mod_workshop\event\assessable_uploaded::create($params); $event->set_legacy_logdata($logdata); $event->trigger(); diff --git a/mod/workshop/toolbox.php b/mod/workshop/toolbox.php index a9f33d13726..2940aeecae9 100644 --- a/mod/workshop/toolbox.php +++ b/mod/workshop/toolbox.php @@ -38,18 +38,26 @@ require_login($course, false, $cm); $workshop = new workshop($workshop, $cm, $course); require_sesskey(); +$params = array( + 'objectid' => $workshop->id, + 'context' => $workshop->context, + 'courseid' => $course->id +); + switch ($tool) { case 'clearaggregatedgrades': require_capability('mod/workshop:overridegrades', $workshop->context); - $workshop->log('update clear aggregated grades'); $workshop->clear_submission_grades(); $workshop->clear_grading_grades(); + $event = \mod_workshop\event\assessment_evaluations_reset::create($params); + $event->trigger(); break; case 'clearassessments': require_capability('mod/workshop:overridegrades', $workshop->context); - $workshop->log('update clear assessments'); $workshop->clear_assessments(); + $event = \mod_workshop\event\submission_assessments_reset::create($params); + $event->trigger(); break; } diff --git a/mod/workshop/view.php b/mod/workshop/view.php index ad84c6f1683..cdbf83773f0 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -76,7 +76,9 @@ $event->trigger(); if ($workshop->phase == workshop::PHASE_SUBMISSION and $workshop->phaseswitchassessment and $workshop->submissionend > 0 and $workshop->submissionend < time()) { $workshop->switch_phase(workshop::PHASE_ASSESSMENT); - $workshop->log('update switch phase', $workshop->view_url(), $workshop->phase); + $eventdata['other']['workshopphase'] = $workshop->phase; + $event = \mod_workshop\event\phase_switched::create($eventdata); + $event->trigger(); // Disable the automatic switching now so that it is not executed again by accident // if the teacher changes the phase back to the submission one. $DB->set_field('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id));