| Línea 145... |
Línea 145... |
| 145 |
* @param string $searchtext The string to search for
|
145 |
* @param string $searchtext The string to search for
|
| 146 |
* @param string $sort A field to sort by
|
146 |
* @param string $sort A field to sort by
|
| 147 |
* @param array $exceptions A list of IDs to ignore, eg 2,4,5,8,9,10
|
147 |
* @param array $exceptions A list of IDs to ignore, eg 2,4,5,8,9,10
|
| 148 |
* @return array
|
148 |
* @return array
|
| 149 |
*/
|
149 |
*/
|
| 150 |
function search_users($courseid, $groupid, $searchtext, $sort='', array $exceptions=null) {
|
150 |
function search_users($courseid, $groupid, $searchtext, $sort='', ?array $exceptions=null) {
|
| 151 |
global $DB;
|
151 |
global $DB;
|
| Línea 152... |
Línea 152... |
| 152 |
|
152 |
|
| Línea 153... |
Línea 153... |
| 153 |
$fullname = $DB->sql_fullname('u.firstname', 'u.lastname');
|
153 |
$fullname = $DB->sql_fullname('u.firstname', 'u.lastname');
|
| Línea 232... |
Línea 232... |
| 232 |
* @return array an array with two elements, a fragment of SQL to go in the
|
232 |
* @return array an array with two elements, a fragment of SQL to go in the
|
| 233 |
* where clause the query, and an associative array containing any required
|
233 |
* where clause the query, and an associative array containing any required
|
| 234 |
* parameters (using named placeholders).
|
234 |
* parameters (using named placeholders).
|
| 235 |
*/
|
235 |
*/
|
| 236 |
function users_search_sql(string $search, string $u = 'u', int $searchtype = USER_SEARCH_STARTS_WITH, array $extrafields = [],
|
236 |
function users_search_sql(string $search, string $u = 'u', int $searchtype = USER_SEARCH_STARTS_WITH, array $extrafields = [],
|
| 237 |
array $exclude = null, array $includeonly = null): array {
|
237 |
?array $exclude = null, ?array $includeonly = null): array {
|
| 238 |
global $DB, $CFG;
|
238 |
global $DB, $CFG;
|
| 239 |
$params = array();
|
239 |
$params = array();
|
| 240 |
$tests = array();
|
240 |
$tests = array();
|
| Línea 241... |
Línea 241... |
| 241 |
|
241 |
|
| Línea 358... |
Línea 358... |
| 358 |
* @param array $customfieldmappings associative array of mappings for custom fields returned by \core_user\fields::get_sql.
|
358 |
* @param array $customfieldmappings associative array of mappings for custom fields returned by \core_user\fields::get_sql.
|
| 359 |
* @return array with two elements:
|
359 |
* @return array with two elements:
|
| 360 |
* string SQL fragment to use in the ORDER BY clause. For example, "firstname, lastname".
|
360 |
* string SQL fragment to use in the ORDER BY clause. For example, "firstname, lastname".
|
| 361 |
* array of parameters used in the SQL fragment. If $search is not given, this is guaranteed to be an empty array.
|
361 |
* array of parameters used in the SQL fragment. If $search is not given, this is guaranteed to be an empty array.
|
| 362 |
*/
|
362 |
*/
|
| 363 |
function users_order_by_sql(string $usertablealias = '', string $search = null, context $context = null,
|
363 |
function users_order_by_sql(string $usertablealias = '', ?string $search = null, ?context $context = null,
|
| 364 |
array $customfieldmappings = []) {
|
364 |
array $customfieldmappings = []) {
|
| 365 |
global $DB, $PAGE;
|
365 |
global $DB, $PAGE;
|
| Línea 366... |
Línea 366... |
| 366 |
|
366 |
|
| 367 |
if ($usertablealias) {
|
367 |
if ($usertablealias) {
|
| Línea 380... |
Línea 380... |
| 380 |
if (!$context) {
|
380 |
if (!$context) {
|
| 381 |
$context = $PAGE->context;
|
381 |
$context = $PAGE->context;
|
| 382 |
}
|
382 |
}
|
| Línea 383... |
Línea 383... |
| 383 |
|
383 |
|
| 384 |
$exactconditions = array();
|
- |
|
| Línea 385... |
Línea 384... |
| 385 |
$paramkey = 'usersortexact1';
|
384 |
$exactconditions = array();
|
| 386 |
|
385 |
|
| 387 |
$exactconditions[] = $DB->sql_fullname($tableprefix . 'firstname', $tableprefix . 'lastname') .
|
386 |
$exactconditions[] = $DB->sql_fullname($tableprefix . 'firstname', $tableprefix . 'lastname') .
|
| 388 |
' = :' . $paramkey;
|
- |
|
| Línea 389... |
Línea 387... |
| 389 |
$params[$paramkey] = $search;
|
387 |
' = :usersortexact';
|
| 390 |
$paramkey++;
|
388 |
$params['usersortexact'] = $search;
|
| 391 |
|
389 |
|
| 392 |
if ($customfieldmappings) {
|
390 |
if ($customfieldmappings) {
|
| Línea 397... |
Línea 395... |
| 397 |
return $tableprefix . $field;
|
395 |
return $tableprefix . $field;
|
| 398 |
}, $fieldstocheck);
|
396 |
}, $fieldstocheck);
|
| 399 |
}
|
397 |
}
|
| Línea 400... |
Línea 398... |
| 400 |
|
398 |
|
| 401 |
foreach ($fieldstocheck as $key => $field) {
|
399 |
foreach ($fieldstocheck as $key => $field) {
|
| 402 |
$exactconditions[] = 'LOWER(' . $field . ') = LOWER(:' . $paramkey . ')';
|
400 |
$exactconditions[] = 'LOWER(' . $field . ') = LOWER(:usersortfield' . $key . ')';
|
| 403 |
$params[$paramkey] = $search;
|
- |
|
| 404 |
$paramkey++;
|
401 |
$params['usersortfield' . $key] = $search;
|
| Línea 405... |
Línea 402... |
| 405 |
}
|
402 |
}
|
| 406 |
|
403 |
|
| Línea 427... |
Línea 424... |
| 427 |
* @param string $recordsperpage The number of records to return per page
|
424 |
* @param string $recordsperpage The number of records to return per page
|
| 428 |
* @param string $fields A comma separated list of fields to be returned from the chosen table.
|
425 |
* @param string $fields A comma separated list of fields to be returned from the chosen table.
|
| 429 |
* @return array|int|bool {@link $USER} records unless get is false in which case the integer count of the records found is returned.
|
426 |
* @return array|int|bool {@link $USER} records unless get is false in which case the integer count of the records found is returned.
|
| 430 |
* False is returned if an error is encountered.
|
427 |
* False is returned if an error is encountered.
|
| 431 |
*/
|
428 |
*/
|
| 432 |
function get_users($get=true, $search='', $confirmed=false, array $exceptions=null, $sort='firstname ASC',
|
429 |
function get_users($get=true, $search='', $confirmed=false, ?array $exceptions=null, $sort='firstname ASC',
|
| 433 |
$firstinitial='', $lastinitial='', $page='', $recordsperpage='', $fields='*', $extraselect='', array $extraparams=null) {
|
430 |
$firstinitial='', $lastinitial='', $page='', $recordsperpage='', $fields='*', $extraselect='', ?array $extraparams=null) {
|
| 434 |
global $DB, $CFG;
|
431 |
global $DB, $CFG;
|
| Línea 435... |
Línea 432... |
| 435 |
|
432 |
|
| 436 |
if ($get && !$recordsperpage) {
|
433 |
if ($get && !$recordsperpage) {
|
| 437 |
debugging('Call to get_users with $get = true no $recordsperpage limit. ' .
|
434 |
debugging('Call to get_users with $get = true no $recordsperpage limit. ' .
|
| Línea 501... |
Línea 498... |
| 501 |
* as appropriate for current user and given context
|
498 |
* as appropriate for current user and given context
|
| 502 |
* @return array Array of {@link $USER} records
|
499 |
* @return array Array of {@link $USER} records
|
| 503 |
*/
|
500 |
*/
|
| 504 |
function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperpage=0,
|
501 |
function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperpage=0,
|
| 505 |
$search='', $firstinitial='', $lastinitial='', $extraselect='',
|
502 |
$search='', $firstinitial='', $lastinitial='', $extraselect='',
|
| 506 |
array $extraparams=null, $extracontext = null) {
|
503 |
?array $extraparams=null, $extracontext = null) {
|
| 507 |
global $DB, $CFG;
|
504 |
global $DB, $CFG;
|
| Línea 508... |
Línea 505... |
| 508 |
|
505 |
|
| Línea 509... |
Línea 506... |
| 509 |
$fullname = $DB->sql_fullname();
|
506 |
$fullname = $DB->sql_fullname();
|
| Línea 731... |
Línea 728... |
| 731 |
$NOTREGEXP = $DB->sql_regex(false);
|
728 |
$NOTREGEXP = $DB->sql_regex(false);
|
| 732 |
}
|
729 |
}
|
| Línea 733... |
Línea 730... |
| 733 |
|
730 |
|
| Línea 734... |
Línea -... |
| 734 |
$i = 0;
|
- |
|
| 735 |
|
- |
|
| 736 |
// Thanks Oracle for your non-ansi concat and type limits in coalesce. MDL-29912
|
- |
|
| 737 |
if ($DB->get_dbfamily() == 'oracle') {
|
- |
|
| 738 |
$concat = "(c.summary|| ' ' || c.fullname || ' ' || c.idnumber || ' ' || c.shortname)";
|
731 |
$i = 0;
|
| 739 |
} else {
|
- |
|
| Línea 740... |
Línea 732... |
| 740 |
$concat = $DB->sql_concat("COALESCE(c.summary, '')", "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
|
732 |
|
| 741 |
}
|
733 |
$concat = $DB->sql_concat("COALESCE(c.summary, '')", "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
|
| Línea 742... |
Línea 734... |
| 742 |
|
734 |
|
| 743 |
foreach ($searchterms as $searchterm) {
|
735 |
foreach ($searchterms as $searchterm) {
|
| - |
|
736 |
$i++;
|
| Línea 744... |
Línea 737... |
| 744 |
$i++;
|
737 |
|
| 745 |
|
738 |
// Initially we aren't going to perform NOT LIKE searches, only MSSQL
|
| 746 |
$NOT = false; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
|
739 |
// will use it to simulate the "-" operator with LIKE clause.
|
| 747 |
/// will use it to simulate the "-" operator with LIKE clause
|
740 |
$NOT = false;
|
| 748 |
|
741 |
|
| 749 |
/// Under Oracle and MSSQL, trim the + and - operators and perform
|
742 |
// Under MSSQL, trim the + and - operators and perform
|
| 750 |
/// simpler LIKE (or NOT LIKE) queries
|
743 |
// simpler LIKE (or NOT LIKE) queries.
|
| Línea 1105... |
Línea 1098... |
| 1105 |
|
1098 |
|
| 1106 |
if (empty($userid)) {
|
1099 |
if (empty($userid)) {
|
| 1107 |
$userid = $USER->id;
|
1100 |
$userid = $USER->id;
|
| Línea 1108... |
Línea 1101... |
| 1108 |
}
|
1101 |
}
|
| 1109 |
|
1102 |
|
| 1110 |
// we can not use SELECT DISTINCT + text field (summary) because of MS SQL and Oracle, subselect used therefore
|
1103 |
// We can not use SELECT DISTINCT + text field (summary) because of MS SQL, subselect used therefore.
|
| 1111 |
$sql = "SELECT c.id, c.remoteid, c.shortname, c.fullname,
|
1104 |
$sql = "SELECT c.id, c.remoteid, c.shortname, c.fullname,
|
| 1112 |
c.hostid, c.summary, c.summaryformat, c.categoryname AS cat_name,
|
1105 |
c.hostid, c.summary, c.summaryformat, c.categoryname AS cat_name,
|
| 1113 |
h.name AS hostname
|
1106 |
h.name AS hostname
|
| Línea 1179... |
Línea 1172... |
| 1179 |
* @param string $table
|
1172 |
* @param string $table
|
| 1180 |
* @param string $field name of the field containing revision
|
1173 |
* @param string $field name of the field containing revision
|
| 1181 |
* @param string $select use empty string when updating all records
|
1174 |
* @param string $select use empty string when updating all records
|
| 1182 |
* @param array $params optional select parameters
|
1175 |
* @param array $params optional select parameters
|
| 1183 |
*/
|
1176 |
*/
|
| 1184 |
function increment_revision_number($table, $field, $select, array $params = null) {
|
1177 |
function increment_revision_number($table, $field, $select, ?array $params = null) {
|
| 1185 |
global $DB;
|
1178 |
global $DB;
|
| Línea 1186... |
Línea 1179... |
| 1186 |
|
1179 |
|
| 1187 |
$now = time();
|
1180 |
$now = time();
|
| 1188 |
$sql = "UPDATE {{$table}}
|
1181 |
$sql = "UPDATE {{$table}}
|
| Línea 1727... |
Línea 1720... |
| 1727 |
*/
|
1720 |
*/
|
| 1728 |
$gettypestyle = function($item): string {
|
1721 |
$gettypestyle = function($item): string {
|
| 1729 |
switch (gettype($item)) {
|
1722 |
switch (gettype($item)) {
|
| 1730 |
case 'NULL':
|
1723 |
case 'NULL':
|
| 1731 |
case 'boolean':
|
1724 |
case 'boolean':
|
| 1732 |
return 'font-italic';
|
1725 |
return 'fst-italic';
|
| 1733 |
case 'integer':
|
1726 |
case 'integer':
|
| 1734 |
case 'double':
|
1727 |
case 'double':
|
| 1735 |
return 'text-primary';
|
1728 |
return 'text-primary';
|
| 1736 |
case 'string' :
|
1729 |
case 'string' :
|
| 1737 |
return 'text-success';
|
1730 |
return 'text-success';
|
| Línea 1872... |
Línea 1865... |
| 1872 |
$out .= PHP_EOL . ' ' . $shortkey . ' = ';
|
1865 |
$out .= PHP_EOL . ' ' . $shortkey . ' = ';
|
| 1873 |
} else {
|
1866 |
} else {
|
| 1874 |
switch ($access) {
|
1867 |
switch ($access) {
|
| 1875 |
case 'protected':
|
1868 |
case 'protected':
|
| 1876 |
// Protected is in normal font.
|
1869 |
// Protected is in normal font.
|
| 1877 |
$bootstrapstyle = ' font-weight-normal';
|
1870 |
$bootstrapstyle = ' fw-normal';
|
| 1878 |
break;
|
1871 |
break;
|
| 1879 |
case 'private':
|
1872 |
case 'private':
|
| 1880 |
// Private is italic.
|
1873 |
// Private is italic.
|
| 1881 |
$bootstrapstyle = ' font-weight-normal font-italic';
|
1874 |
$bootstrapstyle = ' fw-normal fst-italic';
|
| 1882 |
break;
|
1875 |
break;
|
| 1883 |
default:
|
1876 |
default:
|
| 1884 |
// Public is bold, same for array keys.
|
1877 |
// Public is bold, same for array keys.
|
| 1885 |
$bootstrapstyle = '';
|
1878 |
$bootstrapstyle = '';
|
| 1886 |
break;
|
1879 |
break;
|