mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 22:09:29 +00:00
Created friends class
This commit is contained in:
parent
d0eec49c4b
commit
3ad05483f5
29
RestControllers/friendsController.php
Normal file
29
RestControllers/friendsController.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Friends controller
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
class friendsController{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get friends list
|
||||||
|
*
|
||||||
|
* @url POST /friends/getList
|
||||||
|
*/
|
||||||
|
public function getFriendsList(){
|
||||||
|
user_login_required(); //Login required
|
||||||
|
|
||||||
|
//Try to get friends list
|
||||||
|
$friendsList = false;
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if($friendsList === false)
|
||||||
|
Rest_fatal_error(500, "Couldn't get friends list !");
|
||||||
|
|
||||||
|
//Return list
|
||||||
|
return $friendsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -64,57 +64,38 @@ class userController
|
|||||||
* Get informations about a user
|
* Get informations about a user
|
||||||
*
|
*
|
||||||
* @url POST /user/getInfos
|
* @url POST /user/getInfos
|
||||||
* @return array The result
|
|
||||||
*/
|
|
||||||
public function getUserInfos() : array{
|
|
||||||
user_login_required();sleep(5);
|
|
||||||
|
|
||||||
//Determine userID
|
|
||||||
if(!isset($_POST['userID']))
|
|
||||||
Rest_fatal_error(400, "Please specify user ID !");
|
|
||||||
|
|
||||||
$userID = $_POST['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 !");
|
|
||||||
|
|
||||||
//Return result
|
|
||||||
return array($userInfos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get multiple users informations
|
|
||||||
*
|
|
||||||
* @url POST /user/getInfosMultiple
|
* @url POST /user/getInfosMultiple
|
||||||
* @return array The result
|
* @return array The result
|
||||||
*/
|
*/
|
||||||
public function getMultipleUserInfos() : array{
|
public function getUserInfos() : array{
|
||||||
user_login_required();
|
user_login_required();
|
||||||
|
|
||||||
//Determine userID
|
//Determine userID
|
||||||
if(!isset($_POST['usersID']))
|
if(isset($_POST['userID'])){
|
||||||
Rest_fatal_error(400, "Please specify user ID !");
|
$usersID = array($_POST['userID']*1);
|
||||||
|
|
||||||
$usersID = array();
|
|
||||||
foreach(explode(",", $_POST['usersID']) as $userID){
|
|
||||||
if($userID*1 > 0)
|
|
||||||
$usersID[$userID*1] = $userID*1;
|
|
||||||
}
|
}
|
||||||
|
elseif(isset($_POST['usersID'])){
|
||||||
|
//Generate users ID list
|
||||||
|
$usersID = array();
|
||||||
|
foreach(explode(",", $_POST['usersID']) as $userID){
|
||||||
|
if($userID*1 > 0)
|
||||||
|
$usersID[$userID*1] = $userID*1;
|
||||||
|
}
|
||||||
|
|
||||||
//Check for errors
|
//Check for errors
|
||||||
if(count($userID) == 0)
|
if(count($userID) == 0)
|
||||||
Rest_fatal_error(400, "No user ID were specified!");
|
Rest_fatal_error(400, "No user ID were specified!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
//No ID specified
|
||||||
|
Rest_fatal_error(400, "Please specify at least one user ID !");
|
||||||
|
|
||||||
//Try to get user infos
|
//Try to get user infos
|
||||||
$userInfos = CS::get()->user->getMultipleUserInfos($usersID);
|
$userInfos = CS::get()->user->getMultipleUserInfos($usersID);
|
||||||
|
|
||||||
//Check if response is empty
|
//Check if response is empty
|
||||||
if(count($userInfos) == 0)
|
if(count($userInfos) == 0)
|
||||||
throw new RestException(401, "Couldn't get user data (maybe user doesn't exists) !");
|
throw new RestException(401, "Couldn't get user data !");
|
||||||
|
|
||||||
//Return result
|
//Return result
|
||||||
return $userInfos;
|
return $userInfos;
|
||||||
|
20
classes/components/friends.php
Normal file
20
classes/components/friends.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Friends component
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
class friends {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public construcor
|
||||||
|
*/
|
||||||
|
public function __construct(){
|
||||||
|
//Nothing now
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Register component
|
||||||
|
Components::register("friends", new friends());
|
@ -141,7 +141,7 @@ class User{
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get User Infos
|
* Get Single User Infos
|
||||||
*
|
*
|
||||||
* @param Integer $userID The user ID
|
* @param Integer $userID The user ID
|
||||||
* @return Array The result of the function (user informations) (empty one if it fails)
|
* @return Array The result of the function (user informations) (empty one if it fails)
|
||||||
|
Loading…
Reference in New Issue
Block a user