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
......@@ -125,7 +125,7 @@ class task_log_table extends \table_sql {
}
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity(\context_system::instance(), false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity(\context_system::instance(), false)->with_userpic();
$userfields = $userfieldsapi->get_sql('u', false, 'user', 'userid2', false)->selects;
$where = '';
......
......@@ -271,7 +271,7 @@ if ($roleid) {
foreach ($assignableroles as $roleid => $notused) {
$roleusers = '';
if (0 < $assigncounts[$roleid] && $assigncounts[$roleid] <= MAX_USERS_TO_LIST_PER_ROLE) {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$userfields = 'u.id, u.username' . $userfieldsapi->get_sql('u')->selects;
$roleusers = get_role_users($roleid, $context, false, $userfields);
if (!empty($roleusers)) {
......
......@@ -127,7 +127,7 @@ class cohort_role_assignments_table extends table_sql {
*/
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(
......@@ -175,7 +175,7 @@ class cohort_role_assignments_table extends table_sql {
// Add extra user fields that we need for the graded user.
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($this->context, false)->with_name();
$userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_name();
$fields .= $userfieldsapi->get_sql('u')->selects;
if ($count) {
......
......@@ -189,7 +189,7 @@ class api {
$dpos = [];
$context = context_system::instance();
foreach ($dporoles as $roleid) {
$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, '.
......
......@@ -700,7 +700,7 @@ class external extends external_api {
self::validate_context($context);
require_capability('tool/dataprivacy:managedatarequests', $context);
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allusernames = $userfieldsapi->get_sql('', false, '', '', false)->selects;
// Exclude admins and guest user.
$excludedusers = array_keys(get_admins()) + [guest_user()->id];
......@@ -708,7 +708,7 @@ class external extends external_api {
$fields = 'id,' . $allusernames;
// 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);
if (!empty($extrafields)) {
$fields .= ',' . implode(',', $extrafields);
}
......
......@@ -187,7 +187,7 @@ class helper {
global $DB;
// Get users that the user has role assignments to.
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allusernames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT u.id, $allusernames
FROM {role_assignments} ra, {context} c, {user} u
......
......@@ -62,7 +62,7 @@ class tool_dataprivacy_data_request_form extends \core\form\persistent {
'valuehtmlcallback' => function($value) {
global $OUTPUT;
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allusernames = $userfieldsapi->get_sql('', false, '', '', false)->selects;
$fields = 'id, email, ' . $allusernames;
$user = \core_user::get_user($value, $fields);
......
......@@ -879,9 +879,9 @@ class external extends external_api {
$USER->id, SQL_PARAMS_NAMED);
// 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();
$fields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$extrasearchfields = $userfieldsapi->get_required_fields([\core\user_fields::PURPOSE_IDENTITY]);
$extrasearchfields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
list($wheresql, $whereparams) = users_search_sql($query, 'u', true, $extrasearchfields);
list($sortsql, $sortparams) = users_order_by_sql('u', $query, $context);
......
......@@ -93,7 +93,7 @@ class template_plans_table extends table_sql {
*/
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(
......@@ -137,7 +137,7 @@ class template_plans_table extends table_sql {
// Add extra user fields that we need for the graded user.
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($this->context, false)->with_name();
$userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_name();
$fields .= $userfieldsapi->get_sql('u')->selects;
if ($count) {
......
......@@ -92,9 +92,9 @@ class acceptances_table extends \table_sql {
}
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity(\context_system::instance(), false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity(\context_system::instance(), 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]);
$this->set_sql("$userfields",
"{user} u",
......@@ -105,7 +105,7 @@ class acceptances_table extends \table_sql {
}
$this->add_column_header('fullname', get_string('fullnameuser', 'core'));
foreach ($extrafields as $field) {
$this->add_column_header($field, \core\user_fields::get_display_name($field));
$this->add_column_header($field, \core_user\fields::get_display_name($field));
}
if (!$this->is_downloading() && !has_capability('tool/policy:acceptbehalf', \context_system::instance())) {
......@@ -170,7 +170,7 @@ class acceptances_table extends \table_sql {
* Helper configuration method.
*/
protected function configure_for_single_version() {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$userfieldsmod = $userfieldsapi->get_sql('m', false, 'mod', '', false)->selects;
$v = key($this->versionids);
$this->sql->fields .= ", $userfieldsmod, a{$v}.status AS status{$v}, a{$v}.note, ".
......
......@@ -343,7 +343,7 @@ class api {
global $DB;
$ctxfields = context_helper::get_preload_record_columns_sql('c');
$userfieldsapi = \core\user_fields::for_name()->with_userpic()->including(...($extrafields ?? []));
$userfieldsapi = \core_user\fields::for_name()->with_userpic()->including(...($extrafields ?? []));
$userfields = $userfieldsapi->get_sql('u')->selects;
$sql = "SELECT $ctxfields $userfields
......@@ -682,7 +682,7 @@ class api {
$vsql = ' AND a.policyversionid ' . $vsql;
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$userfieldsmod = $userfieldsapi->get_sql('m', false, 'mod', '', false)->selects;
$sql = "SELECT u.id AS mainuserid, a.policyversionid, a.status, a.lang, a.timemodified, a.usermodified, a.note,
u.policyagreed, $userfieldsmod
......
......@@ -128,7 +128,7 @@ class accept_policy extends \moodleform {
$usernames = [];
list($sql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params['usercontextlevel'] = CONTEXT_USER;
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$users = $DB->get_records_sql("SELECT u.id" . $userfieldsapi->get_sql('u')->selects . ", " .
\context_helper::get_preload_record_columns_sql('ctx') .
" FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id
......
......@@ -155,7 +155,7 @@ class process {
'interests',
);
// Include all name fields.
$this->standardfields = array_merge($this->standardfields, \core\user_fields::get_name_fields());
$this->standardfields = array_merge($this->standardfields, \core_user\fields::get_name_fields());
}
/**
......
......@@ -183,13 +183,13 @@
// These columns are always shown in the users list.
$requiredcolumns = array('city', 'country', 'lastaccess');
// Extra columns containing the extra user fields, excluding the required columns (city and country, to be specific).
$userfields = \core\user_fields::for_identity($context, true)->with_name()->excluding(...$requiredcolumns);
$userfields = \core_user\fields::for_identity($context, true)->with_name()->excluding(...$requiredcolumns);
$extracolumns = $userfields->get_required_fields();
// Get all user name fields as an array.
$columns = array_merge($extracolumns, $requiredcolumns);
foreach ($columns as $column) {
$string[$column] = \core\user_fields::get_display_name($column);
$string[$column] = \core_user\fields::get_display_name($column);
if ($sort != $column) {
$columnicon = "";
if ($column == "lastaccess") {
......
......@@ -64,7 +64,7 @@ if (count($cohorts) < 2) {
}
$countries = get_string_manager()->get_list_of_countries(true);
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
foreach ($users as $key => $id) {
$user = $DB->get_record('user', array('id' => $id), 'id, ' . $namefields . ', username,
......
......@@ -24,7 +24,7 @@ echo $OUTPUT->header();
$countries = get_string_manager()->get_list_of_countries(true);
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
foreach ($users as $key => $id) {
$user = $DB->get_record('user', array('id'=>$id), 'id, ' . $namefields . ', username, email, country, lastaccess, city');
......
......@@ -197,7 +197,7 @@ class condition extends \core_availability\condition {
$this->customfield);
}
} else {
$translatedfieldname = \core\user_fields::get_display_name($this->standardfield);
$translatedfieldname = \core_user\fields::get_display_name($this->standardfield);
}
$context = \context_course::instance($course->id);
$a = new \stdClass();
......
......@@ -44,23 +44,23 @@ class frontend extends \core_availability\frontend {
\section_info $section = null) {
// Standard user fields.
$standardfields = array(
'firstname' => \core\user_fields::get_display_name('firstname'),
'lastname' => \core\user_fields::get_display_name('lastname'),
'email' => \core\user_fields::get_display_name('email'),
'city' => \core\user_fields::get_display_name('city'),
'country' => \core\user_fields::get_display_name('country'),
'url' => \core\user_fields::get_display_name('url'),
'icq' => \core\user_fields::get_display_name('icq'),
'skype' => \core\user_fields::get_display_name('skype'),
'aim' => \core\user_fields::get_display_name('aim'),
'yahoo' => \core\user_fields::get_display_name('yahoo'),
'msn' => \core\user_fields::get_display_name('msn'),
'idnumber' => \core\user_fields::get_display_name('idnumber'),
'institution' => \core\user_fields::get_display_name('institution'),
'department' => \core\user_fields::get_display_name('department'),
'phone1' => \core\user_fields::get_display_name('phone1'),
'phone2' => \core\user_fields::get_display_name('phone2'),
'address' => \core\user_fields::get_display_name('address')
'firstname' => \core_user\fields::get_display_name('firstname'),
'lastname' => \core_user\fields::get_display_name('lastname'),
'email' => \core_user\fields::get_display_name('email'),
'city' => \core_user\fields::get_display_name('city'),
'country' => \core_user\fields::get_display_name('country'),
'url' => \core_user\fields::get_display_name('url'),
'icq' => \core_user\fields::get_display_name('icq'),
'skype' => \core_user\fields::get_display_name('skype'),
'aim' => \core_user\fields::get_display_name('aim'),
'yahoo' => \core_user\fields::get_display_name('yahoo'),
'msn' => \core_user\fields::get_display_name('msn'),
'idnumber' => \core_user\fields::get_display_name('idnumber'),
'institution' => \core_user\fields::get_display_name('institution'),
'department' => \core_user\fields::get_display_name('department'),
'phone1' => \core_user\fields::get_display_name('phone1'),
'phone2' => \core_user\fields::get_display_name('phone2'),
'address' => \core_user\fields::get_display_name('address')
);
\core_collator::asort($standardfields);
......
......@@ -1365,7 +1365,7 @@ class backup_users_structure_step extends backup_structure_step {
'phone2', 'institution', 'department', 'address',
'city', 'country', 'lastip', 'picture',
'url', 'description', 'descriptionformat', 'imagealt', 'auth');
$anonfields = array_merge($anonfields, \core\user_fields::get_name_fields());
$anonfields = array_merge($anonfields, \core_user\fields::get_name_fields());
// Add anonymized fields to $userfields with custom final element
foreach ($anonfields as $field) {
......
......@@ -58,7 +58,7 @@ class external_badge implements renderable {
global $DB;
// At this point a user has connected a backpack. So, we are going to get
// their backpack email rather than their account email.
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$user = $DB->get_record_sql("SELECT {$namefields}, b.email
FROM {user} u INNER JOIN {badge_backpack} b ON u.id = b.userid
......
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