Skip to content
Snippets Groups Projects
Commit 719e7463 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added WS list users functionalities

parent 92a77b86
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,13 @@ interface UserDAO { ...@@ -61,6 +61,13 @@ interface UserDAO {
*/ */
function searchUser($searchText); function searchUser($searchText);
/**
* Retrieve a list of all users having given identifiers.
* @param array $identifiers
* @return array
*/
function getUsers(array $identifiers): array;
/** /**
* Perform a join request. * Perform a join request.
* @param type $userId1 the user that will receive all identities * @param type $userId1 the user that will receive all identities
......
...@@ -174,6 +174,47 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO { ...@@ -174,6 +174,47 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
$stmt->bindParam(':surname', $searchParam); $stmt->bindParam(':surname', $searchParam);
$stmt->bindParam(':namesurname', $searchParam); $stmt->bindParam(':namesurname', $searchParam);
return $this->getUsersListFromStatement($stmt);
}
public function getUsers(array $identifiers): array {
if (count($identifiers) === 0) {
return [];
}
$dbh = $this->getDBHandler();
$query = "SELECT `user_id`, (u.`primary_identity` = i.`id`) AS `primary`,"
. " i.`id`, `type`, `typed_id`, `email`, `name`, `surname`, `institution`, `eppn`"
. " FROM identity i"
. " JOIN `user` u on u.id = i.user_id"
. " WHERE i.user_id IN (";
$first = true;
foreach ($identifiers as $id) {
if (!$first) {
$query .= ',';
}
$query .= ':id_' . $id;
if ($first) {
$first = !$first;
}
}
$query .= ')';
$stmt = $dbh->prepare($query);
foreach ($identifiers as $id) {
$stmt->bindParam(':id_' . $id, $id);
}
return $this->getUsersListFromStatement($stmt);
}
private function getUsersListFromStatement(\PDOStatement $stmt): array {
$stmt->execute(); $stmt->execute();
$userMap = array(); $userMap = array();
......
...@@ -65,8 +65,17 @@ Flight::route('GET ' . $WS_PREFIX . '/user', function() { ...@@ -65,8 +65,17 @@ Flight::route('GET ' . $WS_PREFIX . '/user', function() {
$locator->getOAuth2RequestHandler()->validateToken(); $locator->getOAuth2RequestHandler()->validateToken();
$searchText = Flight::request()->query['search']; $searchText = Flight::request()->query['search'];
if ($searchText !== null) {
$users = $locator->getUserDAO()->searchUser($searchText); $users = $locator->getUserDAO()->searchUser($searchText);
} else {
$identifiers = Flight::request()->query['identifiers'];
if ($identifiers === null) {
throw new \RAP\BadRequestException("Missing identifiers parameters");
}
$identifiers = explode(',', $identifiers);
$users = $locator->getUserDAO()->getUsers($identifiers);
}
Flight::json($users); Flight::json($users);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment