MDL-41101 use snapshots for submissions and grades in assign events
This commit is contained in:
@@ -41,14 +41,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class assessable_submitted extends base {
|
||||
/** @var \stdClass */
|
||||
protected $submission;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
*/
|
||||
protected static $preventcreatecall = true;
|
||||
|
||||
/**
|
||||
* Create instance of event.
|
||||
*
|
||||
@@ -67,31 +59,13 @@ class assessable_submitted extends base {
|
||||
'submission_editable' => $editable,
|
||||
),
|
||||
);
|
||||
self::$preventcreatecall = false;
|
||||
/** @var assessable_submitted $event */
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->set_assign($assign);
|
||||
$event->submission = $submission;
|
||||
$event->add_record_snapshot('assign_submission', $submission);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get submission instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_submission() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_submission() is intended for event observers only');
|
||||
}
|
||||
return $this->submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -152,7 +126,8 @@ class assessable_submitted extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$this->set_legacy_logdata('submit for grading', $this->assign->format_submission_for_log($this->submission));
|
||||
$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();
|
||||
}
|
||||
|
||||
@@ -163,10 +138,6 @@ class assessable_submitted extends base {
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (self::$preventcreatecall) {
|
||||
throw new \coding_exception('cannot call assessable_submitted::create() directly, use assessable_submitted::create_from_submission() instead.');
|
||||
}
|
||||
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->other['submission_editable'])) {
|
||||
|
||||
@@ -41,6 +41,28 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @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.
|
||||
|
||||
@@ -41,14 +41,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class feedback_viewed extends base {
|
||||
/** @var \stdClass */
|
||||
protected $grade;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
*/
|
||||
protected static $preventcreatecall = true;
|
||||
|
||||
/**
|
||||
* Create instance of event.
|
||||
*
|
||||
@@ -65,29 +57,13 @@ class feedback_viewed extends base {
|
||||
'assignid' => $assign->get_instance()->id,
|
||||
),
|
||||
);
|
||||
self::$preventcreatecall = false;
|
||||
/** @var feedback_viewed $event */
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->set_assign($assign);
|
||||
$event->grade = $grade;
|
||||
$event->add_record_snapshot('assign_grades', $grade);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get grade instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_grade() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_grade() is intended for event observers only');
|
||||
}
|
||||
return $this->grade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -122,7 +98,7 @@ class feedback_viewed extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$logmessage = get_string('viewfeedbackforuser', 'assign', $this->grade->userid);
|
||||
$logmessage = get_string('viewfeedbackforuser', 'assign', $this->relateduserid);
|
||||
$this->set_legacy_logdata('view feedback', $logmessage);
|
||||
return parent::get_legacy_logdata();
|
||||
}
|
||||
@@ -133,10 +109,6 @@ class feedback_viewed extends base {
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (self::$preventcreatecall) {
|
||||
throw new \coding_exception('cannot call feedback_viewed::create() directly, use feedback_viewed::create_from_grade() instead.');
|
||||
}
|
||||
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->relateduserid)) {
|
||||
|
||||
@@ -35,8 +35,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class statement_accepted extends base {
|
||||
/** @var \stdClass */
|
||||
protected $submission;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -62,26 +60,10 @@ class statement_accepted extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->set_assign($assign);
|
||||
$event->submission = $submission;
|
||||
$event->add_record_snapshot('assign_submission', $submission);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get submission instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_submission() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_submission() is intended for event observers only');
|
||||
}
|
||||
return $this->submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
|
||||
@@ -35,8 +35,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class submission_duplicated extends base {
|
||||
/** @var \stdClass */
|
||||
protected $submission;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -62,26 +60,10 @@ class submission_duplicated extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->set_assign($assign);
|
||||
$event->submission = $submission;
|
||||
$event->add_record_snapshot('assign_submission', $submission);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get submission instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_submission() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_submission() is intended for event observers only');
|
||||
}
|
||||
return $this->submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -117,7 +99,8 @@ class submission_duplicated extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$this->set_legacy_logdata('submissioncopied', $this->assign->format_submission_for_log($this->submission));
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class submission_graded extends base {
|
||||
/** @var \stdClass */
|
||||
protected $grade;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -63,26 +61,10 @@ class submission_graded extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->set_assign($assign);
|
||||
$event->grade = $grade;
|
||||
$event->add_record_snapshot('assign_grades', $grade);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get grade instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_grade() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_grade() is intended for event observers only');
|
||||
}
|
||||
return $this->grade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -118,7 +100,8 @@ class submission_graded extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$this->set_legacy_logdata('grade submission', $this->assign->format_grade_for_log($this->grade));
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,14 +41,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class submission_status_updated extends base {
|
||||
/** @var \stdClass */
|
||||
protected $submission;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
*/
|
||||
protected static $preventcreatecall = true;
|
||||
|
||||
/**
|
||||
* Create instance of event.
|
||||
*
|
||||
@@ -67,31 +59,13 @@ class submission_status_updated extends base {
|
||||
'newstatus' => $submission->status
|
||||
)
|
||||
);
|
||||
self::$preventcreatecall = false;
|
||||
/** @var submission_status_updated $event */
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->set_assign($assign);
|
||||
$event->submission = $submission;
|
||||
$event->add_record_snapshot('assign_submission', $submission);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get submission instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_submission() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_submission() is intended for event observers only');
|
||||
}
|
||||
return $this->submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -127,9 +101,8 @@ class submission_status_updated extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
global $DB;
|
||||
|
||||
$user = $DB->get_record('user', array('id' => $this->submission->userid), '*', MUST_EXIST);
|
||||
$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();
|
||||
@@ -141,10 +114,6 @@ class submission_status_updated extends base {
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (self::$preventcreatecall) {
|
||||
throw new \coding_exception('cannot call submission_status_updated::create() directly, use submission_status_updated::create_from_submission() instead.');
|
||||
}
|
||||
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->other['newstatus'])) {
|
||||
|
||||
@@ -41,14 +41,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class submission_viewed extends base {
|
||||
/** @var \stdClass */
|
||||
protected $submission;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
*/
|
||||
protected static $preventcreatecall = true;
|
||||
|
||||
/**
|
||||
* Create instance of event.
|
||||
*
|
||||
@@ -65,29 +57,13 @@ class submission_viewed extends base {
|
||||
'assignid' => $assign->get_instance()->id,
|
||||
),
|
||||
);
|
||||
self::$preventcreatecall = false;
|
||||
/** @var submission_viewed $event */
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->set_assign($assign);
|
||||
$event->submission = $submission;
|
||||
$event->add_record_snapshot('assign_submission', $submission);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get submission instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_submission() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_submission() is intended for event observers only');
|
||||
}
|
||||
return $this->submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -122,7 +98,7 @@ class submission_viewed extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$logmessage = get_string('viewsubmissionforuser', 'assign', $this->submission->userid);
|
||||
$logmessage = get_string('viewsubmissionforuser', 'assign', $this->relateduserid);
|
||||
$this->set_legacy_logdata('view submission', $logmessage);
|
||||
return parent::get_legacy_logdata();
|
||||
}
|
||||
@@ -133,10 +109,6 @@ class submission_viewed extends base {
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (self::$preventcreatecall) {
|
||||
throw new \coding_exception('cannot call submission_viewed::create() directly, use submission_viewed::create_from_submission() instead.');
|
||||
}
|
||||
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->relateduserid)) {
|
||||
|
||||
@@ -194,13 +194,7 @@ class assign_feedback_offline extends assign_feedback_plugin {
|
||||
'text'=>$newvalue));
|
||||
|
||||
// Trigger event for updating the feedback.
|
||||
$event = \mod_assign\event\feedback_updated::create(array(
|
||||
'relateduserid' => $user->id,
|
||||
'context' => $this->assignment->get_context(),
|
||||
'other' => array(
|
||||
'assignid' => $this->assignment->get_instance()->id
|
||||
)
|
||||
));
|
||||
$event = \mod_assign\event\feedback_updated::create_from_grade($this->assignment, $grade);
|
||||
$event->set_legacy_logdata('save grading feedback', $logdesc);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
@@ -2012,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;
|
||||
}
|
||||
@@ -2616,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;
|
||||
}
|
||||
@@ -5284,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
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -192,6 +192,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 {
|
||||
@@ -205,6 +206,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user