mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 13:59:29 +00:00
Can respond to call
This commit is contained in:
parent
8d004e80f5
commit
d1be731fb4
@ -85,6 +85,50 @@ class CallsController {
|
||||
return self::CallInformationToAPI($call);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to a call
|
||||
*
|
||||
* @url POST /calls/respond
|
||||
*/
|
||||
public function respondToCall(){
|
||||
user_login_required();
|
||||
|
||||
//Get target call ID
|
||||
$call_id = $this->GetSafeCallIDFromRequest("call_id");
|
||||
|
||||
//Get target response
|
||||
$accept = postBool("accept");
|
||||
|
||||
//Set user response to call
|
||||
if(!components()->calls->setMemberResponse($call_id, userID, $accept))
|
||||
Rest_fatal_error(500, "Could not set response of user to call!");
|
||||
|
||||
return array(
|
||||
"success" => "User response to call has been successfully set!"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get safely the ID of a call from the request
|
||||
*
|
||||
* @param $name The name of the POST field containing call ID
|
||||
* @return int The ID of the call
|
||||
*/
|
||||
private function GetSafeCallIDFromRequest(string $name) : int {
|
||||
|
||||
//Get call ID
|
||||
$call_id = postInt($name);
|
||||
|
||||
if($call_id < 1)
|
||||
Rest_fatal_error(401, "Invalid call id !");
|
||||
|
||||
//Check if the user belongs to the call or not
|
||||
if(!components()->calls->doesUserBelongToCall($call_id, userID))
|
||||
Rest_fatal_error(401, "You do not belong to this call!");
|
||||
|
||||
return $call_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a CallsConfig object into an API entry
|
||||
*
|
||||
|
@ -220,6 +220,21 @@ class CallsComponents {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether a user belongs to a call or not
|
||||
*
|
||||
* @param $callID The ID of the target call
|
||||
* @param $userID The ID of the target user
|
||||
* @return bool TRUE if the user belongs to the call / FALSE else
|
||||
*/
|
||||
public function doesUserBelongToCall(int $callID, int $userID) : bool {
|
||||
return db()->count(
|
||||
self::CALLS_MEMBERS_TABLE,
|
||||
"WHERE call_id = ? AND user_id = ?",
|
||||
array($callID, $userID)
|
||||
) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response of a member to a call
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user