MDL-80087 Questions: warn if preload_all_step_users was not called
Co-authored-by: Tim Hunt <[email protected]>
This commit is contained in:
co-authored by
Tim Hunt
parent
45ad566de9
commit
e35eb6b9eb
@@ -87,10 +87,10 @@ class question_attempt_step {
|
||||
*/
|
||||
private $fraction = null;
|
||||
|
||||
/** @var integer the timestamp when this step was created. */
|
||||
/** @var int the timestamp when this step was created. */
|
||||
private $timecreated;
|
||||
|
||||
/** @var integer the id of the user resonsible for creating this step. */
|
||||
/** @var int the id of the user responsible for creating this step. */
|
||||
private $userid;
|
||||
|
||||
/** @var array name => value pairs. The submitted data. */
|
||||
@@ -99,7 +99,7 @@ class question_attempt_step {
|
||||
/** @var array name => array of {@see stored_file}s. Caches the contents of file areas. */
|
||||
private $files = array();
|
||||
|
||||
/** @var stdClass User information. */
|
||||
/** @var stdClass|null User information. */
|
||||
private $user = null;
|
||||
|
||||
/**
|
||||
@@ -107,12 +107,12 @@ class question_attempt_step {
|
||||
* normally created by {@see question_attempt} methods like
|
||||
* {@see question_attempt::process_action()}.
|
||||
* @param array $data the submitted data that defines this step.
|
||||
* @param int $timestamp the time to record for the action. (If not given, use now.)
|
||||
* @param int $userid the user to attribute the aciton to. (If not given, use the current user.)
|
||||
* @param int $existingstepid if this step is going to replace an existing step
|
||||
* @param int|null $timecreated the time to record for the action. (If not given, use now.)
|
||||
* @param int|null $userid the user to attribute the aciton to. (If not given, use the current user.)
|
||||
* @param int|null $existingstepid if this step is going to replace an existing step
|
||||
* (for example, during a regrade) this is the id of the previous step we are replacing.
|
||||
*/
|
||||
public function __construct($data = array(), $timecreated = null, $userid = null,
|
||||
public function __construct($data = [], $timecreated = null, $userid = null,
|
||||
$existingstepid = null) {
|
||||
global $USER;
|
||||
|
||||
@@ -196,9 +196,13 @@ class question_attempt_step {
|
||||
/**
|
||||
* Return the full user object.
|
||||
*
|
||||
* @return stdClass Get full user object.
|
||||
* @return null|stdClass Get full user object.
|
||||
*/
|
||||
public function get_user(): stdClass {
|
||||
public function get_user(): ?stdClass {
|
||||
if ($this->user === null) {
|
||||
debugging('Attempt to access the step user before it was initialised. ' .
|
||||
'Did you forget to call question_usage_by_activity::preload_all_step_users() or similar?', DEBUG_DEVELOPER);
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
@@ -208,7 +212,7 @@ class question_attempt_step {
|
||||
* @return string full name of user.
|
||||
*/
|
||||
public function get_user_fullname(): string {
|
||||
return fullname($this->user);
|
||||
return fullname($this->get_user());
|
||||
}
|
||||
|
||||
/** @return int the timestamp when this step was created. */
|
||||
|
||||
Reference in New Issue
Block a user