Skip to content

Commit

Permalink
Merge branch 'MDL-71835' of git://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdef committed Aug 4, 2021
2 parents 4bd6f39 + 91b5e41 commit 6d0a49f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions report/log/classes/table_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,30 @@ public function col_course($event) {
* @return string|false
*/
protected function get_user_fullname($userid) {
global $DB;

if (empty($userid)) {
return false;
}

if (!empty($this->userfullnames[$userid])) {
return $this->userfullnames[$userid];
// Check if we already have this users' fullname.
$userfullname = $this->userfullnames[$userid] ?? null;
if (!empty($userfullname)) {
return $userfullname;
}

// We already looked for the user and it does not exist.
if ($this->userfullnames[$userid] === false) {
if ($userfullname === false) {
return false;
}

// If we reach that point new users logs have been generated since the last users db query.
list($usql, $uparams) = $DB->get_in_or_equal($userid);
$userfieldsapi = \core_user\fields::for_name();
$sql = "SELECT id," . $userfieldsapi->get_sql('', false, '', '', false)->selects .
" FROM {user} WHERE id " . $usql;
if (!$user = $DB->get_records_sql($sql, $uparams)) {
return false;
$fields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
if ($user = \core_user::get_user($userid, $fields)) {
$this->userfullnames[$userid] = fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context()));
} else {
$this->userfullnames[$userid] = false;
}

$this->userfullnames[$userid] = fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context()));
return $this->userfullnames[$userid];
}

Expand Down

0 comments on commit 6d0a49f

Please sign in to comment.