mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-26 05:28:57 +00:00
Can create survey
This commit is contained in:
parent
d3fa9f5127
commit
f4620717c2
@ -249,7 +249,7 @@ class Posts {
|
||||
*
|
||||
* @param string $kind_page The kind of target page
|
||||
* @param int $kind_page_id The ID of the target page
|
||||
* @param int $userID The ID of the user creating for post
|
||||
* @param int $userID The ID of the user creating the post
|
||||
* @param string $content The content of the post
|
||||
* @param int $visibility The visibility of the post
|
||||
* @param string $kind The kind of post
|
||||
@ -338,7 +338,7 @@ class Posts {
|
||||
|
||||
//Create the survey if required
|
||||
if($kind == $this::POST_KIND_SURVEY){
|
||||
|
||||
CS::get()->components->survey->create($postID, $userID, $survey_question, $survey_answers);
|
||||
}
|
||||
|
||||
return $postID;
|
||||
|
@ -22,6 +22,54 @@ class Survey {
|
||||
*/
|
||||
const SURVEY_RESPONSE_TABLE = "sondage_reponse";
|
||||
|
||||
/**
|
||||
* Create a new survey
|
||||
*
|
||||
* @param int $postID The target post for the survey
|
||||
* @param int $userID The ID of the user creating the survey
|
||||
* @param string $question The question for the survey
|
||||
* @param array $answers The answers for the survey
|
||||
* @return bool True for a sucess / False for a failure
|
||||
*/
|
||||
public function create(int $postID, int $userID, string $question, array $answers) : bool {
|
||||
|
||||
//Create the main survey informations
|
||||
$main_infos = array(
|
||||
"ID_utilisateurs" => $userID,
|
||||
"ID_texte" => $postID,
|
||||
"date_creation" => mysql_date(),
|
||||
"question" => $question
|
||||
);
|
||||
|
||||
//Try to create survey main informations table
|
||||
if(!CS::get()->db->addLine($this::SURVEY_INFOS_TABLE, $main_infos))
|
||||
return false;
|
||||
|
||||
//Get the ID of the survey
|
||||
$surveyID = CS::get()->db->getLastInsertedID();
|
||||
|
||||
//Check for errors
|
||||
if($surveyID < 1)
|
||||
return false;
|
||||
|
||||
//Process each answer
|
||||
$answers_data = array();
|
||||
foreach($answers as $line){
|
||||
$answers_data[] = array(
|
||||
"ID_sondage" => $surveyID,
|
||||
"date_creation" => mysql_date(),
|
||||
"Choix" => $line
|
||||
);
|
||||
}
|
||||
|
||||
//Insert all the answers
|
||||
CS::get()->db->addLines($this::SURVEY_CHOICES_TABLE, $answers_data);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get informations about a survey
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user