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
......@@ -76,7 +76,7 @@ class issued_badge implements renderable {
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));
......
......@@ -89,7 +89,7 @@ class award_criteria_profile extends award_criteria {
$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;
}
}
......@@ -139,7 +139,7 @@ class award_criteria_profile extends award_criteria {
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'));
......
......@@ -87,7 +87,7 @@ if ($badge->has_manual_award_criteria() && has_capability('moodle/badges:awardba
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
......
......@@ -508,12 +508,12 @@ class block_activity_results extends block_base {
// 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!
......
......@@ -50,7 +50,7 @@ class block_mentees extends block_base {
$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
......
......@@ -86,7 +86,7 @@ class fetcher {
}
$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.
......
......@@ -646,7 +646,7 @@ class blog_listing {
if (!$userid) {
$userid = $USER->id;
}
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$allnamefields = $userfieldsapi->get_sql('u', false, '', 'useridalias', false)->selects;
// The query used to locate blog entries is complicated. It will be built from the following components:
$requiredfields = "p.*, $allnamefields"; // The SELECT clause.
......
......@@ -234,7 +234,7 @@ function blog_rss_get_feed($context, $args) {
switch ($type) {
case 'user':
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$info = fullname($DB->get_record('user', array('id' => $id),
$userfieldsapi->get_sql('', false, '', '', false)->selects));
break;
......
......@@ -551,7 +551,7 @@ class comment {
$params = array();
$perpage = (!empty($CFG->commentsperpage))?$CFG->commentsperpage:15;
$start = $page * $perpage;
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
list($componentwhere, $component) = $this->get_component_select_sql('c');
......
......@@ -61,7 +61,7 @@ class comment_manager {
}
$comments = array();
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$usernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, $usernamefields, c.timecreated
FROM {comments} c
......@@ -76,7 +76,7 @@ class comment_manager {
$item->time = userdate($item->timecreated);
$item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions);
// Unset fields not related to the comment
foreach (\core\user_fields::get_name_fields() as $namefield) {
foreach (\core_user\fields::get_name_fields() as $namefield) {
unset($item->$namefield);
}
unset($item->timecreated);
......
......@@ -1033,7 +1033,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
list($sql2, $params2) = $DB->get_in_or_equal($managerroles, SQL_PARAMS_NAMED, 'rid');
list($sort, $sortparams) = users_order_by_sql('u');
$notdeleted = array('notdeleted' => 0);
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT ra.contextid, ra.id AS raid,
r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
......
......@@ -77,7 +77,7 @@ class recent_form extends moodleform {
$options[0] = get_string('allparticipants');
$options[$CFG->siteguest] = get_string('guestuser');
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if (isset($groupoptions[0])) {
......
......@@ -95,7 +95,7 @@ switch ($action) {
$page = optional_param('page', 0, PARAM_INT);
$outcome->response = $manager->search_other_users($search, $searchanywhere, $page);
// 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();
// User is not enrolled, either link to site profile or do not link at all.
if (has_capability('moodle/user:viewdetails', context_system::instance())) {
......
......@@ -558,10 +558,10 @@ class core_enrol_external extends external_api {
$results = array();
// Add also extra user fields.
$identityfields = \core\user_fields::get_identity_fields($context, true);
$identityfields = \core_user\fields::get_identity_fields($context, true);
$customprofilefields = [];
foreach ($identityfields as $key => $value) {
if ($fieldname = \core\user_fields::match_custom_field($value)) {
if ($fieldname = \core_user\fields::match_custom_field($value)) {
unset($identityfields[$key]);
$customprofilefields[$fieldname] = true;
}
......@@ -673,7 +673,7 @@ class core_enrol_external extends external_api {
$requiredfields = array_merge(
['id', 'fullname', 'profileimageurl', 'profileimageurlsmall'],
// TODO Does not support custom user profile fields (MDL-70456).
\core\user_fields::get_identity_fields($context, false)
\core_user\fields::get_identity_fields($context, false)
);
foreach ($users['users'] as $user) {
if ($userdetails = user_get_user_details($user, $course, $requiredfields)) {
......
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core\user_fields;
use core_user\fields;
defined('MOODLE_INTERNAL') || die();
......@@ -240,7 +240,7 @@ class course_enrolment_manager {
list($instancessql, $params, $filter) = $this->get_instance_sql();
list($filtersql, $moreparams) = $this->get_filter_sql();
$params += $moreparams;
$userfields = user_fields::for_identity($this->get_context())->with_userpic()->excluding('lastaccess');
$userfields = fields::for_identity($this->get_context())->with_userpic()->excluding('lastaccess');
['selects' => $fieldselect, 'joins' => $fieldjoin, 'params' => $fieldjoinparams] =
(array)$userfields->get_sql('u', true, '', '', false);
$params += $fieldjoinparams;
......@@ -273,7 +273,7 @@ class course_enrolment_manager {
// Search condition.
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = user_fields::get_identity_fields($this->get_context(), false);
$extrafields = fields::get_identity_fields($this->get_context(), false);
list($sql, $params) = users_search_sql($this->searchfilter, 'u', true, $extrafields);
// Role condition.
......@@ -346,7 +346,7 @@ class course_enrolment_manager {
list($ctxcondition, $params) = $DB->get_in_or_equal($this->context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'ctx');
$params['courseid'] = $this->course->id;
$params['cid'] = $this->course->id;
$userfields = user_fields::for_identity($this->get_context())->with_userpic();
$userfields = fields::for_identity($this->get_context())->with_userpic();
['selects' => $fieldselect, 'joins' => $fieldjoin, 'params' => $fieldjoinparams] =
(array)$userfields->get_sql('u', true);
$params += $fieldjoinparams;
......@@ -387,14 +387,14 @@ class course_enrolment_manager {
// Get custom user field SQL used for querying all the fields we need (identity, name, and
// user picture).
$userfields = user_fields::for_identity($this->context)->with_name()->with_userpic()
$userfields = fields::for_identity($this->context)->with_name()->with_userpic()
->excluding('username', 'lastaccess', 'maildisplay');
['selects' => $fieldselects, 'joins' => $fieldjoins, 'params' => $params, 'mappings' => $mappings] =
(array)$userfields->get_sql('u', true, '', '', false);
// Searchable fields are only the identity and name ones (not userpic).
$searchable = array_fill_keys($userfields->get_required_fields(
[user_fields::PURPOSE_IDENTITY, user_fields::PURPOSE_NAME]), true);
[fields::PURPOSE_IDENTITY, fields::PURPOSE_NAME]), true);
// Add some additional sensible conditions
$tests = array("u.id <> :guestid", 'u.deleted = 0', 'u.confirmed = 1');
......@@ -1068,7 +1068,7 @@ class course_enrolment_manager {
$context = $this->get_context();
$now = time();
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = user_fields::get_identity_fields($context, false);
$extrafields = fields::get_identity_fields($context, false);
$users = array();
foreach ($userroles as $userrole) {
......@@ -1147,7 +1147,7 @@ class course_enrolment_manager {
$url = new moodle_url($pageurl, $this->get_url_params());
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = user_fields::get_identity_fields($context, false);
$extrafields = fields::get_identity_fields($context, false);
$enabledplugins = $this->get_enrolment_plugins(true);
......@@ -1324,7 +1324,7 @@ class course_enrolment_manager {
list($instancesql, $instanceparams) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED, 'instanceid0000');
}
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
list($idsql, $idparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid0000');
......
......@@ -93,7 +93,7 @@ class enrol_manual_enrol_users_form extends moodleform {
'courseid' => $course->id,
'enrolid' => $instance->id,
'perpage' => $CFG->maxusersperpage,
'userfields' => implode(',', \core\user_fields::get_identity_fields($context, true))
'userfields' => implode(',', \core_user\fields::get_identity_fields($context, true))
);
$mform->addElement('autocomplete', 'userlist', get_string('selectusers', 'enrol_manual'), array(), $options);
......
......@@ -55,9 +55,9 @@ $userdetails = array (
'lastname' => get_string('lastname'),
);
// 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);
foreach ($extrafields as $field) {
$userdetails[$field] = \core\user_fields::get_display_name($field);
$userdetails[$field] = \core_user\fields::get_display_name($field);
}
$fields = array(
......
......@@ -1021,7 +1021,7 @@ class enrol_self_plugin extends enrol_plugin {
// We only use the first user.
$i = 0;
do {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$rusers = get_role_users($croles[$i], $context, true, 'u.id, u.confirmed, u.username, '. $allnames . ',
u.email, r.sortorder, ra.id', 'r.sortorder, ra.id ASC, ' . $sort, null, '', '', '', '', $sortparams);
......
......@@ -82,7 +82,7 @@ class enrol_self_enrol_form extends moodleform {
$mform->addElement('password', 'enrolpassword', get_string('password', 'enrol_self'),
array('id' => 'enrolpassword_'.$instance->id));
$context = context_course::instance($this->instance->courseid);
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$keyholders = get_users_by_capability($context, 'enrol/self:holdkey', $ufields);
$keyholdercount = 0;
......
......@@ -91,7 +91,7 @@ switch ($action) {
}
if ($errorstr) {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$user = $DB->get_record('user', array('id' => $userid), 'id' . $userfieldsapi->get_sql()->selects);
$gradestr = new stdClass();
$gradestr->username = fullname($user);
......
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