Commit 48a7b182 authored by Jerome Mouneyrac's avatar Jerome Mouneyrac Committed by Dan Poltawski
Browse files

MDL-33869 user_get_user_details: add support for 'Show user identity' fields set by administrator

parent 3a3f3b22
...@@ -237,6 +237,8 @@ function user_get_user_details($user, $course = null, array $userfields = array( ...@@ -237,6 +237,8 @@ function user_get_user_details($user, $course = null, array $userfields = array(
$currentuser = ($user->id == $USER->id); $currentuser = ($user->id == $USER->id);
$isadmin = is_siteadmin($USER); $isadmin = is_siteadmin($USER);
$showuseridentityfields = get_extra_user_fields($context);
if (!empty($course)) { if (!empty($course)) {
$canviewhiddenuserfields = has_capability('moodle/course:viewhiddenuserfields', $context); $canviewhiddenuserfields = has_capability('moodle/course:viewhiddenuserfields', $context);
} else { } else {
...@@ -319,16 +321,19 @@ function user_get_user_details($user, $course = null, array $userfields = array( ...@@ -319,16 +321,19 @@ function user_get_user_details($user, $course = null, array $userfields = array(
if ($user->address && in_array('address', $userfields)) { if ($user->address && in_array('address', $userfields)) {
$userdetails['address'] = $user->address; $userdetails['address'] = $user->address;
} }
if ($user->phone1 && in_array('phone1', $userfields)) {
$userdetails['phone1'] = $user->phone1;
}
if ($user->phone2 && in_array('phone2', $userfields)) {
$userdetails['phone2'] = $user->phone2;
}
} else { } else {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
} }
if ($user->phone1 && in_array('phone1', $userfields) &&
(isset($showuseridentityfields['phone1']) or $canviewhiddenuserfields)) {
$userdetails['phone1'] = $user->phone1;
}
if ($user->phone2 && in_array('phone2', $userfields) &&
(isset($showuseridentityfields['phone2']) or $canviewhiddenuserfields)) {
$userdetails['phone2'] = $user->phone2;
}
if (isset($user->description) && (!isset($hiddenfields['description']) or $isadmin)) { if (isset($user->description) && (!isset($hiddenfields['description']) or $isadmin)) {
if (!$cannotviewdescription) { if (!$cannotviewdescription) {
...@@ -393,6 +398,7 @@ function user_get_user_details($user, $course = null, array $userfields = array( ...@@ -393,6 +398,7 @@ function user_get_user_details($user, $course = null, array $userfields = array(
if (in_array('email', $userfields) && ($isadmin // The admin is allowed the users email if (in_array('email', $userfields) && ($isadmin // The admin is allowed the users email
or $currentuser // Of course the current user is as well or $currentuser // Of course the current user is as well
or $canviewuseremail // this is a capability in course context, it will be false in usercontext or $canviewuseremail // this is a capability in course context, it will be false in usercontext
or isset($showuseridentityfields['email'])
or $user->maildisplay == 1 or $user->maildisplay == 1
or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER)))) { or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER)))) {
$userdetails['email'] = $user->email; $userdetails['email'] = $user->email;
...@@ -406,13 +412,17 @@ function user_get_user_details($user, $course = null, array $userfields = array( ...@@ -406,13 +412,17 @@ function user_get_user_details($user, $course = null, array $userfields = array(
} }
//Departement/Institution/Idnumber are not displayed on any profile, however you can get them from editing profile. //Departement/Institution/Idnumber are not displayed on any profile, however you can get them from editing profile.
if ($isadmin or $currentuser) { if ($isadmin or $currentuser or isset($showuseridentityfields['idnumber'])) {
if (in_array('idnumber', $userfields) && $user->idnumber) { if (in_array('idnumber', $userfields) && $user->idnumber) {
$userdetails['idnumber'] = $user->idnumber; $userdetails['idnumber'] = $user->idnumber;
} }
}
if ($isadmin or $currentuser or isset($showuseridentityfields['institution'])) {
if (in_array('institution', $userfields) && $user->institution) { if (in_array('institution', $userfields) && $user->institution) {
$userdetails['institution'] = $user->institution; $userdetails['institution'] = $user->institution;
} }
}
if ($isadmin or $currentuser or isset($showuseridentityfields['department'])) {
if (in_array('department', $userfields) && isset($user->department)) { //isset because it's ok to have department 0 if (in_array('department', $userfields) && isset($user->department)) { //isset because it's ok to have department 0
$userdetails['department'] = $user->department; $userdetails['department'] = $user->department;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment