MDL-41101 use record snapshots for user data in assign events
The problem is that event->get_user() would be very confusing because it is mostly related user.
This commit is contained in:
@@ -43,8 +43,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class grading_form_viewed extends base {
|
||||
/** @var \assign */
|
||||
protected $assign;
|
||||
/** @var \stdClass */
|
||||
protected $user;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -71,7 +69,7 @@ class grading_form_viewed extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->assign = $assign;
|
||||
$event->user = $user;
|
||||
$event->add_record_snapshot('user', $user);
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -89,20 +87,6 @@ class grading_form_viewed extends base {
|
||||
return $this->assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_user() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_user() is intended for event observers only');
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -136,9 +120,9 @@ class grading_form_viewed extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$msg = new \lang_string('viewgradingformforstudent',
|
||||
'assign',
|
||||
array('id'=>$this->user->id, 'fullname'=>fullname($this->user)));
|
||||
$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();
|
||||
}
|
||||
|
||||
@@ -43,10 +43,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class marker_updated extends base {
|
||||
/** @var \assign */
|
||||
protected $assign;
|
||||
/** @var \stdClass */
|
||||
protected $user;
|
||||
/** @var \stdClass */
|
||||
protected $marker;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -77,8 +73,8 @@ class marker_updated extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->assign = $assign;
|
||||
$event->user = $user;
|
||||
$event->marker = $marker;
|
||||
$event->add_record_snapshot('user', $user);
|
||||
$event->add_record_snapshot('user', $marker);
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -98,38 +94,6 @@ class marker_updated extends base {
|
||||
return $this->assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_user() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_user() is intended for event observers only');
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get marker user instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_marker() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_marker() is intended for event observers only');
|
||||
}
|
||||
return $this->marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -165,7 +129,9 @@ class marker_updated extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$a = array('id' => $this->user->id, 'fullname' => fullname($this->user), 'marker' => fullname($this->marker));
|
||||
$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();
|
||||
|
||||
@@ -43,8 +43,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class submission_form_viewed extends base {
|
||||
/** @var \assign */
|
||||
protected $assign;
|
||||
/** @var \stdClass */
|
||||
protected $user;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -71,7 +69,7 @@ class submission_form_viewed extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->assign = $assign;
|
||||
$event->user = $user;
|
||||
$event->add_record_snapshot('user', $user);
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -89,20 +87,6 @@ class submission_form_viewed extends base {
|
||||
return $this->assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_user() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_user() is intended for event observers only');
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -144,8 +128,8 @@ class submission_form_viewed extends base {
|
||||
if ($this->relateduserid == $this->userid) {
|
||||
$title = get_string('editsubmission', 'assign');
|
||||
} else {
|
||||
$name = $this->fullname($this->user);
|
||||
$title = get_string('editsubmissionother', 'assign', $name);
|
||||
$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();
|
||||
|
||||
@@ -37,8 +37,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class submission_locked extends base {
|
||||
/** @var \assign */
|
||||
protected $assign;
|
||||
/** @var \stdClass */
|
||||
protected $user;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -65,7 +63,7 @@ class submission_locked extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->assign = $assign;
|
||||
$event->user = $user;
|
||||
$event->add_record_snapshot('user', $user);
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -85,22 +83,6 @@ class submission_locked extends base {
|
||||
return $this->assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_user() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_user() is intended for event observers only');
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -136,7 +118,8 @@ class submission_locked extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$logmessage = get_string('locksubmissionforstudent', 'assign', array('id' => $this->user->id, 'fullname' => fullname($this->user)));
|
||||
$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();
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class submission_unlocked extends base {
|
||||
/** @var \assign */
|
||||
protected $assign;
|
||||
/** @var \stdClass */
|
||||
protected $user;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -65,7 +63,7 @@ class submission_unlocked extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->assign = $assign;
|
||||
$event->user = $user;
|
||||
$event->add_record_snapshot('user', $user);
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -85,22 +83,6 @@ class submission_unlocked extends base {
|
||||
return $this->assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_user() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_user() is intended for event observers only');
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -136,7 +118,8 @@ class submission_unlocked extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$logmessage = get_string('unlocksubmissionforstudent', 'assign', array('id' => $this->user->id, 'fullname' => fullname($this->user)));
|
||||
$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();
|
||||
}
|
||||
|
||||
@@ -43,8 +43,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class workflow_state_updated extends base {
|
||||
/** @var \assign */
|
||||
protected $assign;
|
||||
/** @var \stdClass */
|
||||
protected $user;
|
||||
/**
|
||||
* Flag for prevention of direct create() call.
|
||||
* @var bool
|
||||
@@ -75,7 +73,7 @@ class workflow_state_updated extends base {
|
||||
$event = self::create($data);
|
||||
self::$preventcreatecall = true;
|
||||
$event->assign = $assign;
|
||||
$event->user = $user;
|
||||
$event->add_record_snapshot('user', $user);
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -95,22 +93,6 @@ class workflow_state_updated extends base {
|
||||
return $this->assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user instance.
|
||||
*
|
||||
* NOTE: to be used from observers only.
|
||||
*
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_user() {
|
||||
if ($this->is_restored()) {
|
||||
throw new \coding_exception('get_user() is intended for event observers only');
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
@@ -146,7 +128,8 @@ class workflow_state_updated extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$a = array('id' => $this->user->id, 'fullname' => fullname($this->user), 'state' => $this->other['newstate']);
|
||||
$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();
|
||||
|
||||
@@ -3263,7 +3263,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);
|
||||
@@ -3274,7 +3274,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user