Commit 5e72715e authored by sam marshall's avatar sam marshall
Browse files

MDL-71099 Lib: Move new user_fields class from core to core_user

This class would belong more appropriately within the 'user' API
(core_user) instead of within the 'core' API, since it is
directly related to user data.

Since the class has only just been added to Moodle, now is a good
time to move it.
parent d65ed58e
......@@ -293,7 +293,7 @@ class grade_report_grader extends grade_report {
}
if ($errorstr) {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$userfields = 'id, ' . $userfieldsapi->get_sql('', false, '', '', false)->selects;
$user = $DB->get_record('user', array('id' => $userid), $userfields);
$gradestr = new stdClass();
......@@ -439,7 +439,7 @@ class grade_report_grader extends grade_report {
// Fields we need from the user table.
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($this->context, false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
// We want to query both the current context and parent contexts.
......@@ -661,7 +661,7 @@ class grade_report_grader extends grade_report {
$strgrade = $this->get_lang_string('grade');
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core\user_fields::get_identity_fields($this->context, false);
$extrafields = \core_user\fields::get_identity_fields($this->context, false);
$arrows = $this->get_sort_arrows($extrafields);
......@@ -1946,7 +1946,7 @@ class grade_report_grader extends grade_report {
}
$arrows['studentname'] = '';
$requirednames = order_in_string(\core\user_fields::get_name_fields(), $nameformat);
$requirednames = order_in_string(\core_user\fields::get_name_fields(), $nameformat);
if (!empty($requirednames)) {
foreach ($requirednames as $name) {
$arrows['studentname'] .= html_writer::link(
......@@ -1963,7 +1963,7 @@ class grade_report_grader extends grade_report {
foreach ($extrafields as $field) {
$fieldlink = html_writer::link(new moodle_url($this->baseurl,
array('sortitemid' => $field)), \core\user_fields::get_display_name($field));
array('sortitemid' => $field)), \core_user\fields::get_display_name($field));
$arrows[$field] = $fieldlink;
if ($field == $this->sortitemid) {
......
......@@ -132,7 +132,7 @@ class helper {
// Fields we need from the user table.
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core\user_fields::get_identity_fields($context, false);
$extrafields = \core_user\fields::get_identity_fields($context, false);
$params = array();
if (!empty($search)) {
list($filtersql, $params) = users_search_sql($search, 'u', true, $extrafields);
......@@ -141,7 +141,7 @@ class helper {
$filtersql = '';
}
$userfieldsapi = \core\user_fields::for_userpic()->including(...(array_merge($extrafields, ['username'])));
$userfieldsapi = \core_user\fields::for_userpic()->including(...(array_merge($extrafields, ['username'])));
$ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if ($count) {
$select = "SELECT COUNT(DISTINCT u.id) ";
......@@ -203,7 +203,7 @@ class helper {
$groupwheresql = " AND gm.groupid $insql ";
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT u.id, $ufields
FROM {user} u
......
......@@ -141,7 +141,7 @@ class tablelog extends \table_sql implements \renderable {
*/
protected function define_table_columns() {
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core\user_fields::get_identity_fields($this->context, false);
$extrafields = \core_user\fields::get_identity_fields($this->context, false);
// Define headers and columns.
$cols = array(
......@@ -396,11 +396,11 @@ class tablelog extends \table_sql implements \renderable {
// Add extra user fields that we need for the graded user.
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core\user_fields::get_identity_fields($this->context, false);
$extrafields = \core_user\fields::get_identity_fields($this->context, false);
foreach ($extrafields as $field) {
$fields .= 'u.' . $field . ', ';
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$gradeduserfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$fields .= $gradeduserfields . ', ';
$groupby = $fields;
......
......@@ -52,7 +52,7 @@ $outcome->response = array('users' => array());
$outcome->response['totalusers'] = \gradereport_history\helper::get_users_count($context, $search);;
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core\user_fields::get_identity_fields($context, false);
$extrafields = \core_user\fields::get_identity_fields($context, false);
$useroptions = array('link' => false, 'visibletoscreenreaders' => false);
// Format the user record.
......
......@@ -100,7 +100,7 @@ if ($editform->is_cancelled()) {
$onlyactive = !empty($data->includeonlyactiveenrol) || !has_capability('moodle/course:viewsuspendedusers', $context);
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core\user_fields::get_identity_fields($context, false);
$extrafields = \core_user\fields::get_identity_fields($context, false);
$users = groups_get_potential_members($data->courseid, $data->roleid, $source, $orderby, !empty($data->notingroup),
$onlyactive, $extrafields);
$usercnt = count($users);
......
......@@ -82,9 +82,9 @@ switch ($action) {
$roles = array();
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($context, false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity($context, false)->with_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$extrafields = $userfieldsapi->get_required_fields([\core\user_fields::PURPOSE_IDENTITY]);
$extrafields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
if ($groupmemberroles = groups_get_members_by_role($groupids[0], $courseid,
'u.id, ' . $userfields)) {
......@@ -206,9 +206,9 @@ if ($groups) {
$members = array();
if ($singlegroup) {
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($context, false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity($context, false)->with_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$extrafields = $userfieldsapi->get_required_fields([\core\user_fields::PURPOSE_IDENTITY]);
$extrafields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
if ($groupmemberroles = groups_get_members_by_role(reset($groupids), $courseid,
'u.id, ' . $userfields)) {
......
......@@ -848,7 +848,7 @@ function groups_get_potential_members($courseid, $roleid = null, $source = null,
}
}
$userfieldsapi = \core\user_fields::for_userpic()->including(...$extrafields);
$userfieldsapi = \core_user\fields::for_userpic()->including(...$extrafields);
$allusernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT DISTINCT u.id, u.username, $allusernamefields, u.idnumber
FROM {user} u
......
......@@ -111,9 +111,9 @@ if ($groupingid) {
list($sort, $sortparams) = users_order_by_sql('u');
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($context, false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity($context, false)->with_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$extrafields = $userfieldsapi->get_required_fields([\core\user_fields::PURPOSE_IDENTITY]);
$extrafields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
$allnames = 'u.id, ' . $userfields;
$sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, $allnames, u.idnumber, u.username
......
......@@ -3923,7 +3923,7 @@ function get_role_users($roleid, context $context, $parent = false, $fields = ''
global $DB;
if (empty($fields)) {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$fields = 'u.id, u.confirmed, u.username, '. $allnames . ', ' .
'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '.
......
......@@ -4311,7 +4311,7 @@ class admin_setting_users_with_capability extends admin_setting_configmultiselec
'This is unexpected, and a problem because there is no way to pass these ' .
'parameters to get_users_by_capability. See MDL-34657.');
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$userfields = 'u.id, u.username, ' . $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$users = get_users_by_capability(context_system::instance(), $this->capability, $userfields, $sort);
$this->choices = array(
......
......@@ -1102,7 +1102,7 @@ function signup_setup_new_user($user) {
$user->secret = random_string(15);
$user->auth = $CFG->registerauth;
// Initialize alternate name fields to empty strings.
$namefields = array_diff(\core\user_fields::get_name_fields(), useredit_get_required_name_fields());
$namefields = array_diff(\core_user\fields::get_name_fields(), useredit_get_required_name_fields());
foreach ($namefields as $namefield) {
$user->$namefield = '';
}
......
......@@ -143,7 +143,7 @@ function badges_notify_badge_award(badge $badge, $userid, $issued, $filepathhash
$userfrom = new stdClass();
$userfrom->id = $admin->id;
$userfrom->email = !empty($CFG->badges_defaultissuercontact) ? $CFG->badges_defaultissuercontact : $admin->email;
foreach (\core\user_fields::get_name_fields() as $addname) {
foreach (\core_user\fields::get_name_fields() as $addname) {
$userfrom->$addname = !empty($CFG->badges_defaultissuername) ? '' : $admin->$addname;
}
$userfrom->firstname = !empty($CFG->badges_defaultissuername) ? $CFG->badges_defaultissuername : $admin->firstname;
......
......@@ -66,7 +66,7 @@ class riskadmin extends check {
*/
public function get_result(): result {
global $DB, $CFG;
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT $userfields
FROM {user} u
......
......@@ -165,7 +165,7 @@ class riskbackup_result extends \core\check\result {
'context1' => CONTEXT_COURSE,
'context2' => CONTEXT_COURSE,
];
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$rs = $DB->get_recordset_sql("
SELECT DISTINCT $userfields,
......
......@@ -90,7 +90,7 @@ class riskxss_result extends \core\check\result {
global $CFG, $DB;
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$users = $DB->get_records_sql("SELECT DISTINCT $userfields $this->sqlfrom", $this->params);
foreach ($users as $uid => $user) {
......
......@@ -115,7 +115,7 @@ class send_failed_login_notifications_task extends scheduled_task {
// Now, select all the login error logged records belonging to the ips and infos
// since lastnotifyfailure, that we have stored in the cache_flags table.
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT * FROM (
SELECT l.*, u.username, $namefields
......
......@@ -47,7 +47,7 @@ class send_new_user_passwords_task extends scheduled_task {
// Generate new password emails for users - ppl expect these generated asap.
if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
mtrace('Creating passwords for new users...');
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$usernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.auth, u.deleted,
u.suspended, u.emailstop, u.mnethostid, u.mailformat,
......
......@@ -252,10 +252,10 @@ class core_user {
$extraparams = [];
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity(null, false)->with_userpic()->with_name()
$userfieldsapi = \core_user\fields::for_identity(null, false)->with_userpic()->with_name()
->including('username', 'deleted');
$selectfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$extra = $userfieldsapi->get_required_fields([\core\user_fields::PURPOSE_IDENTITY]);
$extra = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
$index = 1;
foreach ($extra as $fieldname) {
......
......@@ -1295,7 +1295,7 @@ class completion_info {
'moodle/course:isincompletionreports', $groupid, true);
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($extracontext, false)->with_name();
$userfieldsapi = \core_user\fields::for_identity($extracontext, false)->with_name();
$allusernames = $userfieldsapi->get_sql('u')->selects;
$sql = 'SELECT u.id, u.idnumber ' . $allusernames;
$sql .= ' FROM (' . $enrolledsql . ') eu JOIN {user} u ON u.id = eu.id';
......
......@@ -369,7 +369,7 @@ function users_order_by_sql($usertablealias = '', $search = null, context $conte
$paramkey++;
// TODO Does not support custom user profile fields (MDL-70456).
$fieldstocheck = array_merge(array('firstname', 'lastname'), \core\user_fields::get_identity_fields($context, false));
$fieldstocheck = array_merge(array('firstname', 'lastname'), \core_user\fields::get_identity_fields($context, false));
foreach ($fieldstocheck as $key => $field) {
$exactconditions[] = 'LOWER(' . $tableprefix . $field . ') = LOWER(:' . $paramkey . ')';
$params[$paramkey] = $search;
......@@ -517,7 +517,7 @@ function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperp
// If a context is specified, get extra user fields that the current user
// is supposed to see, otherwise just get the name fields.
$userfields = \core\user_fields::for_name();
$userfields = \core_user\fields::for_name();
if ($extracontext) {
$userfields->with_identity($extracontext, true);
}
......
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