2017-05-28 12:09:20 +00:00
|
|
|
<?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
|
2017-05-31 14:49:25 +00:00
|
|
|
$friendsList = CS::get()->components->friends->getList(userID);
|
2017-05-28 12:09:20 +00:00
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if($friendsList === false)
|
|
|
|
Rest_fatal_error(500, "Couldn't get friends list !");
|
|
|
|
|
|
|
|
//Return list
|
|
|
|
return $friendsList;
|
|
|
|
}
|
|
|
|
|
2017-06-04 14:36:12 +00:00
|
|
|
/**
|
|
|
|
* Respond to a friendship request
|
|
|
|
*
|
|
|
|
* @url POST /friends/respondRequest
|
|
|
|
*/
|
|
|
|
public function respondRequest(){
|
|
|
|
user_login_required(); //Login required
|
|
|
|
|
|
|
|
//Check parametres
|
|
|
|
if(!isset($_POST["friendID"]) OR !isset($_POST['accept']))
|
2017-06-19 08:36:39 +00:00
|
|
|
Rest_fatal_error(400, "Please check your parametres !");
|
2017-06-04 14:36:12 +00:00
|
|
|
|
|
|
|
//Extract informations and process request
|
2017-06-18 08:07:52 +00:00
|
|
|
$friendID = toInt($_POST['friendID']);
|
2017-06-04 14:36:12 +00:00
|
|
|
$acceptRequest = $_POST['accept'] == "true";
|
|
|
|
|
|
|
|
//Try to perform request
|
|
|
|
$result = CS::get()->components->friends->respondRequest(userID, $friendID, $acceptRequest);
|
|
|
|
|
|
|
|
//Return result
|
|
|
|
if($result != true)
|
|
|
|
Rest_fatal_error(500, "Couldn't respond to friendship request !");
|
|
|
|
|
|
|
|
//Else it is a success
|
|
|
|
return array("success" => "A response was given to friendship request !");
|
|
|
|
}
|
|
|
|
|
2017-05-28 12:09:20 +00:00
|
|
|
}
|