Merge branch 'w16_MDL-41101_m27_assign' of git://github.com/skodak/moodle

This commit is contained in:
Marina Glancy
2014-04-17 11:20:51 +08:00
38 changed files with 3212 additions and 1090 deletions
@@ -34,14 +34,33 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class all_submissions_downloaded extends \core\event\base {
class all_submissions_downloaded extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @return all_submissions_downloaded
*/
protected $legacylogdata;
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id
);
self::$preventcreatecall = false;
/** @var submission_graded $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Returns description of what happened.
@@ -52,41 +71,13 @@ class all_submissions_downloaded extends \core\event\base {
return "User {$this->userid} has downloaded all the submissions.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_all_submissions_downloaded', 'mod_assign');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Sets the legacy event log data.
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
return get_string('eventallsubmissionsdownloaded', 'mod_assign');
}
/**
@@ -100,4 +91,27 @@ class all_submissions_downloaded extends \core\event\base {
$this->data['objecttable'] = 'assign';
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$this->set_legacy_logdata('download all submissions', get_string('downloadall', 'assign'));
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call all_submissions_downloaded::create() directly, use all_submissions_downloaded::create_from_assign() instead.');
}
parent::validate_data();
}
}
@@ -40,14 +40,31 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assessable_submitted extends \core\event\assessable_submitted {
class assessable_submitted extends base {
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @param bool $editable
* @return assessable_submitted
*/
protected $legacylogdata;
public static function create_from_submission(\assign $assign, \stdClass $submission, $editable) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $submission->id,
'other' => array(
'submission_editable' => $editable,
),
);
/** @var assessable_submitted $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
@@ -83,41 +100,13 @@ class assessable_submitted extends \core\event\assessable_submitted {
return 'assessable_submitted';
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_assessable_submitted', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Sets the legacy event log data.
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
return get_string('eventassessablesubmitted', 'mod_assign');
}
/**
@@ -126,8 +115,20 @@ class assessable_submitted extends \core\event\assessable_submitted {
* @return void
*/
protected function init() {
parent::init();
$this->data['objecttable'] = 'assign_submission';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$submission = $this->get_record_snapshot('assign_submission', $this->objectid);
$this->set_legacy_logdata('submit for grading', $this->assign->format_submission_for_log($submission));
return parent::get_legacy_logdata();
}
/**
@@ -138,6 +139,7 @@ class assessable_submitted extends \core\event\assessable_submitted {
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['submission_editable'])) {
throw new \coding_exception('Other must contain the key submission_editable.');
}
+131
View File
@@ -0,0 +1,131 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign abstract base class.
*
* Most events can extend this class.
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
abstract class base extends \core\event\base {
/** @var \assign */
protected $assign;
/**
* Legacy log data.
*
* @var array
*/
protected $legacylogdata;
/**
* Set assign instance for this event.
* @param \assign $assign
* @throws \coding_exception
*/
public function set_assign(\assign $assign) {
if ($this->is_triggered()) {
throw new \coding_exception('set_assign() must be done before triggerring of event');
}
if ($assign->get_context()->id != $this->get_context()->id) {
throw new \coding_exception('Invalid assign isntance supplied!');
}
$this->assign = $assign;
}
/**
* Get assign instance.
*
* NOTE: to be used from observers only.
*
* @return \assign
*/
public function get_assign() {
if ($this->is_restored()) {
throw new \coding_exception('get_assign() is intended for event observers only');
}
if (!isset($this->assign)) {
debugging('assign property should be initialised in each event', DEBUG_DEVELOPER);
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$cm = get_coursemodule_from_id('assign', $this->contextinstanceid, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$this->assign = new \assign($this->get_context(), $cm, $course);
}
return $this->assign;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Sets the legacy event log data.
*
* @param string $action The current action
* @param string $info A detailed description of the change. But no more than 255 characters.
* @param string $url The url to the assign module instance.
*/
public function set_legacy_logdata($action = '', $info = '', $url = '') {
$fullurl = 'view.php?id=' . $this->contextinstanceid;
if ($url != '') {
$fullurl .= '&' . $url;
}
$this->legacylogdata = array($this->courseid, 'assign', $action, $fullurl, $info, $this->contextinstanceid);
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
if (isset($this->legacylogdata)) {
return $this->legacylogdata;
}
return null;
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if ($this->contextlevel != CONTEXT_MODULE) {
throw new \coding_exception('Context passed must be module context.');
}
}
}
@@ -0,0 +1,126 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign batch set marker allocation viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign batch set marker allocation viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class batch_set_marker_allocation_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return batch_set_marker_allocation_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var batch_set_marker_allocation_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventbatchsetmarkerallocationviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the batch set marker allocation for the assignment with the id
{$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$logmessage = get_string('viewbatchmarkingallocation', 'assign');
$this->set_legacy_logdata('view batch set marker allocation', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call batch_set_marker_allocation_viewed::create() directly, use batch_set_marker_allocation_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -0,0 +1,125 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign assignment batch set workflow stated viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign assignment batch set workflow stated viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class batch_set_workflow_state_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return batch_set_workflow_state_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var batch_set_workflow_state_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventbatchsetworkflowstateviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the batch set workflow for the assignment with the id {$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$logmessage = get_string('viewbatchsetmarkingworkflowstate', 'assign');
$this->set_legacy_logdata('view batch set marking workflow state', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call batch_set_workflow_state_viewed::create() directly, use batch_set_workflow_state_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -0,0 +1,52 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign instance list viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign instance list viewed event.
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
/**
* Create the event from course record.
*
* @param \stdClass $course
* @return course_module_instance_list_viewed
*/
public static function create_from_course(\stdClass $course) {
$params = array(
'context' => \context_course::instance($course->id)
);
$event = \mod_assign\event\course_module_instance_list_viewed::create($params);
$event->add_record_snapshot('course', $course);
return $event;
}
}
+36 -28
View File
@@ -34,14 +34,35 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class extension_granted extends \core\event\base {
class extension_granted extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param int $userid
* @return extension_granted
*/
protected $legacylogdata;
public static function create_from_assign(\assign $assign, $userid) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $userid,
);
self::$preventcreatecall = false;
/** @var extension_granted $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Returns description of what happened.
@@ -52,31 +73,13 @@ class extension_granted extends \core\event\base {
return "User {$this->userid} has granted an extension to {$this->relateduserid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_extension_granted', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventextensiongranted', 'mod_assign');
}
/**
@@ -91,13 +94,13 @@ class extension_granted extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$this->set_legacy_logdata('grant extension', $this->relateduserid);
return parent::get_legacy_logdata();
}
/**
@@ -107,7 +110,12 @@ class extension_granted extends \core\event\base {
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call extension_granted::create() directly, use extension_granted::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('relateduserid is a mandatory property.');
}
@@ -0,0 +1,110 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign feedback updated event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign feedback updated event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class feedback_updated extends base {
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $grade
* @return feedback_updated
*/
public static function create_from_grade(\assign $assign, \stdClass $grade) {
$data = array(
'objectid' => $grade->id,
'relateduserid' => $grade->userid,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
/** @var feedback_updated $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_grades', $grade);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventfeedbackupdated', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} updated the feedback for the user with the id {$this->relateduserid}
for the assignment with the id {$this->other['assignid']}.";
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -0,0 +1,122 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign feedback viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign feedback viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class feedback_viewed extends base {
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $grade
* @return feedback_viewed
*/
public static function create_from_grade(\assign $assign, \stdClass $grade) {
$data = array(
'objectid' => $grade->id,
'relateduserid' => $grade->userid,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
/** @var feedback_viewed $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_grades', $grade);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_grades';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventfeedbackviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the feedback for the user with the id {$this->relateduserid}
for the assignment with the id {$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$logmessage = get_string('viewfeedbackforuser', 'assign', $this->relateduserid);
$this->set_legacy_logdata('view feedback', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -0,0 +1,134 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign grading form viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign grading form viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_form_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $user
* @return grading_form_viewed
*/
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'relateduserid' => $user->id,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var grading_form_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgradingformviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the grading form for the user with the id {$this->relateduserid}
for the assignment with the id {$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$user = $this->get_record_snapshot('user', $this->relateduserid);
$msg = get_string('viewgradingformforstudent', 'assign',
array('id' => $user->id, 'fullname' => fullname($user)));
$this->set_legacy_logdata('view grading form', $msg);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call grading_form_viewed::create() directly, use grading_form_viewed::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -0,0 +1,125 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign grading table viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign grading table viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_table_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return grading_table_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var grading_table_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgradingtableviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the grading table for the assignment with the id {$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$logmessage = get_string('viewsubmissiongradingtable', 'assign');
$this->set_legacy_logdata('view submission grading table', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call grading_table_viewed::create() directly, use grading_table_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -34,14 +34,33 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class identities_revealed extends \core\event\base {
class identities_revealed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @return identities_revealed
*/
protected $legacylogdata;
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id
);
self::$preventcreatecall = false;
/** @var identities_revealed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Returns description of what happened.
@@ -52,31 +71,13 @@ class identities_revealed extends \core\event\base {
return "User {$this->userid} has revealed the identities in assignment {$this->objectid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_identities_revealed', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventidentitiesrevealed', 'mod_assign');
}
/**
@@ -91,13 +92,26 @@ class identities_revealed extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$this->set_legacy_logdata('reveal identities', get_string('revealidentities', 'assign'));
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call identities_revealed::create() directly, use identities_revealed::create_from_assign() instead.');
}
parent::validate_data();
}
}
+46 -29
View File
@@ -40,14 +40,41 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class marker_updated extends \core\event\base {
class marker_updated extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @param \stdClass $marker
* @return marker_updated
*/
protected $legacylogdata;
public static function create_from_marker(\assign $assign, \stdClass $user, \stdClass $marker) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
'other' => array(
'markerid' => $marker->id,
),
);
self::$preventcreatecall = false;
/** @var marker_updated $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
$event->add_record_snapshot('user', $marker);
return $event;
}
/**
* Returns description of what happened.
@@ -58,31 +85,13 @@ class marker_updated extends \core\event\base {
return "User {$this->userid} has set the marker of {$this->relateduserid} to {$this->other['markerid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_marker_updated', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventmarkerupdated', 'mod_assign');
}
/**
@@ -97,23 +106,31 @@ class marker_updated extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$user = $this->get_record_snapshot('user', $this->relateduserid);
$marker = $this->get_record_snapshot('user', $this->other['markerid']);
$a = array('id' => $user->id, 'fullname' => fullname($user), 'marker' => fullname($marker));
$logmessage = get_string('setmarkerallocationforlog', 'assign', $a);
$this->set_legacy_logdata('set marking allocation', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call marker_updated::create() directly, use marker_updated::create_from_marker() instead.');
}
parent::validate_data();
if (!isset($this->other['markerid'])) {
throw new \coding_exception('markerid must be set in $other.');
} else if (!isset($this->relateduserid)) {
@@ -0,0 +1,125 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign reveal identities confirmation page viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign reveal identities confirmation page viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class reveal_identities_confirmation_page_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return reveal_identities_confirmation_page_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var reveal_identities_confirmation_page_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventrevealidentitiesconfirmationpageviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the confirmation page for revealing identities for the
assignment with the id {$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$this->set_legacy_logdata('view', get_string('viewrevealidentitiesconfirm', 'assign'));
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call reveal_identities_confirmation_page_viewed::create() directly, use reveal_identities_confirmation_page_viewed::create_from_grade() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
+47 -29
View File
@@ -34,14 +34,35 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class statement_accepted extends \core\event\base {
class statement_accepted extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @return statement_accepted
*/
protected $legacylogdata;
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $submission->id
);
self::$preventcreatecall = false;
/** @var statement_accepted $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
@@ -52,31 +73,13 @@ class statement_accepted extends \core\event\base {
return "The user {$this->userid} has accepted the statement of the submission {$this->objectid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_statement_accepted', 'mod_assign');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventstatementaccepted', 'mod_assign');
}
/**
@@ -86,18 +89,33 @@ class statement_accepted extends \core\event\base {
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'assign_submission';
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
global $USER;
$logmessage = get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER)); // Nasty hack.
$this->set_legacy_logdata('submission statement accepted', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call statement_accepted::create() directly, use statement_accepted::create_from_submission() instead.');
}
parent::validate_data();
}
}
@@ -0,0 +1,126 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign submission form viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission form viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_confirmation_form_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return submission_confirmation_form_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var submission_confirmation_form_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionconfirmationformviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the submission confirmation form for the assignment with the id
{$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$logmessage = get_string('viewownsubmissionform', 'assign');
$this->set_legacy_logdata('view confirm submit assignment form', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_confirmation_form_viewed::create() directly, use submission_confirmation_form_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -41,7 +41,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2014 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class submission_created extends \core\event\base {
abstract class submission_created extends base {
/**
* Init method.
@@ -60,14 +60,6 @@ abstract class submission_created extends \core\event\base {
return get_string('eventsubmissioncreated', 'mod_assign');
}
/**
* Returns relevant URL.
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Custom validation.
*
@@ -34,14 +34,35 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_duplicated extends \core\event\base {
class submission_duplicated extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @return submission_duplicated
*/
protected $legacylogdata;
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'objectid' => $submission->id,
'context' => $assign->get_context(),
);
self::$preventcreatecall = false;
/** @var submission_duplicated $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
@@ -52,31 +73,13 @@ class submission_duplicated extends \core\event\base {
return "The user {$this->userid} duplicated his submission {$this->objectid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_submission_duplicated', 'mod_assign');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventsubmissionduplicated', 'mod_assign');
}
/**
@@ -91,13 +94,26 @@ class submission_duplicated extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$submission = $this->get_record_snapshot('assign_submission', $this->objectid);
$this->set_legacy_logdata('submissioncopied', $this->assign->format_submission_for_log($submission));
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_duplicated::create() directly, use submission_duplicated::create_from_submission() instead.');
}
parent::validate_data();
}
}
@@ -0,0 +1,142 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign submission form viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission form viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_form_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $user
* @return submission_form_viewed
*/
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'relateduserid' => $user->id,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var submission_form_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionformviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
if ($this->userid != $this->relateduserid) {
return "The user with the id {$this->userid} viewed the submission form for the user with the id {$this->relateduserid}
for the assignment with the id {$this->other['assignid']}.";
}
return "The user with the id {$this->userid} viewed their submission for the assignment with the id
{$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
if ($this->relateduserid == $this->userid) {
$title = get_string('editsubmission', 'assign');
} else {
$user = $this->get_record_snapshot('user', $this->relateduserid);
$title = get_string('editsubmissionother', 'assign', fullname($user));
}
$this->set_legacy_logdata('view submit assignment form', $title);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_form_viewed::create() directly, use submission_form_viewed::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
+38 -28
View File
@@ -34,14 +34,36 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_graded extends \core\event\base {
class submission_graded extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $grade
* @return submission_graded
*/
protected $legacylogdata;
public static function create_from_grade(\assign $assign, \stdClass $grade) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $grade->id,
'relateduserid' => $grade->userid
);
self::$preventcreatecall = false;
/** @var submission_graded $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_grades', $grade);
return $event;
}
/**
* Returns description of what happened.
@@ -52,31 +74,13 @@ class submission_graded extends \core\event\base {
return "User {$this->userid} has graded the submission {$this->objectid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_submission_graded', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventsubmissiongraded', 'mod_assign');
}
/**
@@ -91,13 +95,14 @@ class submission_graded extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$grade = $this->get_record_snapshot('assign_grades', $this->objectid);
$this->set_legacy_logdata('grade submission', $this->assign->format_grade_for_log($grade));
return parent::get_legacy_logdata();
}
/**
@@ -107,7 +112,12 @@ class submission_graded extends \core\event\base {
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_graded::create() directly, use submission_graded::create_from_grade() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('relateduserid is a mandatory property.');
}
+39 -29
View File
@@ -34,14 +34,36 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_locked extends \core\event\base {
class submission_locked extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @return submission_locked
*/
protected $legacylogdata;
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
);
self::$preventcreatecall = false;
/** @var submission_locked $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Returns description of what happened.
@@ -52,31 +74,13 @@ class submission_locked extends \core\event\base {
return "User {$this->userid} locked the submission for user {$this->relateduserid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_submission_locked', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventsubmissionlocked', 'mod_assign');
}
/**
@@ -91,23 +95,29 @@ class submission_locked extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$user = $this->get_record_snapshot('user', $this->relateduserid);
$logmessage = get_string('locksubmissionforstudent', 'assign', array('id' => $user->id, 'fullname' => fullname($user)));
$this->set_legacy_logdata('lock submission', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_locked::create() directly, use submission_locked::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('relateduserid is a mandatory property.');
}
@@ -40,14 +40,31 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_status_updated extends \core\event\base {
class submission_status_updated extends base {
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @return submission_status_updated
*/
protected $legacylogdata;
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $submission->id,
'relateduserid' => ($assign->get_instance()->teamsubmission) ? null : $submission->userid,
'other' => array(
'newstatus' => $submission->status
)
);
/** @var submission_status_updated $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
@@ -58,31 +75,13 @@ class submission_status_updated extends \core\event\base {
return "User {$this->userid} has updated the status of the submission {$this->objectid} to {$this->other['newstatus']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_submission_status_updated', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventsubmissionstatusupdated', 'mod_assign');
}
/**
@@ -97,23 +96,26 @@ class submission_status_updated extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$submission = $this->get_record_snapshot('assign_submission', $this->objectid);
$user = $this->get_record_snapshot('user', $submission->userid);
$logmessage = get_string('reverttodraftforstudent', 'assign', array('id' => $user->id, 'fullname' => fullname($user)));
$this->set_legacy_logdata('revert submission to draft', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['newstatus'])) {
throw new \coding_exception('newstatus must be set in $other.');
}
@@ -0,0 +1,127 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign submission status viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission status viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_status_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return submission_status_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var submission_status_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionstatusviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} has viewed the status of their submission for the assignment with
the id {$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$this->set_legacy_logdata('view', get_string('viewownsubmissionstatus', 'assign'));
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_status_viewed::create() directly, use submission_status_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -34,14 +34,36 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_unlocked extends \core\event\base {
class submission_unlocked extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @return submission_unlocked
*/
protected $legacylogdata;
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
);
self::$preventcreatecall = false;
/** @var submission_unlocked $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Returns description of what happened.
@@ -52,31 +74,13 @@ class submission_unlocked extends \core\event\base {
return "User {$this->userid} unlocked the submission for user {$this->relateduserid}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_submission_unlocked', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventsubmissionunlocked', 'mod_assign');
}
/**
@@ -91,23 +95,29 @@ class submission_unlocked extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$user = $this->get_record_snapshot('user', $this->relateduserid);
$logmessage = get_string('unlocksubmissionforstudent', 'assign', array('id' => $user->id, 'fullname' => fullname($user)));
$this->set_legacy_logdata('unlock submission', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_unlocked::create() directly, use submission_unlocked::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('relateduserid is a mandatory property.');
}
@@ -41,7 +41,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class submission_updated extends \core\event\base {
abstract class submission_updated extends base {
/**
* Init method.
@@ -60,14 +60,6 @@ abstract class submission_updated extends \core\event\base {
return get_string('eventsubmissionupdated', 'mod_assign');
}
/**
* Returns relevant URL.
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Custom validation.
*
@@ -0,0 +1,122 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_assign submission viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission viewed event.
*
* @property-read array $other {
* Extra information about the event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_viewed extends base {
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $submission
* @return submission_viewed
*/
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'objectid' => $submission->id,
'relateduserid' => $submission->userid,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
/** @var submission_viewed $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_submission';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with the id {$this->userid} viewed the submission for the user with the id {$this->relateduserid} for the
assignment with the id {$this->other['assignid']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
$logmessage = get_string('viewsubmissionforuser', 'assign', $this->relateduserid);
$this->set_legacy_logdata('view submission', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' must be set in other.');
}
}
}
@@ -40,14 +40,40 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class workflow_state_updated extends \core\event\base {
class workflow_state_updated extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @param string $state
* @return workflow_state_updated
*/
protected $legacylogdata;
public static function create_from_user(\assign $assign, \stdClass $user, $state) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
'other' => array(
'newstate' => $state,
),
);
self::$preventcreatecall = false;
/** @var workflow_state_updated $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Returns description of what happened.
@@ -58,31 +84,13 @@ class workflow_state_updated extends \core\event\base {
return "User {$this->userid} has set the workflow state of {$this->relateduserid} to {$this->other['newstate']}.";
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_workflow_state_updated', 'mod_assign');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
return get_string('eventworkflowstateupdated', 'mod_assign');
}
/**
@@ -97,23 +105,30 @@ class workflow_state_updated extends \core\event\base {
}
/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$user = $this->get_record_snapshot('user', $this->relateduserid);
$a = array('id' => $user->id, 'fullname' => fullname($user), 'state' => $this->other['newstate']);
$logmessage = get_string('setmarkingworkflowstateforlog', 'assign', $a);
$this->set_legacy_logdata('set marking workflow state', $logmessage);
return parent::get_legacy_logdata();
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call workflow_state_updated::create() directly, use workflow_state_updated::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->other['newstate'])) {
throw new \coding_exception('newstate must be set in $other.');
} else if (!isset($this->relateduserid)) {
+5 -3
View File
@@ -166,7 +166,6 @@ class assign_feedback_offline extends assign_feedback_plugin {
$grade->grader = $USER->id;
if ($this->assignment->update_grade($grade)) {
$this->assignment->notify_grade_modified($grade);
$this->assignment->add_to_log('grade submission', $this->assignment->format_grade_for_log($grade));
$updatecount += 1;
}
}
@@ -189,12 +188,15 @@ class assign_feedback_offline extends assign_feedback_plugin {
$grade = $this->assignment->get_user_grade($record->user->id, true);
$this->assignment->notify_grade_modified($grade);
if ($plugin->set_editor_text($field, $newvalue, $grade->id)) {
$logdesc = get_string('feedbackupdate', 'assignfeedback_offline',
$logdesc = new lang_string('feedbackupdate', 'assignfeedback_offline',
array('field'=>$description,
'student'=>$userdesc,
'text'=>$newvalue));
$this->assignment->add_to_log('save grading feedback', $logdesc);
// Trigger event for updating the feedback.
$event = \mod_assign\event\feedback_updated::create_from_grade($this->assignment, $grade);
$event->set_legacy_logdata('save grading feedback', $logdesc);
$event->trigger();
}
// If this is the gradebook comments plugin - post an update to the gradebook.
+1 -1
View File
@@ -32,7 +32,7 @@ require_login($course);
$PAGE->set_url('/mod/assign/index.php', array('id' => $id));
$PAGE->set_pagelayout('incourse');
add_to_log($course->id, 'assign', 'view all', 'index.php?id=$course->id', '');
\mod_assign\event\course_module_instance_list_viewed::create_from_course($course)->trigger();
// Print the header.
$strplural = get_string("modulenameplural", "assign");
+23 -12
View File
@@ -140,20 +140,31 @@ $string['editsubmissionother'] = 'Edit submission for {$a}';
$string['editsubmission_help'] = 'Make changes to your submission';
$string['editingstatus'] = 'Editing status';
$string['editaction'] = 'Actions...';
$string['event_assessable_submitted'] = 'A submission has been submitted.';
$string['event_all_submissions_downloaded'] = 'All the submissions are being downloaded.';
$string['event_extension_granted'] = 'An extension has been granted.';
$string['event_identities_revealed'] = 'The identities have been revealed.';
$string['event_marker_updated'] = 'The allocated marker has been updated.';
$string['event_statement_accepted'] = 'The user has accepted the statement of the submission.';
$string['event_submission_duplicated'] = 'The user duplicated his submission.';
$string['event_submission_graded'] = 'The submission has been graded.';
$string['event_submission_locked'] = 'The submissions have been locked for a user.';
$string['event_submission_status_updated'] = 'The status of the submission has been updated.';
$string['event_submission_unlocked'] = 'The submissions have been unlocked for a user.';
$string['event_workflow_state_updated'] = 'The state of the workflow has been updated.';
$string['eventallsubmissionsdownloaded'] = 'All the submissions are being downloaded.';
$string['eventassessablesubmitted'] = 'A submission has been submitted.';
$string['eventbatchsetmarkerallocationviewed'] = 'Batch set marker allocation viewed';
$string['eventbatchsetworkflowstateviewed'] = 'Batch set workflow state viewed.';
$string['eventextensiongranted'] = 'An extension has been granted.';
$string['eventfeedbackupdated'] = 'Feedback updated';
$string['eventfeedbackviewed'] = 'Feedback viewed';
$string['eventgradingformviewed'] = 'Grading form viewed';
$string['eventgradingtableviewed'] = 'Grading table viewed';
$string['eventidentitiesrevealed'] = 'The identities have been revealed.';
$string['eventmarkerupdated'] = 'The allocated marker has been updated.';
$string['eventrevealidentitiesconfirmationpageviewed'] = 'Reveal identities confirmation page viewed.';
$string['eventstatementaccepted'] = 'The user has accepted the statement of the submission.';
$string['eventsubmissionconfirmationformviewed'] = 'Submission confirmation form viewed.';
$string['eventsubmissioncreated'] = 'Submission created.';
$string['eventsubmissionduplicated'] = 'The user duplicated his submission.';
$string['eventsubmissionformviewed'] = 'Submission form viewed.';
$string['eventsubmissiongraded'] = 'The submission has been graded.';
$string['eventsubmissionlocked'] = 'The submissions have been locked for a user.';
$string['eventsubmissionstatusupdated'] = 'The status of the submission has been updated.';
$string['eventsubmissionstatusviewed'] = 'The status of the submission has been viewed.';
$string['eventsubmissionunlocked'] = 'The submissions have been unlocked for a user.';
$string['eventsubmissionupdated'] = 'Submission updated.';
$string['eventsubmissionviewed'] = 'Submission viewed.';
$string['eventworkflowstateupdated'] = 'The state of the workflow has been updated.';
$string['extensionduedate'] = 'Extension due date';
$string['extensionnotafterduedate'] = 'Extension date must be after the due date';
$string['extensionnotafterfromdate'] = 'Extension date must be after the allow submissions from date';
+64 -211
View File
@@ -1837,6 +1837,7 @@ class assign {
if ($result) {
$this->gradebook_item_update(null, $grade);
\mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
}
return $result;
}
@@ -2011,8 +2012,7 @@ class assign {
$submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
$sid = $DB->insert_record('assign_submission', $submission);
$submission->id = $sid;
return $submission;
return $DB->get_record('assign_submission', array('id' => $sid));
}
return false;
}
@@ -2150,8 +2150,6 @@ class assign {
* @return string
*/
protected function view_plugin_content($pluginsubtype) {
global $USER;
$o = '';
$submissionid = optional_param('sid', 0, PARAM_INT);
@@ -2179,8 +2177,9 @@ class assign {
$this->get_return_action(),
$this->get_return_params()));
$logmessage = get_string('viewsubmissionforuser', 'assign', $item->userid);
$this->add_to_log('view submission', $logmessage);
// Trigger event for viewing a submission.
\mod_assign\event\submission_viewed::create_from_submission($this, $item)->trigger();
} else {
$plugin = $this->get_feedback_plugin_by_type($plugintype);
if ($gradeid <= 0) {
@@ -2200,13 +2199,15 @@ class assign {
$this->get_course_module()->id,
$this->get_return_action(),
$this->get_return_params()));
$logmessage = get_string('viewfeedbackforuser', 'assign', $item->userid);
$this->add_to_log('view feedback', $logmessage);
// Trigger event for viewing feedback.
\mod_assign\event\feedback_viewed::create_from_grade($this, $item)->trigger();
}
$o .= $this->view_return_links();
$o .= $this->view_footer();
return $o;
}
@@ -2347,7 +2348,12 @@ class assign {
* @return string
*/
protected function view_footer() {
return $this->get_renderer()->render_footer();
// When viewing the footer during PHPUNIT tests a set_state error is thrown.
if (!PHPUNIT_TEST) {
return $this->get_renderer()->render_footer();
}
return '';
}
/**
@@ -2500,14 +2506,7 @@ class assign {
$result .= $this->get_renderer()->continue_button($url);
$result .= $this->view_footer();
} else if ($zipfile = $this->pack_files($filesforzipping)) {
$addtolog = $this->add_to_log('download all submissions', get_string('downloadall', 'assign'), '', true);
$params = array(
'context' => $this->context,
'objectid' => $this->get_instance()->id
);
$event = \mod_assign\event\all_submissions_downloaded::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\all_submissions_downloaded::create_from_assign($this)->trigger();
// Send file and delete after sending.
send_temp_file($zipfile, $filename);
// We will not get here - send_temp_file calls exit.
@@ -2518,6 +2517,9 @@ class assign {
/**
* Util function to add a message to the log.
*
* @deprecated since 2.7 - Use new events system instead.
* (see http://docs.moodle.org/dev/Migrating_logging_calls_in_plugins).
*
* @param string $action The current action
* @param string $info A detailed description of the change. But no more than 255 characters.
* @param string $url The url to the assign module instance.
@@ -2543,6 +2545,9 @@ class assign {
);
if ($return) {
// We only need to call debugging when returning a value. This is because the call to
// call_user_func_array('add_to_log', $args) will trigger a debugging message of it's own.
debugging('The mod_assign add_to_log() function is now deprecated.', DEBUG_DEVELOPER);
return $args;
}
call_user_func_array('add_to_log', $args);
@@ -2610,8 +2615,7 @@ class assign {
$submission->attemptnumber = 0;
}
$sid = $DB->insert_record('assign_submission', $submission);
$submission->id = $sid;
return $submission;
return $DB->get_record('assign_submission', array('id' => $sid));
}
return false;
}
@@ -2919,10 +2923,7 @@ class assign {
$o .= $this->get_renderer()->render($history);
}
$msg = get_string('viewgradingformforstudent',
'assign',
array('id'=>$user->id, 'fullname'=>fullname($user)));
$this->add_to_log('view grading form', $msg);
\mod_assign\event\grading_form_viewed::create_from_user($this, $user)->trigger();
$o .= $this->view_footer();
return $o;
@@ -2934,8 +2935,6 @@ class assign {
* @return string
*/
protected function view_reveal_identities_confirm() {
global $CFG, $USER;
require_capability('mod/assign:revealidentities', $this->get_context());
$o = '';
@@ -2958,7 +2957,9 @@ class assign {
$confirmurl,
$cancelurl);
$o .= $this->view_footer();
$this->add_to_log('view', get_string('viewrevealidentitiesconfirm', 'assign'));
\mod_assign\event\reveal_identities_confirmation_page_viewed::create_from_assign($this)->trigger();
return $o;
}
@@ -3176,15 +3177,15 @@ class assign {
$o .= $this->view_footer();
$logmessage = get_string('viewsubmissiongradingtable', 'assign');
$this->add_to_log('view submission grading table', $logmessage);
\mod_assign\event\grading_table_viewed::create_from_assign($this)->trigger();
return $o;
}
/**
* Capture the output of the plagiarism plugins disclosures and return it as a string.
*
* @return void
* @return string
*/
protected function plagiarism_print_disclosure() {
global $CFG;
@@ -3260,7 +3261,7 @@ class assign {
require_once($CFG->dirroot . '/mod/assign/submission_form.php');
// Need submit permission to submit an assignment.
$userid = optional_param('userid', $USER->id, PARAM_INT);
$user = clone($USER);
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
if ($userid == $USER->id) {
// User is editing their own submission.
require_capability('mod/assign:submit', $this->context);
@@ -3271,7 +3272,6 @@ class assign {
print_error('nopermission');
}
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
$name = $this->fullname($user);
$title = get_string('editsubmissionother', 'assign', $name);
}
@@ -3303,7 +3303,8 @@ class assign {
$o .= $this->get_renderer()->render(new assign_form('editsubmissionform', $mform));
$o .= $this->view_footer();
$this->add_to_log('view submit assignment form', $title);
\mod_assign\event\submission_form_viewed::create_from_user($this, $user)->trigger();
return $o;
}
@@ -3477,7 +3478,7 @@ class assign {
* @param moodleform $mform Set to a grading batch operations form
* @return string - the page to view after processing these actions
*/
private function view_batch_set_workflow_state($mform) {
protected function view_batch_set_workflow_state($mform) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');
@@ -3522,7 +3523,8 @@ class assign {
$o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
$o .= $this->view_footer();
$this->add_to_log('view batch set marking workflow state', get_string('viewbatchsetmarkingworkflowstate', 'assign'));
\mod_assign\event\batch_set_workflow_state_viewed::create_from_assign($this)->trigger();
return $o;
}
@@ -3532,7 +3534,7 @@ class assign {
* @param moodleform $mform Set to a grading batch operations form
* @return string - the page to view after processing these actions
*/
private function view_batch_markingallocation($mform) {
public function view_batch_markingallocation($mform) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
@@ -3583,7 +3585,8 @@ class assign {
$o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
$o .= $this->view_footer();
$this->add_to_log('view batch set marker allocation', get_string('viewbatchmarkingallocation', 'assign'));
\mod_assign\event\batch_set_marker_allocation_viewed::create_from_assign($this)->trigger();
return $o;
}
@@ -3635,8 +3638,7 @@ class assign {
$o .= $this->get_renderer()->render($submitforgradingpage);
$o .= $this->view_footer();
$logmessage = get_string('viewownsubmissionform', 'assign');
$this->add_to_log('view confirm submit assignment form', $logmessage);
\mod_assign\event\submission_confirmation_form_viewed::create_from_assign($this)->trigger();
return $o;
}
@@ -4022,7 +4024,9 @@ class assign {
}
$o .= $this->view_footer();
$this->add_to_log('view', get_string('viewownsubmissionstatus', 'assign'));
\mod_assign\event\submission_status_viewed::create_from_assign($this)->trigger();
return $o;
}
@@ -4755,26 +4759,13 @@ class assign {
}
if (!empty($data->submissionstatement) && $USER->id == $userid) {
$logmessage = get_string('submissionstatementacceptedlog',
'mod_assign',
fullname($USER));
$this->add_to_log('submission statement accepted', $logmessage);
\mod_assign\event\statement_accepted::create_from_submission($this, $submission)->trigger();
}
$logdata = $this->add_to_log('submit for grading', $this->format_submission_for_log($submission), '', true);
$this->notify_graders($submission);
$this->notify_student_submission_receipt($submission);
// Trigger assessable_submitted event on submission.
$params = array(
'context' => context_module::instance($this->get_course_module()->id),
'objectid' => $submission->id,
'other' => array(
'submission_editable' => false
)
);
$event = \mod_assign\event\assessable_submitted::create($params);
$event->set_legacy_logdata($logdata);
$event->trigger();
\mod_assign\event\assessable_submitted::create_from_submission($this, $submission, false)->trigger();
return true;
}
$notices[] = get_string('submissionsclosed', 'assign');
@@ -4884,15 +4875,7 @@ class assign {
$result = $this->update_user_flags($flags);
if ($result) {
$addtolog = $this->add_to_log('grant extension', $userid, '', true);
$params = array(
'context' => $this->context,
'objectid' => $flags->assignment,
'relateduserid' => $userid
);
$event = \mod_assign\event\extension_granted::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\extension_granted::create_from_assign($this, $userid)->trigger();
}
return $result;
}
@@ -5147,16 +5130,6 @@ class assign {
$data);
}
}
$addtolog = $this->add_to_log('grade submission', $this->format_grade_for_log($grade), '', true);
$params = array(
'context' => $this->context,
'objectid' => $grade->id,
'relateduserid' => $userid
);
$event = \mod_assign\event\submission_graded::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
}
return get_string('quickgradingchangessaved', 'assign');
@@ -5206,14 +5179,7 @@ class assign {
$this->gradebook_item_update(null, $grade);
}
$addtolog = $this->add_to_log('reveal identities', get_string('revealidentities', 'assign'), '', true);
$params = array(
'context' => $this->context,
'objectid' => $update->id
);
$event = \mod_assign\event\identities_revealed::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\identities_revealed::create_from_assign($this)->trigger();
}
/**
@@ -5316,6 +5282,8 @@ class assign {
* The size limit for the log file is 255 characters, so be careful not
* to include too much information.
*
* @deprecated since 2.7
*
* @param stdClass $grade
* @return string
*/
@@ -5338,10 +5306,12 @@ class assign {
* The size limit for the log file is 255 characters, so be careful not
* to include too much information.
*
* @deprecated since 2.7
*
* @param stdClass $submission
* @return string
*/
protected function format_submission_for_log(stdClass $submission) {
public function format_submission_for_log(stdClass $submission) {
global $DB;
$info = '';
@@ -5439,14 +5409,7 @@ class assign {
return false;
}
$addtolog = $this->add_to_log('submissioncopied', $this->format_submission_for_log($submission), '', true);
$params = array(
'context' => $this->context,
'objectid' => $submission->id
);
$event = \mod_assign\event\submission_duplicated::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\submission_duplicated::create_from_submission($this, $submission)->trigger();
$complete = COMPLETION_INCOMPLETE;
if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
@@ -5463,19 +5426,11 @@ class assign {
// is clear that the submission was copied.
$this->notify_student_submission_copied($submission);
$this->notify_graders($submission);
// Trigger assessable_submitted event on submission.
// The same logic applies here - we could not notify teachers,
// but then they would wonder why there are submitted assignments
// and they haven't been notified.
$params = array(
'context' => context_module::instance($this->get_course_module()->id),
'objectid' => $submission->id,
'other' => array(
'submission_editable' => true
)
);
$event = \mod_assign\event\assessable_submitted::create($params);
$event->trigger();
\mod_assign\event\assessable_submitted::create_from_submission($this, $submission, true)->trigger();
}
return true;
}
@@ -5554,6 +5509,7 @@ class assign {
}
}
}
$allempty = $this->submission_empty($submission);
if ($pluginerror || $allempty) {
if ($allempty) {
@@ -5566,18 +5522,7 @@ class assign {
// Logging.
if (isset($data->submissionstatement) && ($userid == $USER->id)) {
$logmessage = get_string('submissionstatementacceptedlog',
'mod_assign',
fullname($USER));
$this->add_to_log('submission statement accepted', $logmessage);
$addtolog = $this->add_to_log('submission statement accepted', $logmessage, '', true);
$params = array(
'context' => $this->context,
'objectid' => $submission->id
);
$event = \mod_assign\event\statement_accepted::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\statement_accepted::create_from_submission($this, $submission)->trigger();
}
$complete = COMPLETION_INCOMPLETE;
@@ -5592,16 +5537,7 @@ class assign {
if (!$instance->submissiondrafts) {
$this->notify_student_submission_receipt($submission);
$this->notify_graders($submission);
// Trigger assessable_submitted event on submission.
$params = array(
'context' => context_module::instance($this->get_course_module()->id),
'objectid' => $submission->id,
'other' => array(
'submission_editable' => true
)
);
$event = \mod_assign\event\assessable_submitted::create($params);
$event->trigger();
\mod_assign\event\assessable_submitted::create_from_submission($this, $submission, true)->trigger();
}
return true;
}
@@ -6111,28 +6047,12 @@ class assign {
$grade->grader = $USER->id;
$this->update_grade($grade);
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$completion = new completion_info($this->get_course());
if ($completion->is_enabled($this->get_course_module()) &&
$this->get_instance()->completionsubmit) {
$completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
}
$logmessage = get_string('reverttodraftforstudent',
'assign',
array('id'=>$user->id, 'fullname'=>fullname($user)));
$addtolog = $this->add_to_log('revert submission to draft', $logmessage, '', true);
$params = array(
'context' => $this->context,
'objectid' => $submission->id,
'relateduserid' => ($this->get_instance()->teamsubmission) ? null : $userid,
'other' => array(
'newstatus' => $submission->status
)
);
$event = \mod_assign\event\submission_status_updated::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
return true;
}
@@ -6179,19 +6099,7 @@ class assign {
}
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$logmessage = get_string('locksubmissionforstudent',
'assign',
array('id'=>$user->id, 'fullname'=>fullname($user)));
$addtolog = $this->add_to_log('lock submission', $logmessage, '', true);
$params = array(
'context' => $this->context,
'objectid' => $flags->assignment,
'relateduserid' => $user->id
);
$event = \mod_assign\event\submission_locked::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\submission_locked::create_from_user($this, $user)->trigger();
return true;
}
@@ -6229,23 +6137,7 @@ class assign {
}
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$params = array('id'=>$user->id,
'fullname'=>fullname($user),
'state'=>$state);
$message = get_string('setmarkingworkflowstateforlog', 'assign', $params);
$addtolog = $this->add_to_log('set marking workflow state', $message, '', true);
$params = array(
'context' => $this->context,
'objectid' => $this->get_instance()->id,
'relateduserid' => $userid,
'other' => array(
'newstate' => $state
)
);
$event = \mod_assign\event\workflow_state_updated::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger();
}
}
}
@@ -6280,25 +6172,8 @@ class assign {
$flags->allocatedmarker = $marker->id;
if ($this->update_user_flags($flags)) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$params = array('id'=>$user->id,
'fullname'=>fullname($user),
'marker'=>fullname($marker));
$message = get_string('setmarkerallocationforlog', 'assign', $params);
$addtolog = $this->add_to_log('set marking allocation', $message, '', true);
$params = array(
'context' => $this->context,
'objectid' => $this->get_instance()->id,
'relateduserid' => $userid,
'other' => array(
'markerid' => $marker->id
)
);
$event = \mod_assign\event\marker_updated::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\marker_updated::create_from_marker($this, $user, $marker)->trigger();
}
}
}
@@ -6349,19 +6224,7 @@ class assign {
}
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$logmessage = get_string('unlocksubmissionforstudent',
'assign',
array('id'=>$user->id, 'fullname'=>fullname($user)));
$addtolog = $this->add_to_log('unlock submission', $logmessage, '', true);
$params = array(
'context' => $this->context,
'objectid' => $flags->assignment,
'relateduserid' => $user->id
);
$event = \mod_assign\event\submission_unlocked::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
\mod_assign\event\submission_unlocked::create_from_user($this, $user)->trigger();
return true;
}
@@ -6439,16 +6302,6 @@ class assign {
if (!isset($formdata->sendstudentnotifications) || $formdata->sendstudentnotifications) {
$this->notify_grade_modified($grade);
}
$addtolog = $this->add_to_log('grade submission', $this->format_grade_for_log($grade), '', true);
$params = array(
'context' => $this->context,
'objectid' => $grade->id,
'relateduserid' => $userid
);
$event = \mod_assign\event\submission_graded::create($params);
$event->set_legacy_logdata($addtolog);
$event->trigger();
}
+2
View File
@@ -260,6 +260,7 @@ class assign_submission_file extends assign_submission_plugin {
$params['objectid'] = $filesubmission->id;
$event = \assignsubmission_file\event\submission_updated::create($params);
$event->set_assign($this->assignment);
$event->trigger();
return $updatestatus;
} else {
@@ -272,6 +273,7 @@ class assign_submission_file extends assign_submission_plugin {
$params['objectid'] = $filesubmission->id;
$event = \assignsubmission_file\event\submission_created::create($params);
$event->set_assign($this->assignment);
$event->trigger();
return $filesubmission->id > 0;
}
@@ -262,6 +262,7 @@ class assign_submission_onlinetext extends assign_submission_plugin {
$params['objectid'] = $onlinetextsubmission->id;
$updatestatus = $DB->update_record('assignsubmission_onlinetext', $onlinetextsubmission);
$event = \assignsubmission_onlinetext\event\submission_updated::create($params);
$event->set_assign($this->assignment);
$event->trigger();
return $updatestatus;
} else {
@@ -275,6 +276,7 @@ class assign_submission_onlinetext extends assign_submission_plugin {
$onlinetextsubmission->id = $DB->insert_record('assignsubmission_onlinetext', $onlinetextsubmission);
$params['objectid'] = $onlinetextsubmission->id;
$event = \assignsubmission_onlinetext\event\submission_created::create($params);
$event->set_assign($this->assignment);
$event->trigger();
return $onlinetextsubmission->id > 0;
}
+44
View File
@@ -290,4 +290,48 @@ class testable_assign extends assign {
// Changed method from protected to public.
return parent::get_graders($userid);
}
public function testable_view_batch_set_workflow_state() {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');
// Mock submit data.
$data = array();
$data['selectedusers'] = '1';
mod_assign_batch_set_marking_workflow_state_form::mock_submit($data);
// Set required variables in the form - not valid just allows us to continue.
$formparams = array();
$formparams['users'] = array(1);
$formparams['usershtml'] = 1;
$formparams['cm'] = $this->get_course_module()->id;
$formparams['context'] = $this->get_context();
$formparams['markingworkflowstates'] = 1;
$mform = new mod_assign_batch_set_marking_workflow_state_form('', $formparams);
return parent::view_batch_set_workflow_state($mform);
}
public function testable_view_batch_markingallocation() {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
// Mock submit data.
$data = array();
$data['selectedusers'] = '1';
mod_assign_batch_set_allocatedmarker_form::mock_submit($data);
// Set required variables in the form - not valid just allows us to continue.
$formparams = array();
$formparams['users'] = array(1);
$formparams['usershtml'] = 1;
$formparams['cm'] = $this->get_course_module()->id;
$formparams['context'] = $this->get_context();
$formparams['markers'] = 1;
$mform = new mod_assign_batch_set_allocatedmarker_form('', $formparams);
return parent::view_batch_markingallocation($mform);
}
}
-171
View File
@@ -1,171 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains the event tests for the module assign.
*
* @package mod_assign
* @copyright 2014 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
require_once($CFG->dirroot . '/mod/assign/tests/fixtures/event_mod_assign_fixtures.php');
/**
* Contains the event tests for the module assign.
*
* @package mod_assign
* @copyright 2014 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_events_testcase extends advanced_testcase {
/** @var stdClass $user A user to submit an assignment. */
protected $user;
/** @var stdClass $course New course created to hold the assignment activity. */
protected $course;
/** @var stdClass $cm A context module object. */
protected $cm;
/** @var stdClass $context Context of the assignment activity. */
protected $context;
/** @var array $params Standard event parameters. */
protected $params;
/**
* Setup all the various parts of an assignment activity.
*/
protected function setUp() {
$this->user = $this->getDataGenerator()->create_user();
$this->course = $this->getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $this->course->id));
$this->cm = get_coursemodule_from_instance('assign', $instance->id);
$this->context = context_module::instance($this->cm->id);
// Standard Event parameters.
$this->params = array(
'context' => $this->context,
'courseid' => $this->course->id
);
}
/**
* Basic tests for the submission_created() abstract class.
*/
public function test_submission_created() {
$this->resetAfterTest();
$eventinfo = $this->params;
$eventinfo['other'] = array(
'submissionid' => '17',
'submissionattempt' => 0,
'submissionstatus' => 'submitted'
);
$sink = $this->redirectEvents();
$event = \mod_assign_unittests\event\submission_created::create($eventinfo);
$event->trigger();
$result = $sink->get_events();
$event = reset($result);
$sink->close();
$this->assertEquals($this->context->id, $event->contextid);
$this->assertEquals($this->course->id, $event->courseid);
// Check that an error occurs when teamsubmission is not set.
try {
\mod_assign_unittests\event\submission_created::create($this->params);
$this->fail('Other must contain the key submissionid.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
// Check that the submission status debugging is fired.
$subinfo = $this->params;
$subinfo['other'] = array('submissionid' => '23');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionattempt.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
$subinfo['other'] = array('submissionattempt' => '0');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionstatus.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
/**
* Basic tests for the submission_updated() abstract class.
*/
public function test_submission_updated() {
$this->resetAfterTest();
$eventinfo = $this->params;
$eventinfo['other'] = array(
'submissionid' => '17',
'submissionattempt' => 0,
'submissionstatus' => 'submitted'
);
$sink = $this->redirectEvents();
$event = \mod_assign_unittests\event\submission_updated::create($eventinfo);
$event->trigger();
$result = $sink->get_events();
$event = reset($result);
$sink->close();
$this->assertEquals($this->context->id, $event->contextid);
$this->assertEquals($this->course->id, $event->courseid);
// Check that an error occurs when teamsubmission is not set.
try {
\mod_assign_unittests\event\submission_created::create($this->params);
$this->fail('Other must contain the key submissionid.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
// Check that the submission status debugging is fired.
$subinfo = $this->params;
$subinfo['other'] = array('submissionid' => '23');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionattempt.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
$subinfo['other'] = array('submissionattempt' => '0');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionstatus.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
}
+994
View File
@@ -0,0 +1,994 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains the event tests for the module assign.
*
* @package mod_assign
* @copyright 2014 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
require_once($CFG->dirroot . '/mod/assign/tests/fixtures/event_mod_assign_fixtures.php');
/**
* Contains the event tests for the module assign.
*
* @package mod_assign
* @copyright 2014 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_events_testcase extends mod_assign_base_testcase {
/**
* Basic tests for the submission_created() abstract class.
*/
public function test_base_event() {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $this->course->id));
$modcontext = context_module::instance($instance->cmid);
$data = array(
'context' => $modcontext,
);
/** @var \mod_assign_unittests\event\nothing_happened $event */
$event = \mod_assign_unittests\event\nothing_happened::create($data);
$assign = $event->get_assign();
$this->assertDebuggingCalled();
$this->assertInstanceOf('assign', $assign);
$event = \mod_assign_unittests\event\nothing_happened::create($data);
$event->set_assign($assign);
$assign2 = $event->get_assign();
$this->assertDebuggingNotCalled();
$this->assertSame($assign, $assign2);
}
/**
* Basic tests for the submission_created() abstract class.
*/
public function test_submission_created() {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $this->course->id));
$modcontext = context_module::instance($instance->cmid);
// Standard Event parameters.
$params = array(
'context' => $modcontext,
'courseid' => $this->course->id
);
$eventinfo = $params;
$eventinfo['other'] = array(
'submissionid' => '17',
'submissionattempt' => 0,
'submissionstatus' => 'submitted'
);
$sink = $this->redirectEvents();
$event = \mod_assign_unittests\event\submission_created::create($eventinfo);
$event->trigger();
$result = $sink->get_events();
$event = reset($result);
$sink->close();
$this->assertEquals($modcontext->id, $event->contextid);
$this->assertEquals($this->course->id, $event->courseid);
// Check that an error occurs when teamsubmission is not set.
try {
\mod_assign_unittests\event\submission_created::create($params);
$this->fail('Other must contain the key submissionid.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
// Check that the submission status debugging is fired.
$subinfo = $params;
$subinfo['other'] = array('submissionid' => '23');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionattempt.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
$subinfo['other'] = array('submissionattempt' => '0');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionstatus.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
/**
* Basic tests for the submission_updated() abstract class.
*/
public function test_submission_updated() {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $this->course->id));
$modcontext = context_module::instance($instance->cmid);
// Standard Event parameters.
$params = array(
'context' => $modcontext,
'courseid' => $this->course->id
);
$eventinfo = $params;
$eventinfo['other'] = array(
'submissionid' => '17',
'submissionattempt' => 0,
'submissionstatus' => 'submitted'
);
$sink = $this->redirectEvents();
$event = \mod_assign_unittests\event\submission_updated::create($eventinfo);
$event->trigger();
$result = $sink->get_events();
$event = reset($result);
$sink->close();
$this->assertEquals($modcontext->id, $event->contextid);
$this->assertEquals($this->course->id, $event->courseid);
// Check that an error occurs when teamsubmission is not set.
try {
\mod_assign_unittests\event\submission_created::create($params);
$this->fail('Other must contain the key submissionid.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
// Check that the submission status debugging is fired.
$subinfo = $params;
$subinfo['other'] = array('submissionid' => '23');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionattempt.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
$subinfo['other'] = array('submissionattempt' => '0');
try {
\mod_assign_unittests\event\submission_created::create($subinfo);
$this->fail('Other must contain the key submissionstatus.');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
public function test_extension_granted() {
$this->setUser($this->editingteachers[0]);
$tomorrow = time() + 24*60*60;
$yesterday = time() - 24*60*60;
$assign = $this->create_instance(array('duedate' => $yesterday, 'cutoffdate' => $yesterday));
$sink = $this->redirectEvents();
$assign->testable_save_user_extension($this->students[0]->id, $tomorrow);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\extension_granted', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grant extension',
'view.php?id=' . $assign->get_course_module()->id,
$this->students[0]->id,
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
public function test_submission_locked() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->lock_submission($this->students[0]->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_locked', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'lock submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('locksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_identities_revealed() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance(array('blindmarking'=>1));
$sink = $this->redirectEvents();
$assign->reveal_identities();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\identities_revealed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$expected = array(
$assign->get_course()->id,
'assign',
'reveal identities',
'view.php?id=' . $assign->get_course_module()->id,
get_string('revealidentities', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
/**
* Test the submission_status_viewed event.
*/
public function test_submission_status_viewed() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
// We need to set the URL in order to view the feedback.
$PAGE->set_url('/a_url');
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\submission_status_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewownsubmissionstatus', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
public function test_submission_status_updated() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$assign->testable_update_submission($submission, $this->students[0]->id, true, false);
$sink = $this->redirectEvents();
$assign->revert_to_draft($this->students[0]->id);
$events = $sink->get_events();
$this->assertCount(2, $events);
$event = $events[1];
$this->assertInstanceOf('\mod_assign\event\submission_status_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals(ASSIGN_SUBMISSION_STATUS_DRAFT, $event->other['newstatus']);
$expected = array(
$assign->get_course()->id,
'assign',
'revert submission to draft',
'view.php?id=' . $assign->get_course_module()->id,
get_string('reverttodraftforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_marker_updated() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->testable_process_set_batch_marking_allocation($this->students[0]->id, $this->teachers[0]->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\marker_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals($this->teachers[0]->id, $event->other['markerid']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking allocation',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkerallocationforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'marker' => fullname($this->teachers[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_workflow_state_updated() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->testable_process_set_batch_marking_workflow_state($this->students[0]->id, ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\workflow_state_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals(ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW, $event->other['newstate']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking workflow state',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW)),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_duplicated() {
$this->setUser($this->students[0]);
$assign = $this->create_instance();
$submission1 = $assign->get_user_submission($this->students[0]->id, true, 0);
$submission2 = $assign->get_user_submission($this->students[0]->id, true, 1);
$submission2->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
$assign->testable_update_submission($submission2, $this->students[0]->id, time(), $assign->get_instance()->teamsubmission);
$sink = $this->redirectEvents();
$notices = null;
$assign->copy_previous_attempt($notices);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_duplicated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission2->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->userid);
$submission2->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
$expected = array(
$assign->get_course()->id,
'assign',
'submissioncopied',
'view.php?id=' . $assign->get_course_module()->id,
$assign->testable_format_submission_for_log($submission2),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
public function test_submission_unlocked() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->unlock_submission($this->students[0]->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_unlocked', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'unlock submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('unlocksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_graded() {
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
// Test apply_grade_to_user.
$sink = $this->redirectEvents();
$data = new stdClass();
$data->grade = '50.0';
$assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
$grade = $assign->get_user_grade($this->students[0]->id, false, 0);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grade submission',
'view.php?id=' . $assign->get_course_module()->id,
$assign->format_grade_for_log($grade),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Test process_save_quick_grades.
$sink = $this->redirectEvents();
$data = array(
'grademodified_' . $this->students[0]->id => time(),
'quickgrade_' . $this->students[0]->id => '60.0'
);
$assign->testable_process_save_quick_grades($data);
$grade = $assign->get_user_grade($this->students[0]->id, false);
$this->assertEquals('60.0', $grade->grade);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grade submission',
'view.php?id=' . $assign->get_course_module()->id,
$assign->format_grade_for_log($grade),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Test update_grade.
$sink = $this->redirectEvents();
$data = clone($grade);
$data->grade = '50.0';
$assign->update_grade($data);
$grade = $assign->get_user_grade($this->students[0]->id, false, 0);
$this->assertEquals('50.0', $grade->grade);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grade submission',
'view.php?id=' . $assign->get_course_module()->id,
$assign->format_grade_for_log($grade),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
/**
* Test the submission_viewed event.
*/
public function test_submission_viewed() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
// We need to set the URL in order to view the submission.
$PAGE->set_url('/a_url');
// A hack - these variables are used by the view_plugin_content function to
// determine what we actually want to view - would usually be set in URL.
global $_POST;
$_POST['plugin'] = 'comments';
$_POST['sid'] = $submission->id;
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view('viewpluginassignsubmission');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\submission_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission->id, $event->objectid);
$expected = array(
$assign->get_course()->id,
'assign',
'view submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewsubmissionforuser', 'assign', $this->students[0]->id),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the feedback_viewed event.
*/
public function test_feedback_viewed() {
global $DB, $PAGE;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
// Insert a grade for this submission.
$grade = new stdClass();
$grade->assignment = 1;
$grade->userid = $this->students[0]->id;
$gradeid = $DB->insert_record('assign_grades', $grade);
// We need to set the URL in order to view the feedback.
$PAGE->set_url('/a_url');
// A hack - these variables are used by the view_plugin_content function to
// determine what we actually want to view - would usually be set in URL.
global $_POST;
$_POST['plugin'] = 'comments';
$_POST['gid'] = $gradeid;
$_POST['sid'] = $submission->id;
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view('viewpluginassignfeedback');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\feedback_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($gradeid, $event->objectid);
$expected = array(
$assign->get_course()->id,
'assign',
'view feedback',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewfeedbackforuser', 'assign', $this->students[0]->id),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the feedback_updated event.
*/
public function test_feedback_updated() {
$assign = $this->create_instance();
$logdesc = get_string('feedbackupdate', 'assignfeedback_offline',
array('field' => 'The description',
'student' => 'The student\'s name',
'text' => 'Text'));
$event = \mod_assign\event\feedback_updated::create(array(
'userid' => 2,
'relateduserid' => 2,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id
)
));
$event->set_legacy_logdata('save grading feedback', $logdesc);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\feedback_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expectedlog = array($assign->get_course()->id, 'assign', 'save grading feedback', 'view.php?id=' . $assign->get_course_module()->id,
$logdesc, $assign->get_course_module()->id);
$this->assertEventLegacyLogData($expectedlog, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the grading_form_viewed event.
*/
public function test_grading_form_viewed() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
// We need to set the URL in order to view the feedback.
$PAGE->set_url('/a_url');
// A hack - this variable is used by the view_single_grade_page function.
global $_POST;
$_POST['rownum'] = 1;
$_POST['userid'] = $this->students[0]->id;
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view('grade');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\grading_form_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view grading form',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewgradingformforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the grading_table_viewed event.
*/
public function test_grading_table_viewed() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
// We need to set the URL in order to view the feedback.
$PAGE->set_url('/a_url');
// A hack - this variable is used by the view_single_grade_page function.
global $_POST;
$_POST['rownum'] = 1;
$_POST['userid'] = $this->students[0]->id;
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view('grading');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\grading_table_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view submission grading table',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewsubmissiongradingtable', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the submission_form_viewed event.
*/
public function test_submission_form_viewed() {
global $PAGE;
$this->setUser($this->students[0]);
$assign = $this->create_instance();
// We need to set the URL in order to view the submission form.
$PAGE->set_url('/a_url');
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view('editsubmission');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\submission_form_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view submit assignment form',
'view.php?id=' . $assign->get_course_module()->id,
get_string('editsubmission', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the submission_form_viewed event.
*/
public function test_submission_confirmation_form_viewed() {
global $PAGE;
$this->setUser($this->students[0]);
$assign = $this->create_instance();
// We need to set the URL in order to view the submission form.
$PAGE->set_url('/a_url');
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view('submit');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\submission_confirmation_form_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view confirm submit assignment form',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewownsubmissionform', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the reveal_identities_confirmation_page_viewed event.
*/
public function test_reveal_identities_confirmation_page_viewed() {
global $PAGE;
// Set to the admin user so we have the permission to reveal identities.
$this->setAdminUser();
$assign = $this->create_instance();
// We need to set the URL in order to view the submission form.
$PAGE->set_url('/a_url');
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->view('revealidentities');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\reveal_identities_confirmation_page_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewrevealidentitiesconfirm', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the statement_accepted event.
*/
public function test_statement_accepted() {
// We want to be a student so we can submit assignments.
$this->setUser($this->students[0]);
// We do not want to send any messages to the student during the PHPUNIT test.
set_config('submissionreceipts', false, 'assign');
$assign = $this->create_instance();
// Create the data we want to pass to the submit_for_grading function.
$data = new stdClass();
$data->submissionstatement = 'We are the Borg. You will be assimilated. Resistance is futile. - do you agree
to these terms?';
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->submit_for_grading($data, array());
$events = $sink->get_events();
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\statement_accepted', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'submission statement accepted',
'view.php?id=' . $assign->get_course_module()->id,
get_string('submissionstatementacceptedlog',
'mod_assign',
fullname($this->students[0])),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
// Enable the online text submission plugin.
$submissionplugins = $assign->get_submission_plugins();
foreach ($submissionplugins as $plugin) {
if ($plugin->get_type() === 'onlinetext') {
$plugin->enable();
break;
}
}
// Create the data we want to pass to the save_submission function.
$data = new stdClass();
$data->onlinetext_editor = array(
'text' => 'Online text',
'format' => FORMAT_HTML,
'itemid' => file_get_unused_draft_itemid()
);
$data->submissionstatement = 'We are the Borg. You will be assimilated. Resistance is futile. - do you agree
to these terms?';
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->save_submission($data, $notices);
$events = $sink->get_events();
$event = $events[2];
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\statement_accepted', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the batch_set_workflow_state_viewed event.
*/
public function test_batch_set_workflow_state_viewed() {
$assign = $this->create_instance();
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->testable_view_batch_set_workflow_state();
$events = $sink->get_events();
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\batch_set_workflow_state_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view batch set marking workflow state',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewbatchsetmarkingworkflowstate', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the batch_set_marker_allocation_viewed event.
*/
public function test_batch_set_marker_allocation_viewed() {
$assign = $this->create_instance();
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->testable_view_batch_markingallocation();
$events = $sink->get_events();
$event = reset($events);
// Check that the event contains the expected values.
$this->assertInstanceOf('\mod_assign\event\batch_set_marker_allocation_viewed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$expected = array(
$assign->get_course()->id,
'assign',
'view batch set marker allocation',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewbatchmarkingallocation', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
}
+17
View File
@@ -46,3 +46,20 @@ class submission_created extends \mod_assign\event\submission_created {
class submission_updated extends \mod_assign\event\submission_updated {
}
/**
* mod_assign test class for event base.
*
* @package mod_assign
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class nothing_happened extends \mod_assign\event\base {
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
public static function get_name() {
return 'Nothing happened';
}
}
-319
View File
@@ -1147,133 +1147,7 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
$this->assertNotEquals(true, strpos($output, $this->students[0]->lastname));
}
public function test_extension_granted_event() {
$this->setUser($this->editingteachers[0]);
$tomorrow = time() + 24*60*60;
$yesterday = time() - 24*60*60;
$assign = $this->create_instance(array('duedate' => $yesterday, 'cutoffdate' => $yesterday));
$sink = $this->redirectEvents();
$assign->testable_save_user_extension($this->students[0]->id, $tomorrow);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\extension_granted', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grant extension',
'view.php?id=' . $assign->get_course_module()->id,
$this->students[0]->id,
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
public function test_submission_locked_event() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->lock_submission($this->students[0]->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_locked', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'lock submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('locksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_identities_revealed_event() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance(array('blindmarking'=>1));
$sink = $this->redirectEvents();
$assign->reveal_identities();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\identities_revealed', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$expected = array(
$assign->get_course()->id,
'assign',
'reveal identities',
'view.php?id=' . $assign->get_course_module()->id,
get_string('revealidentities', 'assign'),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_status_updated_event() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$assign->testable_update_submission($submission, $this->students[0]->id, true, false);
$sink = $this->redirectEvents();
$assign->revert_to_draft($this->students[0]->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_status_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals(ASSIGN_SUBMISSION_STATUS_DRAFT, $event->other['newstatus']);
$expected = array(
$assign->get_course()->id,
'assign',
'revert submission to draft',
'view.php?id=' . $assign->get_course_module()->id,
get_string('reverttodraftforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_teacher_submit_for_student() {
global $PAGE;
@@ -1359,199 +1233,6 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
$sink->close();
}
public function test_marker_updated_event() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->testable_process_set_batch_marking_allocation($this->students[0]->id, $this->teachers[0]->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\marker_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals($this->teachers[0]->id, $event->other['markerid']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking allocation',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkerallocationforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'marker' => fullname($this->teachers[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_workflow_state_updated_event() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->testable_process_set_batch_marking_workflow_state($this->students[0]->id, ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\workflow_state_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals(ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW, $event->other['newstate']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking workflow state',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW)),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_duplicated_event() {
$this->setUser($this->students[0]);
$assign = $this->create_instance();
$submission1 = $assign->get_user_submission($this->students[0]->id, true, 0);
$submission2 = $assign->get_user_submission($this->students[0]->id, true, 1);
$submission2->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
$assign->testable_update_submission($submission2, $this->students[0]->id, time(), $assign->get_instance()->teamsubmission);
$sink = $this->redirectEvents();
$notices = null;
$assign->copy_previous_attempt($notices);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_duplicated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission2->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->userid);
$submission2->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
$expected = array(
$assign->get_course()->id,
'assign',
'submissioncopied',
'view.php?id=' . $assign->get_course_module()->id,
$assign->testable_format_submission_for_log($submission2),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
public function test_submission_unlocked_event() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$sink = $this->redirectEvents();
$assign->unlock_submission($this->students[0]->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_unlocked', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'unlock submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('unlocksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_graded_event() {
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
// Test apply_grade_to_user.
$sink = $this->redirectEvents();
$data = new stdClass();
$data->grade = '50.0';
$assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
$grade = $assign->get_user_grade($this->students[0]->id, false, 0);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grade submission',
'view.php?id=' . $assign->get_course_module()->id,
$assign->format_grade_for_log($grade),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Test process_save_quick_grades.
$sink = $this->redirectEvents();
$data = array(
'grademodified_' . $this->students[0]->id => time(),
'quickgrade_' . $this->students[0]->id => '60.0'
);
$assign->testable_process_save_quick_grades($data);
$grade = $assign->get_user_grade($this->students[0]->id, false);
$this->assertEquals('60.0', $grade->grade);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grade submission',
'view.php?id=' . $assign->get_course_module()->id,
$assign->format_grade_for_log($grade),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
}
public function test_disable_submit_after_cutoff_date() {
global $PAGE;