Created getinfosMultiple users method

This commit is contained in:
Pierre 2017-05-27 14:09:05 +02:00
parent 0b01b666fd
commit 0694456217
2 changed files with 63 additions and 0 deletions

View File

@ -86,6 +86,35 @@ class userController
return array($userInfos);
}
/**
* Get multiple users informations
*
* @url POST /user/getInfosMultiple
* @return array The result
*/
public function getMultipleUserInfos() : array{
user_login_required();
//Determine userID
if(!isset($_POST['usersID']))
Rest_fatal_error(400, "Please specify user ID !");
$usersID = array();
foreach(json_decode($_POST['usersID']) as $userID){
$usersID[] = $userID*1;
}
//Try to get user infos
$userInfos = CS::get()->user->getUserInfos($userID);
//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);
}
/**
* Get current user infos using tokens
*

View File

@ -165,6 +165,40 @@ class User{
return $this->generateUserInfosArray($userInfos[0]);
}
/**
* Get Multiple Users Infos
*
* @param Array $usersID The users ID
* @return Array The result of the function (user informations) (empty one if it fails)
*/
public function getMultipleUserInfos(array $usersID) : array {
//Prepare database request
$tablesName = "utilisateurs";
$conditions = "WHERE ";
$conditionsValues = array();
//Process users
foreach($usersID as $i=>$process){
$conditions.= ($i==0 ? "" : " OR ")."utilisateurs.ID = ?";
$conditionsValues[] = $process;
}
//Perform request
$usersInfos = CS::get()->db->select($tablesName, $conditions, $conditionsValues);
//Check if result is correct or not
if(count($usersInfos) == 0)
return array(); //No result
//Process result
foreach($userInfos as $processUser){
$result[$processUser['ID']] = $this->generateUserInfosArray($processUser);
}
//Return result
return $result;
}
/**
* Generate and return an array containing informations about a user
* given the database entry