Commit 3f003455 authored by sam marshall's avatar sam marshall
Browse files

MDL-45242 Lib: Replace direct references to ->showuseridentity

parent 60a1b159
......@@ -878,10 +878,8 @@ class external extends external_api {
list($filtercapsql, $filtercapparams) = api::filter_users_with_capability_on_user_context_sql($cap,
$USER->id, SQL_PARAMS_NAMED);
$extrasearchfields = array();
if (!empty($CFG->showuseridentity) && has_capability('moodle/site:viewuseridentity', $context)) {
$extrasearchfields = explode(',', $CFG->showuseridentity);
}
// TODO Does not support custom user profile fields (MDL-70456).
$extrasearchfields = \core\user_fields::get_identity_fields($context, false);
$fields = \user_picture::fields('u', $extrasearchfields);
list($wheresql, $whereparams) = users_search_sql($query, 'u', true, $extrasearchfields);
......
......@@ -251,12 +251,8 @@ class core_user {
$extrasql = '';
$extraparams = [];
if (empty($CFG->showuseridentity)) {
// Explode gives wrong result with empty string.
$extra = [];
} else {
$extra = explode(',', $CFG->showuseridentity);
}
// TODO Does not support custom user profile fields (MDL-70456).
$extra = \core\user_fields::get_identity_fields(null, false);
// We need the username just to skip guests.
$extrafieldlist = $extra;
......
......@@ -3171,9 +3171,10 @@ function user_get_participants_sql($courseid, $groupid = 0, $accesssince = 0, $r
}
$conditions[] = $idnumber;
if (!empty($CFG->showuseridentity)) {
// TODO Does not support custom user profile fields (MDL-70456).
$extrasearchfields = \core\user_fields::get_identity_fields($context, false);
if (!empty($extrasearchfields)) {
// Search all user identify fields.
$extrasearchfields = explode(',', $CFG->showuseridentity);
foreach ($extrasearchfields as $extrasearchfield) {
if (in_array($extrasearchfield, ['email', 'idnumber', 'country'])) {
// Already covered above. Search by country not supported.
......
......@@ -125,12 +125,8 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,
} else {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
}
$canviewuseridentity = has_capability('moodle/site:viewuseridentity', $courseorusercontext);
if ($canviewuseridentity) {
$identityfields = array_flip(explode(',', $CFG->showuseridentity));
} else {
$identityfields = array();
}
// TODO Does not support custom user profile fields (MDL-70456).
$identityfields = array_flip(\core\user_fields::get_identity_fields($courseorusercontext, false));
if (is_mnet_remote_user($user)) {
$sql = "SELECT h.id, h.name, h.wwwroot,
......@@ -156,7 +152,7 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,
or ($user->maildisplay == core_user::MAILDISPLAY_COURSE_MEMBERS_ONLY and enrol_sharing_course($user, $USER))
or has_capability('moodle/course:useremail', $courseorusercontext) // TODO: Deprecate/remove for MDL-37479.
))
or (isset($identityfields['email']) and $canviewuseridentity)
or (isset($identityfields['email']))
) {
$maildisplay = obfuscate_mailto($user->email, '');
if ($iscurrentuser) {
......
......@@ -168,7 +168,8 @@ class grading_app implements templatable, renderable {
$export->rarrow = $output->rarrow();
$export->larrow = $output->larrow();
// List of identity fields to display (the user info will not contain any fields the user cannot view anyway).
$export->showuseridentity = $CFG->showuseridentity;
// TODO Does not support custom user profile fields (MDL-70456).
$export->showuseridentity = implode(',', \core\user_fields::get_identity_fields(null, false));
$export->currentuserid = $USER->id;
$helpicon = new \help_icon('sendstudentnotifications', 'assign');
$export->helpicon = $helpicon->export_for_template($output);
......
......@@ -48,7 +48,8 @@ class user_summary_exporter extends \core\external\exporter {
$profileurl = (new moodle_url('/user/profile.php', array('id' => $this->data->id)))->out(false);
$identityfields = array_flip(explode(',', $CFG->showuseridentity));
// TODO Does not support custom user profile fields (MDL-70456).
$identityfields = array_flip(\core\user_fields::get_identity_fields(null, false));
$data = $this->data;
foreach ($identityfields as $field => $index) {
if (!empty($data->$field)) {
......
......@@ -962,30 +962,29 @@ class participants_search {
$conditions[] = $idnumber;
if (!empty($CFG->showuseridentity)) {
// Search all user identify fields.
$extrasearchfields = explode(',', $CFG->showuseridentity);
foreach ($extrasearchfields as $extrasearchfield) {
if (in_array($extrasearchfield, ['email', 'idnumber', 'country'])) {
// Already covered above. Search by country not supported.
continue;
}
$param = $searchkey3 . $extrasearchfield;
$condition = $DB->sql_like($extrasearchfield, ':' . $param, false, false);
$params[$param] = "%$keyword%";
// Search all user identify fields.
// TODO Does not support custom user profile fields (MDL-70456).
$extrasearchfields = \core\user_fields::get_identity_fields(null, false);
foreach ($extrasearchfields as $extrasearchfield) {
if (in_array($extrasearchfield, ['email', 'idnumber', 'country'])) {
// Already covered above. Search by country not supported.
continue;
}
$param = $searchkey3 . $extrasearchfield;
$condition = $DB->sql_like($extrasearchfield, ':' . $param, false, false);
$params[$param] = "%$keyword%";
if ($notjoin) {
$condition = "($extrasearchfield IS NOT NULL AND {$condition})";
}
if ($notjoin) {
$condition = "($extrasearchfield IS NOT NULL AND {$condition})";
}
if (!in_array($extrasearchfield, $this->userfields)) {
// User cannot see this field, but allow match if their own account.
$userid3 = 'userid' . $index . '3' . $extrasearchfield;
$condition = "(". $condition . " AND u.id = :$userid3)";
$params[$userid3] = $USER->id;
}
$conditions[] = $condition;
if (!in_array($extrasearchfield, $this->userfields)) {
// User cannot see this field, but allow match if their own account.
$userid3 = 'userid' . $index . '3' . $extrasearchfield;
$condition = "(". $condition . " AND u.id = :$userid3)";
$params[$userid3] = $USER->id;
}
$conditions[] = $condition;
}
// Search by middlename.
......
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