Skip to content

Commit

Permalink
Update class.ilSoapUserAdministration.php : Mantis #0038383: Search u…
Browse files Browse the repository at this point in the history
…ser by matriculation returns several users

This modification ensures that when the search is performed for users by matriculation number, it will return only those users whose matriculation number exactly matches the search term. For other fields, the search will still use a LIKE operator to find partial matches.
  • Loading branch information
waddahadel authored May 25, 2024
1 parent d98a05f commit 0c60391
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions webservice/soap/classes/class.ilSoapUserAdministration.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,35 +980,42 @@ public function searchUser($sid, $a_keyfields, $query_operator, $a_keyvalues, $a
*/

public function __buildSearchQuery($a_keyfields, $queryOperator, $a_keyvalues)
{
global $DIC;
{
global $DIC;

$ilDB = $DIC['ilDB'];
$query = array();
$ilDB = $DIC['ilDB'];
$query = array();

$allowed_fields = array("firstname","lastname","email","login","matriculation","institution","department","title","ext_account");
$allowed_fields = array("firstname","lastname","email","login","matriculation","institution","department","title","ext_account");

foreach ($a_keyfields as $keyfield) {
$keyfield = strtolower($keyfield);
foreach ($a_keyfields as $keyfield) {
$keyfield = strtolower($keyfield);

if (!in_array($keyfield, $allowed_fields)) {
continue;
}
if (!in_array($keyfield, $allowed_fields)) {
continue;
}

$field_query = array();
foreach ($a_keyvalues as $keyvalue) {
if (strlen($keyvalue) >= 3) {
$field_query []= $keyfield . " like '%" . $keyvalue . "%'";
$field_query = array();
foreach ($a_keyvalues as $keyvalue) {
if (strlen($keyvalue) >= 3) {
if ($keyfield === 'matriculation') {
// Use exact match for matriculation
$field_query[] = $ilDB->quoteIdentifier($keyfield) . " = " . $ilDB->quote($keyvalue, 'text');
} else {
// Use LIKE for other fields
$field_query[] = $ilDB->like($ilDB->quoteIdentifier($keyfield), 'text', '%' . $keyvalue . '%');
}
}
if (count($field_query)) {
$query [] = join(" " . strtoupper($queryOperator) . " ", $field_query);
}
}

return count($query) ? " AND ((" . join(") OR (", $query) . "))" : "AND 0";
if (count($field_query)) {
$query[] = join(" " . strtoupper($queryOperator) . " ", $field_query);
}
}

return count($query) ? " AND ((" . join(") OR (", $query) . "))" : "AND 0";
}



/**
* return user xmls for given user ids (csv separated ids) as xml based on usr dtd.
Expand Down

0 comments on commit 0c60391

Please sign in to comment.