Skip to content

Commit

Permalink
MySpace User list: Improve search user BT#18720
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed May 19, 2021
1 parent b4555e8 commit aa96c22
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions main/inc/lib/sessionmanager.lib.php
Expand Up @@ -6126,12 +6126,34 @@ public static function getAllUsersFromCoursesFromAllSessionFromStatus(

if (!empty($keyword)) {
$keyword = Database::escape_string($keyword);

$keywordParts = explode(' ', $keyword);
$extraConditions = '';
if (!empty($keywordParts)) {
$keywordParts = array_filter($keywordParts);
foreach ($keywordParts as $part) {
if (empty($part)) {
continue;
}
$part = Database::escape_string($part);
$extraConditions .= "
OR
(u.username LIKE '%$part%' OR
u.firstname LIKE '%$part%' OR
u.lastname LIKE '%$part%' OR
u.official_code LIKE '%$part%'
)
";
}
}

$userConditions .= " AND (
u.username LIKE '%$keyword%' OR
u.firstname LIKE '%$keyword%' OR
u.lastname LIKE '%$keyword%' OR
u.official_code LIKE '%$keyword%' OR
u.email LIKE '%$keyword%'
$extraConditions
)";
}

Expand Down Expand Up @@ -6199,6 +6221,7 @@ public static function getAllUsersFromCoursesFromAllSessionFromStatus(
}

$sql .= $limitCondition;
var_dump($sql);
$result = Database::query($sql);

return Database::store_result($result);
Expand Down
23 changes: 23 additions & 0 deletions main/inc/lib/usermanager.lib.php
Expand Up @@ -5395,12 +5395,35 @@ public static function getUsersFollowedByUser(

if (!empty($keyword)) {
$keyword = Database::escape_string($keyword);

$keywordParts = explode(' ', $keyword);
$extraConditions = '';
if (!empty($keywordParts)) {
$keywordParts = array_filter($keywordParts);
foreach ($keywordParts as $part) {
if (empty($part)) {
continue;
}
$part = Database::escape_string($part);
$extraConditions .= "
OR
(u.username LIKE '%$part%' OR
u.firstname LIKE '%$part%' OR
u.lastname LIKE '%$part%' OR
u.official_code LIKE '%$part%'
)
";
}
}

$userConditions .= " AND (
u.username LIKE '%$keyword%' OR
u.firstname LIKE '%$keyword%' OR
u.lastname LIKE '%$keyword%' OR
u.official_code LIKE '%$keyword%' OR
u.email LIKE '%$keyword%'
$extraConditions
)";
}

Expand Down

0 comments on commit aa96c22

Please sign in to comment.