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
......@@ -90,7 +90,7 @@ if ($override->groupid) {
$group = $DB->get_record('groups', array('id' => $override->groupid), 'id, name');
$confirmstr = get_string("overridedeletegroupsure", "assign", $group->name);
} else {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
$user = $DB->get_record('user', array('id' => $override->userid),
'id, ' . $namefields);
......
......@@ -121,7 +121,7 @@ if ($groupmode) {
list($sort, $params) = users_order_by_sql('u');
$params['assignid'] = $assign->id;
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
if ($accessallgroups) {
$sql = 'SELECT o.*, ' . $userfieldsapi->get_sql('u', false, '', '', false)->selects . '
FROM {assign_overrides} o
......
......@@ -372,7 +372,7 @@ function chat_print_recent_activity($course, $viewfullnames, $timestart) {
$groupselect = "";
}
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if (!$users = $DB->get_records_sql("SELECT $userfields
FROM {course_modules} cm
......@@ -514,7 +514,7 @@ function chat_get_users($chatid, $groupid=0, $groupingid=0) {
$groupingjoin = '';
}
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
return $DB->get_records_sql("SELECT DISTINCT $ufields, c.lastmessageping, c.firstping
FROM {chat_users} c
......@@ -907,7 +907,7 @@ function chat_format_message($message, $courseid, $currentuser, $chatlastrow=nul
if (isset($users[$message->userid])) {
$user = $users[$message->userid];
} else if ($user = $DB->get_record('user', ['id' => $message->userid], implode(',', \core\user_fields::get_picture_fields()))) {
} else if ($user = $DB->get_record('user', ['id' => $message->userid], implode(',', \core_user\fields::get_picture_fields()))) {
$users[$message->userid] = $user;
} else {
return null;
......@@ -939,7 +939,7 @@ function chat_format_message_theme ($message, $chatuser, $currentuser, $grouping
if (isset($users[$message->userid])) {
$sender = $users[$message->userid];
} else if ($sender = $DB->get_record('user', array('id' => $message->userid),
implode(',', \core\user_fields::get_picture_fields()))) {
implode(',', \core_user\fields::get_picture_fields()))) {
$users[$message->userid] = $sender;
} else {
return null;
......
......@@ -799,7 +799,7 @@ function choice_get_response_data($choice, $cm, $groupmode, $onlyactive) {
/// First get all the users who have access here
/// To start with we assume they are all "unanswered" then move them later
// 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;
$allresponses[0] = get_enrolled_users($context, 'mod/choice:choose', $currentgroup,
$userfields, null, 0, 0, $onlyactive);
......
......@@ -96,7 +96,7 @@
$users = choice_get_response_data($choice, $cm, $groupmode, $onlyactive);
// 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 ($download == "ods" && has_capability('mod/choice:downloadresponses', $context)) {
require_once("$CFG->libdir/odslib.class.php");
......@@ -119,7 +119,7 @@
// Add headers for extra user fields.
foreach ($extrafields as $field) {
$myxls->write_string(0, $i++, \core\user_fields::get_display_name($field));
$myxls->write_string(0, $i++, \core_user\fields::get_display_name($field));
}
$myxls->write_string(0, $i++, get_string("group"));
......@@ -180,7 +180,7 @@
// Add headers for extra user fields.
foreach ($extrafields as $field) {
$myxls->write_string(0, $i++, \core\user_fields::get_display_name($field));
$myxls->write_string(0, $i++, \core_user\fields::get_display_name($field));
}
$myxls->write_string(0, $i++, get_string("group"));
......@@ -236,7 +236,7 @@
// Add headers for extra user fields.
foreach ($extrafields as $field) {
echo \core\user_fields::get_display_name($field) . "\t";
echo \core_user\fields::get_display_name($field) . "\t";
}
echo get_string("group"). "\t";
......
......@@ -4118,7 +4118,7 @@ function data_get_recordids($alias, $searcharray, $dataid, $recordids) {
function data_get_advanced_search_sql($sort, $data, $recordids, $selectdata, $sortorder) {
global $DB;
$userfieldsapi = \core\user_fields::for_userpic()->excluding('id');
$userfieldsapi = \core_user\fields::for_userpic()->excluding('id');
$namefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if ($sort == 0) {
......
......@@ -1112,7 +1112,7 @@ function data_search_entries($data, $cm, $context, $mode, $currentgroup, $search
$advparams = array();
// This is used for the initial reduction of advanced search results with required entries.
$entrysql = '';
$userfieldsapi = \core\user_fields::for_userpic()->excluding('id');
$userfieldsapi = \core_user\fields::for_userpic()->excluding('id');
$namefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
// Find the field we are sorting on.
......
......@@ -62,7 +62,7 @@ $presets = data_get_available_presets($context);
$strdelete = get_string('deleted', 'data');
foreach ($presets as &$preset) {
if (!empty($preset->userid)) {
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
$presetuser = $DB->get_record('user', array('id' => $preset->userid), 'id, ' . $namefields, MUST_EXIST);
$preset->description = $preset->name.' ('.fullname($presetuser, true).')';
......
......@@ -294,7 +294,7 @@
echo $OUTPUT->notification(get_string('recorddeleted','data'), 'notifysuccess');
}
} else { // Print a confirmation page
$userfieldsapi = \core\user_fields::for_userpic()->excluding('id');
$userfieldsapi = \core_user\fields::for_userpic()->excluding('id');
$allnamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$dbparams = array($delete);
if ($deleterecord = $DB->get_record_sql("SELECT dr.*, $allnamefields
......@@ -331,7 +331,7 @@
$validrecords = array();
$recordids = array();
foreach ($multidelete as $value) {
$userfieldsapi = \core\user_fields::for_userpic()->excluding('id');
$userfieldsapi = \core_user\fields::for_userpic()->excluding('id');
$allnamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$dbparams = array('id' => $value);
if ($deleterecord = $DB->get_record_sql("SELECT dr.*, $allnamefields
......
......@@ -121,9 +121,9 @@ class mod_feedback_responses_table extends table_sql {
);
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($this->get_context(), false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity($this->get_context(), false)->with_userpic();
$ufields = $userfieldsapi->get_sql('u', false, '', $this->useridfield, false)->selects;
$extrafields = $userfieldsapi->get_required_fields([\core\user_fields::PURPOSE_IDENTITY]);
$extrafields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
$fields = 'c.id, c.timemodified as completed_timemodified, c.courseid, '.$ufields;
$from = '{feedback_completed} c '
. 'JOIN {user} u ON u.id = c.userid AND u.deleted = :notdeleted';
......@@ -143,7 +143,7 @@ class mod_feedback_responses_table extends table_sql {
foreach ($extrafields as $field) {
$fields .= ", u.{$field}";
$tablecolumns[] = $field;
$tableheaders[] = \core\user_fields::get_display_name($field);
$tableheaders[] = \core_user\fields::get_display_name($field);
}
}
......
......@@ -388,7 +388,7 @@ function feedback_get_recent_mod_activity(&$activities, &$index,
$sqlargs = array();
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', 'useridagain', false)->selects;
$sql = " SELECT fk . * , fc . * , $userfields
FROM {feedback_completed} fc
......@@ -986,7 +986,7 @@ function feedback_get_incomplete_users(cm_info $cm,
//first get all user who can complete this feedback
$cap = 'mod/feedback:complete';
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$fields = 'u.id, ' . $allnames . ', u.picture, u.email, u.imagealt';
if (!$allusers = get_users_by_capability($context,
......@@ -1124,7 +1124,7 @@ function feedback_get_complete_users($cm,
$sortsql = '';
}
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = 'SELECT DISTINCT '.$ufields.', c.timemodified as completed_timemodified
FROM {user} u, {feedback_completed} c '.$fromgroup.'
......
......@@ -57,7 +57,7 @@ class export_form extends \moodleform {
'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, ' . $allusernames;
$user = \core_user::get_user($value, $fields);
......
......@@ -131,7 +131,7 @@ class discussion_list extends db_table_vault {
// - Most recent editor.
$thistable = new dml_table(self::TABLE, $alias, $alias);
$posttable = new dml_table('forum_posts', 'fp', 'p_');
$userfieldsapi = \core\user_fields::for_userpic()->including('deleted');
$userfieldsapi = \core_user\fields::for_userpic()->including('deleted');
$firstauthorfields = $userfieldsapi->get_sql('fa', false,
self::FIRST_AUTHOR_ALIAS, self::FIRST_AUTHOR_ID_ALIAS, false)->selects;
$latestuserfields = $userfieldsapi->get_sql('la', false,
......@@ -274,7 +274,7 @@ class discussion_list extends db_table_vault {
$nameformat = get_string('fullnamedisplay', '', (object)['firstname' => 'firstname', 'lastname' => 'lastname']);
}
// Fetch all the available user name fields.
$availablefields = order_in_string(\core\user_fields::get_name_fields(), $nameformat);
$availablefields = order_in_string(\core_user\fields::get_name_fields(), $nameformat);
// We'll default to the first name if there's no available name field.
$returnfield = 'firstname';
if (!empty($availablefields)) {
......
......@@ -393,7 +393,7 @@ class subscriptions {
global $CFG, $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.username,
......
......@@ -839,7 +839,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
// Build an object that represents the posting user
$postuser = new stdClass;
$postuserfields = explode(',', implode(',', \core\user_fields::get_picture_fields()));
$postuserfields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
$postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
$postuser->id = $post->userid;
$postuser->fullname = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']);
......
......@@ -674,7 +674,7 @@ class mod_forum_external extends external_api {
$discussion->usermodifiedfullname = null;
$discussion->usermodifiedpictureurl = null;
} else {
$picturefields = explode(',', implode(',', \core\user_fields::get_picture_fields()));
$picturefields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
// Load user objects from the results of the query.
$user = new stdclass();
......
......@@ -644,7 +644,7 @@ function forum_print_recent_activity($course, $viewfullnames, $timestart) {
// do not use log table if possible, it may be huge and is expensive to join with other tables
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$allnamefields = $userfieldsapi->get_sql('u', false, '', 'duserid', false)->selects;
if (!$posts = $DB->get_records_sql("SELECT p.*,
f.course, f.type AS forumtype, f.name AS forumname, f.intro, f.introformat, f.duedate,
......@@ -972,7 +972,7 @@ function forum_scale_used_anywhere(int $scaleid): bool {
function forum_get_post_full($postid) {
global $CFG, $DB;
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
return $DB->get_record_sql("SELECT p.*, d.forum, $allnames, u.email, u.picture, u.imagealt
FROM {forum_posts} p
......@@ -1002,7 +1002,7 @@ function forum_get_all_discussion_posts($discussionid, $sort, $tracking = false)
$params[] = $USER->id;
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$params[] = $discussionid;
if (!$posts = $DB->get_records_sql("SELECT p.*, $allnames, u.email, u.picture, u.imagealt $tr_sel
......@@ -1301,7 +1301,7 @@ function forum_search_posts($searchterms, $courseid, $limitfrom, $limitnum,
FROM $fromsql
WHERE $selectsql";
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$searchsql = "SELECT p.*,
d.forum,
......@@ -1342,7 +1342,7 @@ function forum_get_user_posts($forumid, $userid) {
}
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
return $DB->get_records_sql("SELECT p.*, d.forum, $allnames, u.email, u.picture, u.imagealt
FROM {forum} f
......@@ -1434,7 +1434,7 @@ function forum_count_user_posts($forumid, $userid) {
function forum_get_post_from_log($log) {
global $CFG, $DB;
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if ($log->action == "add post") {
......@@ -1763,7 +1763,7 @@ function forum_get_discussions($cm, $forumsort="", $fullpost=true, $unused=-1, $
$postdata = "p.*";
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
if (empty($userlastmodified)) { // We don't need to know this
$umfields = "";
......@@ -2439,7 +2439,7 @@ function forum_print_discussion_header(&$post, $forum, $group = -1, $datestring
// Picture
$postuser = new stdClass();
$postuserfields = explode(',', implode(',', \core\user_fields::get_picture_fields()));
$postuserfields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
$postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
$postuser->id = $post->userid;
echo '<td class="author">';
......@@ -4114,7 +4114,7 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
$groupselect = "";
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if (!$posts = $DB->get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
d.timestart, d.timeend, d.userid AS duserid,
......@@ -4187,7 +4187,7 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
$tmpactivity->user = new stdClass();
$additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email');
$additionalfields = explode(',', implode(',', \core\user_fields::get_picture_fields()));
$additionalfields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
$tmpactivity->user = username_load_fields_from_object($tmpactivity->user, $post, null, $additionalfields);
$tmpactivity->user->id = $post->userid;
......@@ -6024,7 +6024,7 @@ function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false,
// Prepare SQL to both count and search.
// We alias user.id to useridx because we forum_posts already has a userid field and not aliasing this would break
// oracle and mssql.
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', 'useridx', false)->selects;
$countsql = 'SELECT COUNT(*) ';
$selectsql = 'SELECT p.*, d.forum, d.name AS discussionname, '.$userfields.' ';
......
......@@ -126,7 +126,7 @@ class mod_forum_renderer extends plugin_renderer_base {
} else {
$cm = $modinfo->instances['forum'][$forum->id];
// TODO Does not support custom user profile fields (MDL-70456).
$canviewemail = in_array('email', \core\user_fields::get_identity_fields(context_module::instance($cm->id), false));
$canviewemail = in_array('email', \core_user\fields::get_identity_fields(context_module::instance($cm->id), false));
$strparams = new stdclass();
$strparams->name = format_string($forum->name);
$strparams->count = count($users);
......
......@@ -544,7 +544,7 @@ class summary_table extends table_sql {
global $USER;
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core\user_fields::for_identity($this->userfieldscontext, false)->with_userpic();
$userfieldsapi = \core_user\fields::for_identity($this->userfieldscontext, false)->with_userpic();
$userfieldssql = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
// Define base SQL query format.
......
......@@ -182,7 +182,7 @@ function forum_rss_feed_discussions_sql($forum, $cm, $newsince=0) {
$forumsort = "d.timemodified DESC";
$postdata = "p.id AS postid, p.subject, p.created as postcreated, p.modified, p.discussion, p.userid, p.message as postmessage, p.messageformat AS postformat, p.messagetrust AS posttrust";
$userfieldsapi = \core\user_fields::for_userpic();
$userfieldsapi = \core_user\fields::for_userpic();
$userpicturefields = $userfieldsapi->get_sql('u', false, '', 'userid', false)->selects;
$sql = "SELECT $postdata, d.id as discussionid, d.name as discussionname, d.timemodified, d.usermodified, d.groupid,
......@@ -236,7 +236,7 @@ function forum_rss_feed_posts_sql($forum, $cm, $newsince=0) {
$privatewhere = '';
}
$userfieldsapi = \core\user_fields::for_name();
$userfieldsapi = \core_user\fields::for_name();
$usernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT p.id AS postid,
d.id AS discussionid,
......
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