Skip to content

Commit

Permalink
MDL-71099 Lib: Move new user_fields class from core to core_user
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sammarshallou committed Mar 25, 2021
1 parent d65ed58 commit 5e72715
Show file tree
Hide file tree
Showing 161 changed files with 420 additions and 420 deletions.
2 changes: 1 addition & 1 deletion admin/classes/task_log_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function query_db($pagesize, $useinitialsbar = true) {
}

// 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 = '';
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function col_actions($data) {
*/
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(
Expand Down Expand Up @@ -175,7 +175,7 @@ protected function get_sql_and_params($count = false) {

// 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) {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static function get_site_dpos() {
$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, '.
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/dataprivacy/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,15 +700,15 @@ public static function get_users($query) {
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];
$sort = 'lastname ASC, firstname ASC';
$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);
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/classes/local/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static function get_children_of_user($userid) {
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
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/createdatarequest_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function definition() {
'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);
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/lp/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,9 @@ public static function search_users($query, $capability = '', $limitfrom = 0, $l
$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);
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/lp/classes/output/template_plans_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function col_name($row) {
*/
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(
Expand Down Expand Up @@ -137,7 +137,7 @@ protected function get_sql_and_params($count = false) {

// 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) {
Expand Down
8 changes: 4 additions & 4 deletions admin/tool/policy/classes/acceptances_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function __construct($uniqueid, acceptances_filter $acceptancesfilter, re
}

// 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",
Expand All @@ -105,7 +105,7 @@ public function __construct($uniqueid, acceptances_filter $acceptancesfilter, re
}
$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())) {
Expand Down Expand Up @@ -170,7 +170,7 @@ protected function add_column_header($key, $label, $sortable = true, $columnclas
* 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, ".
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/policy/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public static function get_user_minors($userid, array $extrafields = null) {
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
Expand Down Expand Up @@ -682,7 +682,7 @@ public static function get_user_acceptances($userid, $versions = null) {
$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
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/policy/classes/form/accept_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function validate_and_get_users($versionids, $userids, $action) {
$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
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/uploaduser/classes/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function find_standard_fields(): void {
'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());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion admin/user/user_bulk_cohortadd.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}

$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,
Expand Down
2 changes: 1 addition & 1 deletion admin/user/user_bulk_display.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

$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');
Expand Down
2 changes: 1 addition & 1 deletion availability/condition/profile/classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function get_description($full, $not, \core_availability\info $info) {
$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();
Expand Down
34 changes: 17 additions & 17 deletions availability/condition/profile/classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ protected function get_javascript_init_params($course, \cm_info $cm = null,
\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);

Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ protected function define_structure() {
'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) {
Expand Down
2 changes: 1 addition & 1 deletion badges/classes/output/external_badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($badge, $recipient) {
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
Expand Down
2 changes: 1 addition & 1 deletion badges/classes/output/issued_badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct($hash) {
array('hash' => $hash), IGNORE_MISSING);
if ($rec) {
// Get a recipient from database.
$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 u.id, $namefields, u.deleted, u.email
FROM {user} u WHERE u.id = :userid", array('userid' => $rec->userid));
Expand Down
4 changes: 2 additions & 2 deletions badges/criteria/award_criteria_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function get_options(&$mform) {
$checked = true;
}
$this->config_options($mform, array('id' => $field, 'checked' => $checked,
'name' => \core\user_fields::get_display_name($field), 'error' => false));
'name' => \core_user\fields::get_display_name($field), 'error' => false));
$none = false;
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function get_details($short = '') {
if (is_numeric($p['field'])) {
$str = $DB->get_field('user_info_field', 'name', array('id' => $p['field']));
} else {
$str = \core\user_fields::get_display_name($p['field']);
$str = \core_user\fields::get_display_name($p['field']);
}
if (!$str) {
$output[] = $OUTPUT->error_text(get_string('error:nosuchfield', 'badges'));
Expand Down
2 changes: 1 addition & 1 deletion badges/recipients.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
echo $OUTPUT->box($OUTPUT->single_button($url, get_string('award', 'badges')), 'clearfix mdl-align');
}

$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT b.userid, b.dateissued, b.uniquehash, $namefields
FROM {badge_issued} b INNER JOIN {user} u
Expand Down
4 changes: 2 additions & 2 deletions blocks/activity_results/block_activity_results.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ public function get_content() {

// Now grab all the users from the database.
$userids = array_merge(array_keys($best), array_keys($worst));
$fields = array_merge(array('id', 'idnumber'), \core\user_fields::get_name_fields());
$fields = array_merge(array('id', 'idnumber'), \core_user\fields::get_name_fields());
$fields = implode(',', $fields);
$users = $DB->get_records_list('user', 'id', $userids, '', $fields);

// If configured to view user idnumber, ensure current user can see it.
$extrafields = \core\user_fields::for_identity($this->context)->get_required_fields();
$extrafields = \core_user\fields::for_identity($this->context)->get_required_fields();
$canviewidnumber = (array_search('idnumber', $extrafields) !== false);

// Ready for output!
Expand Down
2 changes: 1 addition & 1 deletion blocks/mentees/block_mentees.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function get_content() {
$this->content = new stdClass();

// get all the mentees, i.e. users you have a direct assignment to
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allusernames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, $allusernames
FROM {role_assignments} ra, {context} c, {user} u
Expand Down
2 changes: 1 addition & 1 deletion blocks/online_users/classes/fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function set_sql($currentgroup, $now, $timetoshowusers, $context, $sit
}
$params = array();

$userfieldsapi = \core\user_fields::for_userpic()->including('username', 'deleted');
$userfieldsapi = \core_user\fields::for_userpic()->including('username', 'deleted');
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;

// Add this to the SQL to show only group users.
Expand Down
Loading

0 comments on commit 5e72715

Please sign in to comment.