mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-06-18 16:18:04 +00:00
Response to a survey can be saved.
This commit is contained in:
@ -30,6 +30,39 @@ class surveysController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a response to a survey
|
||||
*
|
||||
* @url POST /surveys/send_response
|
||||
*/
|
||||
public function send_response(){
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Get the ID of the survey
|
||||
$surveyID = $this->getSurveyIDFromPostID("postID");
|
||||
|
||||
//Get the ID of the response of the user
|
||||
if(!isset($_POST['choiceID']))
|
||||
Rest_fatal_error(401, "Please specify the ID of your choice in your request!");
|
||||
$choiceID = (int) $_POST['choiceID'];
|
||||
|
||||
//Try to cancel the user's previous response to the survey
|
||||
if(!components()->survey->cancel_response($surveyID, userID))
|
||||
Rest_fatal_error(500, "Couldn't cancel user previous response to the survey !");
|
||||
|
||||
//Check if the user choice exists or not
|
||||
if(!components()->survey->choice_exists($surveyID, $choiceID))
|
||||
Rest_fatal_error(404, "Specified response does not exists!");
|
||||
|
||||
//Save the answer
|
||||
if(!components()->survey->send_response(userID, $surveyID, $choiceID))
|
||||
Rest_fatal_error(500, "An error occured while trying to save response to the survey!");
|
||||
|
||||
//Success
|
||||
return array("success" => "User response has been saved!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of a survey from a $_POST ID
|
||||
*
|
||||
|
Reference in New Issue
Block a user