Commit 558cc1b8 authored by sam marshall's avatar sam marshall
Browse files

MDL-45242 Lib: Replace calls to deprecated functions

In all cases changes have been kept to a minimum while not making
the code completely horrible. For example, there are many instances
where it would probably be better to rewrite a query entirely, but
I have not done that (in order to reduce the risk of changes).
parent 3f003455
......@@ -131,7 +131,8 @@ function report_stats_report($course, $report, $mode, $user, $roleid, $time) {
list($sort, $moreparams) = users_order_by_sql('u');
$moreparams['courseid'] = $course->id;
$fields = user_picture::fields('u', array('idnumber'));
$userfieldsapi = \core\user_fields::for_userpic()->including('idnumber');
$fields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "SELECT DISTINCT $fields
FROM {stats_user_{$param->table}} s
JOIN {user} u ON u.id = s.userid
......
......@@ -150,7 +150,8 @@ abstract class engine {
global $DB;
if (empty(self::$cachedusers[$userid])) {
$fields = get_all_user_name_fields(true);
$userfieldsapi = \core\user_fields::for_name();
$fields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
self::$cachedusers[$userid] = $DB->get_record('user', array('id' => $userid), 'id, ' . $fields);
}
return self::$cachedusers[$userid];
......
......@@ -155,7 +155,8 @@ class core_tag_manage_table extends table_sql {
$sort = "tg.name";
}
$allusernames = get_all_user_name_fields(true, 'u');
$userfieldsapi = \core\user_fields::for_name();
$allusernames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$sql = "
SELECT tg.id, tg.name, tg.rawname, tg.isstandard, tg.flag, tg.timemodified,
u.id AS owner, $allusernames,
......
......@@ -93,7 +93,8 @@ if ($formaction == 'bulkchange.php') {
'lastname' => get_string('lastname'),
);
$identityfields = get_extra_user_fields($context);
// TODO Does not support custom user profile fields (MDL-70456).
$identityfields = \core\user_fields::get_identity_fields($context, false);
$identityfieldsselect = '';
foreach ($identityfields as $field) {
......
......@@ -94,7 +94,7 @@ class user extends \core_search\base {
$doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
// Include all alternate names in title.
$array = [];
foreach (get_all_user_name_fields(false, null, null, null, true) as $field) {
foreach (\core\user_fields::get_name_fields(true) as $field) {
$array[$field] = $record->$field;
}
$fullusername = join(' ', $array);
......
......@@ -141,9 +141,10 @@ class participants extends \table_sql implements dynamic_table {
$headers[] = get_string('fullname');
$columns[] = 'fullname';
$extrafields = get_extra_user_fields($this->context);
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core\user_fields::get_identity_fields($this->context, false);
foreach ($extrafields as $field) {
$headers[] = get_user_field_name($field);
$headers[] = \core\user_fields::get_display_name($field);
$columns[] = $field;
}
......
......@@ -77,7 +77,8 @@ class participants_search {
$this->context = $context;
$this->filterset = $filterset;
$this->userfields = get_extra_user_fields($this->context);
// TODO Does not support custom user profile fields (MDL-70456).
$this->userfields = \core\user_fields::get_identity_fields($this->context, false);
}
/**
......
......@@ -480,7 +480,7 @@ function useredit_get_enabled_name_fields() {
global $CFG;
// Get all of the other name fields which are not ranked as necessary.
$additionalusernamefields = array_diff(get_all_user_name_fields(), array('firstname', 'lastname'));
$additionalusernamefields = array_diff(\core\user_fields::get_name_fields(), array('firstname', 'lastname'));
// Find out which additional name fields are actually being used from the fullnamedisplay setting.
$enabledadditionalusernames = array();
foreach ($additionalusernamefields as $enabledname) {
......@@ -507,7 +507,14 @@ function useredit_get_disabled_name_fields($enabledadditionalusernames = null) {
}
// These are the additional fields that are not currently enabled.
$nonusednamefields = array_diff(get_all_user_name_fields(),
$nonusednamefields = array_diff(\core\user_fields::get_name_fields(),
array_merge(array('firstname', 'lastname'), $enabledadditionalusernames));
return $nonusednamefields;
// It may not be significant anywhere, but for compatibility, this used to return an array
// with keys and values the same.
$result = [];
foreach ($nonusednamefields as $field) {
$result[$field] = $field;
}
return $result;
}
......@@ -302,7 +302,8 @@ function user_get_user_details($user, $course = null, array $userfields = array(
$currentuser = ($user->id == $USER->id);
$isadmin = is_siteadmin($USER);
$showuseridentityfields = get_extra_user_fields($context);
// TODO Does not support custom user profile fields (MDL-70456).
$showuseridentityfields = \core\user_fields::get_identity_fields($context, false);
if (!empty($course)) {
$canviewhiddenuserfields = has_capability('moodle/course:viewhiddenuserfields', $context);
......
......@@ -114,7 +114,8 @@ abstract class user_selector_base {
}
// Populate the list of additional user identifiers to display.
$this->extrafields = get_extra_user_fields($this->accesscontext);
// TODO Does not support custom user profile fields (MDL-70456).
$this->extrafields = \core\user_fields::get_identity_fields($this->accesscontext, false);
if (isset($options['exclude']) && is_array($options['exclude'])) {
$this->exclude = $options['exclude'];
......@@ -438,7 +439,7 @@ abstract class user_selector_base {
// Raw list of fields.
$fields = array('id');
// Add additional name fields.
$fields = array_merge($fields, get_all_user_name_fields(), $this->extrafields);
$fields = array_merge($fields, \core\user_fields::get_name_fields(), $this->extrafields);
// Prepend the table alias.
if ($u) {
......
......@@ -23,7 +23,7 @@ $PAGE->set_title($title);
$PAGE->set_heading($title);
echo $OUTPUT->header();
$rs = $DB->get_recordset_select("user", "deleted = 0 AND picture > 0", array(), "lastaccess DESC", user_picture::fields());
$rs = $DB->get_recordset_select("user", "deleted = 0 AND picture > 0", array(), "lastaccess DESC", implode(',', \core\user_fields::get_picture_fields()));
foreach ($rs as $user) {
$fullname = s(fullname($user));
echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=1\" ".
......
......@@ -217,8 +217,9 @@ class token_table extends \table_sql {
debugging('Initial bar not implemented yet. Call out($pagesize, false)');
}
$usernamefields = get_all_user_name_fields(true, 'u');
$creatorfields = get_all_user_name_fields(true, 'c', null, 'creator');
$userfieldsapi = \core\user_fields::for_name();
$usernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$creatorfields = $userfieldsapi->get_sql('c', false, 'creator', '', false)->selects;
$params = ["tokenmode" => EXTERNAL_TOKEN_PERMANENT];
......
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