mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 22:09:29 +00:00
Get multiple users infos
This commit is contained in:
parent
0694456217
commit
bc8b3dc0a2
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user