From bc8b3dc0a2484516a29a28ba3f1c4bef0fe5fee9 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 27 May 2017 15:11:17 +0200 Subject: [PATCH] Get multiple users infos --- RestControllers/userController.php | 15 ++++++++++----- classes/user.php | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/RestControllers/userController.php b/RestControllers/userController.php index 09f55a8..5bb6bc9 100644 --- a/RestControllers/userController.php +++ b/RestControllers/userController.php @@ -67,7 +67,7 @@ class userController * @return array The result */ public function getUserInfos() : array{ - user_login_required(); + user_login_required();sleep(5); //Determine userID if(!isset($_POST['userID'])) @@ -100,19 +100,24 @@ class userController Rest_fatal_error(400, "Please specify user ID !"); $usersID = array(); - foreach(json_decode($_POST['usersID']) as $userID){ - $usersID[] = $userID*1; + foreach(explode(",", $_POST['usersID']) as $userID){ + if($userID*1 > 0) + $usersID[$userID*1] = $userID*1; } + //Check for errors + if(count($userID) == 0) + Rest_fatal_error(400, "No user ID were specified!"); + //Try to get user infos - $userInfos = CS::get()->user->getUserInfos($userID); + $userInfos = CS::get()->user->getMultipleUserInfos($usersID); //Check if response is empty if(count($userInfos) == 0) throw new RestException(401, "Couldn't get user data (maybe user doesn't exists) !"); //Return result - return array($userInfos); + return $userInfos; } /** diff --git a/classes/user.php b/classes/user.php index 121db38..ee70e19 100644 --- a/classes/user.php +++ b/classes/user.php @@ -174,12 +174,12 @@ class User{ public function getMultipleUserInfos(array $usersID) : array { //Prepare database request $tablesName = "utilisateurs"; - $conditions = "WHERE "; + $conditions = "WHERE (utilisateurs.ID < 0)"; $conditionsValues = array(); //Process users foreach($usersID as $i=>$process){ - $conditions.= ($i==0 ? "" : " OR ")."utilisateurs.ID = ?"; + $conditions .= " OR utilisateurs.ID = ?"; $conditionsValues[] = $process; } @@ -191,7 +191,7 @@ class User{ return array(); //No result //Process result - foreach($userInfos as $processUser){ + foreach($usersInfos as $processUser){ $result[$processUser['ID']] = $this->generateUserInfosArray($processUser); }