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..cd26c950a45 --- /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_TEACHING; + $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..d92ccd122d7 --- /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_TEACHING; + $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/course_module_viewed.php b/mod/workshop/classes/event/course_module_viewed.php index c5b8d51a849..562160d6a80 100644 --- a/mod/workshop/classes/event/course_module_viewed.php +++ b/mod/workshop/classes/event/course_module_viewed.php @@ -23,8 +23,12 @@ */ namespace mod_workshop\event; + defined('MOODLE_INTERNAL') || die(); +global $CFG; +require_once("$CFG->dirroot/mod/workshop/locallib.php"); + /** * Event for when a workshop activity is viewed. * 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/tests/events_test.php b/mod/workshop/tests/events_test.php new file mode 100644 index 00000000000..72b50c3e079 --- /dev/null +++ b/mod/workshop/tests/events_test.php @@ -0,0 +1,312 @@ +. + +/** + * Unit tests for workshop events. + * + * @package mod_workshop + * @category phpunit + * @copyright 2013 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/mod/workshop/lib.php'); // Include the code to test. +require_once($CFG->dirroot . '/mod/workshop/locallib.php'); // Include the code to test. +require_once($CFG->dirroot . '/lib/cronlib.php'); // Include the code to test. +require_once(__DIR__ . '/fixtures/testable.php'); + + +/** + * Test cases for the internal workshop api + */ +class mod_workshop_events_testcase extends advanced_testcase { + + /** @var stdClass $workshop Basic workshop data stored in an object. */ + protected $workshop; + /** @var stdClass $course Generated Random Course. */ + protected $course; + /** @var stdClass mod info */ + protected $cm; + /** @var context $context Course module context. */ + protected $context; + + /** + * Set up the testing environment. + */ + protected function setUp() { + parent::setUp(); + $this->setAdminUser(); + + // Create a workshop activity. + $this->course = $this->getDataGenerator()->create_course(); + $this->workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $this->course)); + $this->cm = get_coursemodule_from_instance('workshop', $this->workshop->id); + $this->context = context_module::instance($this->cm->id); + } + + protected function tearDown() { + $this->workshop = null; + $this->course = null; + $this->cm = null; + $this->context = null; + parent::tearDown(); + } + + /** + * This event is triggered in view.php and workshop/lib.php through the function workshop_cron(). + */ + public function test_phase_switched_event() { + $this->resetAfterTest(); + $this->setAdminUser(); + + // Add additional workshop information. + $this->workshop->phase = 20; + $this->workshop->phaseswitchassessment = 1; + $this->workshop->submissionend = time() - 1; + + $event = \mod_workshop\event\phase_switched::create(array( + 'objectid' => $this->workshop->id, + 'context' => $this->context, + 'courseid' => $this->course->id, + 'other' => array('workshopphase' => $this->workshop->phase) + )); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $event->trigger(); + $events = $sink->get_events(); + $event = reset($events); + + // Check that the legacy log data is valid. + $expected = array($this->course->id, 'workshop', 'update switch phase', 'view.php?id=' . $this->workshop->id, + $this->workshop->phase, $this->cm->id); + $this->assertEventLegacyLogData($expected, $event); + + $sink->close(); + } + + public function test_assessment_evaluated() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $cm = get_coursemodule_from_instance('workshop', $this->workshop->id, $this->course->id, false, MUST_EXIST); + + $workshop = new testable_workshop($this->workshop, $cm, $this->course); + + $assessments = array(); + $assessments[] = (object)array('reviewerid' => 2, 'gradinggrade' => null, + 'gradinggradeover' => null, 'aggregationid' => null, 'aggregatedgrade' => 12); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $workshop->aggregate_grading_grades_process($assessments); + $events = $sink->get_events(); + $event = reset($events); + + $this->assertInstanceOf('\mod_workshop\event\assessment_evaluated', $event); + $this->assertEquals('workshop_aggregations', $event->objecttable); + $this->assertEquals(context_module::instance($cm->id), $event->get_context()); + + $sink->close(); + } + + public function test_assessment_reevaluated() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $cm = get_coursemodule_from_instance('workshop', $this->workshop->id, $this->course->id, false, MUST_EXIST); + + $workshop = new testable_workshop($this->workshop, $cm, $this->course); + + $assessments = array(); + $assessments[] = (object)array('reviewerid' => 2, 'gradinggrade' => null, 'gradinggradeover' => null, + 'aggregationid' => 2, 'aggregatedgrade' => 12); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $workshop->aggregate_grading_grades_process($assessments); + $events = $sink->get_events(); + $event = reset($events); + + $this->assertInstanceOf('\mod_workshop\event\assessment_reevaluated', $event); + $this->assertEquals('workshop_aggregations', $event->objecttable); + $this->assertEquals(context_module::instance($cm->id), $event->get_context()); + $expected = array($this->course->id, 'workshop', 'update aggregate grade', + 'view.php?id=' . $event->get_context()->instanceid, $event->objectid, $event->get_context()->instanceid); + $this->assertEventLegacyLogData($expected, $event); + + $sink->close(); + } + + /** + * There is no api involved so the best we can do is test legacy data by triggering event manually. + */ + public function test_aggregate_grades_reset_event() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $event = \mod_workshop\event\assessment_evaluations_reset::create(array( + 'objectid' => $this->workshop->id, + 'context' => $this->context, + 'courseid' => $this->course->id, + )); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $event->trigger(); + $events = $sink->get_events(); + $event = reset($events); + + // Check that the legacy log data is valid. + $expected = array($this->course->id, 'workshop', 'update clear aggregated grade', 'view.php?id=' . $this->workshop->id, + $this->workshop->id, $this->cm->id); + $this->assertEventLegacyLogData($expected, $event); + + $sink->close(); + } + + /** + * There is no api involved so the best we can do is test legacy data by triggering event manually. + */ + public function test_instances_list_viewed_event() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $context = context_course::instance($this->course->id); + + $event = \mod_workshop\event\instances_list_viewed::create(array('context' => $context)); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $event->trigger(); + $events = $sink->get_events(); + $event = reset($events); + + // Check that the legacy log data is valid. + $expected = array($this->course->id, 'workshop', 'view all', 'index.php?id=' . $this->course->id, ''); + $this->assertEventLegacyLogData($expected, $event); + + $sink->close(); + } + + /** + * There is no api involved so the best we can do is test legacy data by triggering event manually. + */ + public function test_submission_created_event() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $user = $this->getDataGenerator()->create_user(); + $submissionid = 48; + + $event = \mod_workshop\event\submission_created::create(array( + 'objectid' => $submissionid, + 'context' => $this->context, + 'courseid' => $this->course->id, + 'relateduserid' => $user->id, + 'other' => array( + 'workshopid' => $this->workshop->id + ) + ) + ); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $event->trigger(); + $events = $sink->get_events(); + $event = reset($events); + + // Check that the legacy log data is valid. + $expected = array($this->course->id, 'workshop', 'add submission', + 'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id); + $this->assertEventLegacyLogData($expected, $event); + + $sink->close(); + } + + /** + * There is no api involved so the best we can do is test legacy data by triggering event manually. + */ + public function test_submission_updated_event() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $user = $this->getDataGenerator()->create_user(); + $submissionid = 48; + + $event = \mod_workshop\event\submission_updated::create(array( + 'objectid' => $submissionid, + 'context' => $this->context, + 'courseid' => $this->course->id, + 'relateduserid' => $user->id, + 'other' => array( + 'workshopid' => $this->workshop->id + ) + ) + ); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $event->trigger(); + $events = $sink->get_events(); + $event = reset($events); + + // Check that the legacy log data is valid. + $expected = array($this->course->id, 'workshop', 'update submission', + 'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id); + $this->assertEventLegacyLogData($expected, $event); + + $sink->close(); + } + + /** + * There is no api involved so the best we can do is test legacy data by triggering event manually. + */ + public function test_submission_viewed_event() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $user = $this->getDataGenerator()->create_user(); + $submissionid = 48; + + $event = \mod_workshop\event\submission_viewed::create(array( + 'objectid' => $submissionid, + 'context' => $this->context, + 'courseid' => $this->course->id, + 'relateduserid' => $user->id, + 'other' => array( + 'workshopid' => $this->workshop->id + ) + ) + ); + + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $event->trigger(); + $events = $sink->get_events(); + $event = reset($events); + + // Check that the legacy log data is valid. + $expected = array($this->course->id, 'workshop', 'view submission', + 'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id); + $this->assertEventLegacyLogData($expected, $event); + + $sink->close(); + } +} diff --git a/mod/workshop/tests/fixtures/testable.php b/mod/workshop/tests/fixtures/testable.php new file mode 100644 index 00000000000..e7e1cd3e20b --- /dev/null +++ b/mod/workshop/tests/fixtures/testable.php @@ -0,0 +1,41 @@ +. + +/** + * mod_workshop fixtures + * + * @package mod_workshop + * @category phpunit + * @copyright 2014 Petr Skoda + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Test subclass that makes all the protected methods we want to test public. + */ +class testable_workshop extends workshop { + + public function aggregate_submission_grades_process(array $assessments) { + parent::aggregate_submission_grades_process($assessments); + } + + public function aggregate_grading_grades_process(array $assessments, $timegraded = null) { + parent::aggregate_grading_grades_process($assessments, $timegraded); + } + +} diff --git a/mod/workshop/tests/locallib_test.php b/mod/workshop/tests/locallib_test.php index a6321ed98bb..08f5a028d11 100644 --- a/mod/workshop/tests/locallib_test.php +++ b/mod/workshop/tests/locallib_test.php @@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/mod/workshop/locallib.php'); // Include the code to test +require_once(__DIR__ . '/fixtures/testable.php'); /** @@ -40,8 +41,11 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { /** setup testing environment */ protected function setUp() { parent::setUp(); - - $this->workshop = new testable_workshop(); + $this->setAdminUser(); + $course = $this->getDataGenerator()->create_course(); + $workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course)); + $cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST); + $this->workshop = new testable_workshop($workshop, $cm, $course); } protected function tearDown() { @@ -50,6 +54,8 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_aggregate_submission_grades_process_notgraded() { + $this->resetAfterTest(true); + // fixture set-up $batch = array(); // batch of a submission's assessments $batch[] = (object)array('submissionid' => 12, 'submissiongrade' => null, 'weight' => 1, 'grade' => null); @@ -126,6 +132,8 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_aggregate_submission_grades_process_mean_nochange() { + $this->resetAfterTest(true); + // fixture set-up $batch = array(); // batch of a submission's assessments $batch[] = (object)array('submissionid' => 45, 'submissiongrade' => 19.67750, 'weight' => 1, 'grade' => 56.12000); @@ -167,6 +175,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_aggregate_grading_grades_process_nograding() { + $this->resetAfterTest(true); // fixture set-up $batch = array(); $batch[] = (object)array('reviewerid'=>2, 'gradinggrade'=>null, 'gradinggradeover'=>null, 'aggregationid'=>null, 'aggregatedgrade'=>null); @@ -205,6 +214,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_aggregate_grading_grades_process_single_grade_uptodate() { + $this->resetAfterTest(true); // fixture set-up $batch = array(); $batch[] = (object)array('reviewerid'=>3, 'gradinggrade'=>90.00000, 'gradinggradeover'=>null, 'aggregationid'=>1, 'aggregatedgrade'=>90.00000); @@ -297,6 +307,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_percent_to_value() { + $this->resetAfterTest(true); // fixture setup $total = 185; $percent = 56.6543; @@ -307,6 +318,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_percent_to_value_negative() { + $this->resetAfterTest(true); // fixture setup $total = 185; $percent = -7.098; @@ -317,6 +329,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_percent_to_value_over_hundred() { + $this->resetAfterTest(true); // fixture setup $total = 185; $percent = 121.08; @@ -327,6 +340,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_lcm() { + $this->resetAfterTest(true); // fixture setup + exercise SUT + verify in one step $this->assertEquals(workshop::lcm(1,4), 4); $this->assertEquals(workshop::lcm(2,4), 4); @@ -336,6 +350,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_lcm_array() { + $this->resetAfterTest(true); // fixture setup $numbers = array(5,3,15); // excersise SUT @@ -345,6 +360,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { } public function test_prepare_example_assessment() { + $this->resetAfterTest(true); // fixture setup $fakerawrecord = (object)array( 'id' => 42, @@ -374,6 +390,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { public function test_prepare_example_reference_assessment() { global $USER; + $this->resetAfterTest(true); // fixture setup $fakerawrecord = (object)array( 'id' => 38, @@ -400,26 +417,3 @@ class mod_workshop_internal_api_testcase extends advanced_testcase { $a = $this->workshop->prepare_example_reference_assessment($fakerawrecord); } } - - -/** - * Test subclass that makes all the protected methods we want to test public. - */ -class testable_workshop extends workshop { - - public function __construct() { - $this->id = 16; - $this->cm = new stdclass(); - $this->course = new stdclass(); - $this->context = new stdclass(); - } - - public function aggregate_submission_grades_process(array $assessments) { - parent::aggregate_submission_grades_process($assessments); - } - - public function aggregate_grading_grades_process(array $assessments, $timegraded = null) { - parent::aggregate_grading_grades_process($assessments, $timegraded); - } - -} 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));