mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 23:42:11 +02:00
MDL-82170 user: replace increment operator on string type variable.
This commit is contained in:
parent
07881a5772
commit
db01833822
@ -382,12 +382,10 @@ function users_order_by_sql(string $usertablealias = '', ?string $search = null,
|
||||
}
|
||||
|
||||
$exactconditions = array();
|
||||
$paramkey = 'usersortexact1';
|
||||
|
||||
$exactconditions[] = $DB->sql_fullname($tableprefix . 'firstname', $tableprefix . 'lastname') .
|
||||
' = :' . $paramkey;
|
||||
$params[$paramkey] = $search;
|
||||
$paramkey++;
|
||||
' = :usersortexact';
|
||||
$params['usersortexact'] = $search;
|
||||
|
||||
if ($customfieldmappings) {
|
||||
$fieldstocheck = array_merge([$tableprefix . 'firstname', $tableprefix . 'lastname'], array_values($customfieldmappings));
|
||||
@ -399,9 +397,8 @@ function users_order_by_sql(string $usertablealias = '', ?string $search = null,
|
||||
}
|
||||
|
||||
foreach ($fieldstocheck as $key => $field) {
|
||||
$exactconditions[] = 'LOWER(' . $field . ') = LOWER(:' . $paramkey . ')';
|
||||
$params[$paramkey] = $search;
|
||||
$paramkey++;
|
||||
$exactconditions[] = 'LOWER(' . $field . ') = LOWER(:usersortfield' . $key . ')';
|
||||
$params['usersortfield' . $key] = $search;
|
||||
}
|
||||
|
||||
$sort = 'CASE WHEN ' . implode(' OR ', $exactconditions) .
|
||||
|
@ -174,12 +174,11 @@ final class datalib_test extends \advanced_testcase {
|
||||
|
||||
list($sort, $params) = users_order_by_sql('', 'search', \context_system::instance());
|
||||
$this->assert_same_sql('CASE WHEN
|
||||
' . $DB->sql_fullname() . ' = :usersortexact1 OR
|
||||
LOWER(firstname) = LOWER(:usersortexact2) OR
|
||||
LOWER(lastname) = LOWER(:usersortexact3)
|
||||
' . $DB->sql_fullname() . ' = :usersortexact OR
|
||||
LOWER(firstname) = LOWER(:usersortfield0) OR
|
||||
LOWER(lastname) = LOWER(:usersortfield1)
|
||||
THEN 0 ELSE 1 END, lastname, firstname, id', $sort);
|
||||
$this->assertEquals(array('usersortexact1' => 'search', 'usersortexact2' => 'search',
|
||||
'usersortexact3' => 'search'), $params);
|
||||
$this->assertEquals(['usersortexact' => 'search', 'usersortfield0' => 'search', 'usersortfield1' => 'search'], $params);
|
||||
}
|
||||
|
||||
public function test_users_order_by_sql_search_with_extra_fields_and_prefix(): void {
|
||||
@ -191,14 +190,14 @@ final class datalib_test extends \advanced_testcase {
|
||||
|
||||
list($sort, $params) = users_order_by_sql('u', 'search', \context_system::instance());
|
||||
$this->assert_same_sql('CASE WHEN
|
||||
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact1 OR
|
||||
LOWER(u.firstname) = LOWER(:usersortexact2) OR
|
||||
LOWER(u.lastname) = LOWER(:usersortexact3) OR
|
||||
LOWER(u.email) = LOWER(:usersortexact4) OR
|
||||
LOWER(u.idnumber) = LOWER(:usersortexact5)
|
||||
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact OR
|
||||
LOWER(u.firstname) = LOWER(:usersortfield0) OR
|
||||
LOWER(u.lastname) = LOWER(:usersortfield1) OR
|
||||
LOWER(u.email) = LOWER(:usersortfield2) OR
|
||||
LOWER(u.idnumber) = LOWER(:usersortfield3)
|
||||
THEN 0 ELSE 1 END, u.lastname, u.firstname, u.id', $sort);
|
||||
$this->assertEquals(array('usersortexact1' => 'search', 'usersortexact2' => 'search',
|
||||
'usersortexact3' => 'search', 'usersortexact4' => 'search', 'usersortexact5' => 'search'), $params);
|
||||
$this->assertEquals(['usersortexact' => 'search', 'usersortfield0' => 'search',
|
||||
'usersortfield1' => 'search', 'usersortfield2' => 'search', 'usersortfield3' => 'search'], $params);
|
||||
}
|
||||
|
||||
public function test_users_order_by_sql_search_with_custom_fields(): void {
|
||||
@ -211,13 +210,13 @@ final class datalib_test extends \advanced_testcase {
|
||||
list($sort, $params) =
|
||||
users_order_by_sql('u', 'search', \context_system::instance(), ['profile_field_customfield' => 'x.customfield']);
|
||||
$this->assert_same_sql('CASE WHEN
|
||||
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact1 OR
|
||||
LOWER(u.firstname) = LOWER(:usersortexact2) OR
|
||||
LOWER(u.lastname) = LOWER(:usersortexact3) OR
|
||||
LOWER(x.customfield) = LOWER(:usersortexact4)
|
||||
' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact OR
|
||||
LOWER(u.firstname) = LOWER(:usersortfield0) OR
|
||||
LOWER(u.lastname) = LOWER(:usersortfield1) OR
|
||||
LOWER(x.customfield) = LOWER(:usersortfield2)
|
||||
THEN 0 ELSE 1 END, u.lastname, u.firstname, u.id', $sort);
|
||||
$this->assertEquals(array('usersortexact1' => 'search', 'usersortexact2' => 'search',
|
||||
'usersortexact3' => 'search', 'usersortexact4' => 'search'), $params);
|
||||
$this->assertEquals(['usersortexact' => 'search', 'usersortfield0' => 'search',
|
||||
'usersortfield1' => 'search', 'usersortfield2' => 'search'], $params);
|
||||
}
|
||||
|
||||
public function test_get_admin(): void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user