mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Created getinfosMultiple users method
This commit is contained in:
parent
0b01b666fd
commit
0694456217
@ -86,6 +86,35 @@ class userController
|
|||||||
return array($userInfos);
|
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
|
* Get current user infos using tokens
|
||||||
*
|
*
|
||||||
|
@ -165,6 +165,40 @@ class User{
|
|||||||
return $this->generateUserInfosArray($userInfos[0]);
|
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
|
* Generate and return an array containing informations about a user
|
||||||
* given the database entry
|
* given the database entry
|
||||||
|
Loading…
Reference in New Issue
Block a user