Can create survey

This commit is contained in:
Pierre
2018-01-07 19:06:01 +01:00
parent d3fa9f5127
commit f4620717c2
2 changed files with 50 additions and 2 deletions

View File

@ -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
*