Skip to content

Commit

Permalink
MDL-41101 use record snapshots for user data in assign events
Browse files Browse the repository at this point in the history
The problem is that event->get_user() would be very confusing
because it is mostly related user.
  • Loading branch information
skodak authored and Petr Skoda committed Apr 17, 2014
1 parent 0e5deb2 commit 31904cc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 140 deletions.
24 changes: 4 additions & 20 deletions mod/assign/classes/event/grading_form_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
class grading_form_viewed extends base {
/** @var \assign */
protected $assign;
/** @var \stdClass */
protected $user;
/**
* Flag for prevention of direct create() call.
* @var bool
Expand All @@ -71,7 +69,7 @@ public static function create_from_user(\assign $assign, \stdClass $user) {
$event = self::create($data);
self::$preventcreatecall = true;
$event->assign = $assign;
$event->user = $user;
$event->add_record_snapshot('user', $user);
return $event;
}

Expand All @@ -89,20 +87,6 @@ public function get_assign() {
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.
*/
Expand Down Expand Up @@ -136,9 +120,9 @@ public function get_description() {
* @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();
}
Expand Down
44 changes: 5 additions & 39 deletions mod/assign/classes/event/marker_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
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
Expand Down Expand Up @@ -77,8 +73,8 @@ public static function create_from_marker(\assign $assign, \stdClass $user, \std
$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;
}

Expand All @@ -98,38 +94,6 @@ public function get_assign() {
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.
*
Expand Down Expand Up @@ -165,7 +129,9 @@ protected function init() {
* @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();
Expand Down
22 changes: 3 additions & 19 deletions mod/assign/classes/event/submission_form_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
class submission_form_viewed extends base {
/** @var \assign */
protected $assign;
/** @var \stdClass */
protected $user;
/**
* Flag for prevention of direct create() call.
* @var bool
Expand All @@ -71,7 +69,7 @@ public static function create_from_user(\assign $assign, \stdClass $user) {
$event = self::create($data);
self::$preventcreatecall = true;
$event->assign = $assign;
$event->user = $user;
$event->add_record_snapshot('user', $user);
return $event;
}

Expand All @@ -89,20 +87,6 @@ public function get_assign() {
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.
*/
Expand Down Expand Up @@ -144,8 +128,8 @@ protected function get_legacy_logdata() {
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();
Expand Down
23 changes: 3 additions & 20 deletions mod/assign/classes/event/submission_locked.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
class submission_locked extends base {
/** @var \assign */
protected $assign;
/** @var \stdClass */
protected $user;
/**
* Flag for prevention of direct create() call.
* @var bool
Expand All @@ -65,7 +63,7 @@ public static function create_from_user(\assign $assign, \stdClass $user) {
$event = self::create($data);
self::$preventcreatecall = true;
$event->assign = $assign;
$event->user = $user;
$event->add_record_snapshot('user', $user);
return $event;
}

Expand All @@ -85,22 +83,6 @@ public function get_assign() {
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.
*
Expand Down Expand Up @@ -136,7 +118,8 @@ protected function init() {
* @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();
}
Expand Down
23 changes: 3 additions & 20 deletions mod/assign/classes/event/submission_unlocked.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
class submission_unlocked extends base {
/** @var \assign */
protected $assign;
/** @var \stdClass */
protected $user;
/**
* Flag for prevention of direct create() call.
* @var bool
Expand All @@ -65,7 +63,7 @@ public static function create_from_user(\assign $assign, \stdClass $user) {
$event = self::create($data);
self::$preventcreatecall = true;
$event->assign = $assign;
$event->user = $user;
$event->add_record_snapshot('user', $user);
return $event;
}

Expand All @@ -85,22 +83,6 @@ public function get_assign() {
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.
*
Expand Down Expand Up @@ -136,7 +118,8 @@ protected function init() {
* @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();
}
Expand Down
23 changes: 3 additions & 20 deletions mod/assign/classes/event/workflow_state_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
class workflow_state_updated extends base {
/** @var \assign */
protected $assign;
/** @var \stdClass */
protected $user;
/**
* Flag for prevention of direct create() call.
* @var bool
Expand Down Expand Up @@ -75,7 +73,7 @@ public static function create_from_user(\assign $assign, \stdClass $user, $state
$event = self::create($data);
self::$preventcreatecall = true;
$event->assign = $assign;
$event->user = $user;
$event->add_record_snapshot('user', $user);
return $event;
}

Expand All @@ -95,22 +93,6 @@ public function get_assign() {
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.
*
Expand Down Expand Up @@ -146,7 +128,8 @@ protected function init() {
* @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();
Expand Down
3 changes: 1 addition & 2 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@ protected function view_edit_submission_page($mform, $notices) {
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);
Expand All @@ -3274,7 +3274,6 @@ protected function view_edit_submission_page($mform, $notices) {
print_error('nopermission');
}

$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
$name = $this->fullname($user);
$title = get_string('editsubmissionother', 'assign', $name);
}
Expand Down

0 comments on commit 31904cc

Please sign in to comment.