示例#1
0
 /**
  * This function stores the options of the questions in the table
  *
  * @param array $form_content
  * @author Patrick Cool <*****@*****.**>, Ghent University
  * @version January 2007
  *
  * @todo writing the update statement when editing a question
  */
 public function save_question_options($form_content, $survey_data)
 {
     $course_id = api_get_course_int_id();
     // A percentage question type has options 1 -> 100
     if ($form_content['type'] == 'percentage') {
         for ($i = 1; $i < 101; $i++) {
             $form_content['answers'][] = $i;
         }
     }
     if (is_numeric($survey_data['survey_share']) && $survey_data['survey_share'] != 0) {
         survey_manager::save_shared_question_options($form_content, $survey_data);
     }
     // Table definition
     $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
     // We are editing a question so we first have to remove all the existing options from the database
     if (is_numeric($form_content['question_id'])) {
         $sql = "DELETE FROM {$table_survey_question_option}\n\t\t\t        WHERE c_id = {$course_id} AND question_id = '" . Database::escape_string($form_content['question_id']) . "'";
         Database::query($sql);
     }
     $counter = 1;
     if (is_array($form_content['answers'])) {
         //foreach ($form_content['answers'] as $key => $answer) {
         for ($i = 0; $i < count($form_content['answers']); $i++) {
             $sql = "INSERT INTO {$table_survey_question_option} (c_id, question_id, survey_id, option_text, value,sort) VALUES (\n                            {$course_id},\n                            '" . Database::escape_string($form_content['question_id']) . "',\n                            '" . Database::escape_string($form_content['survey_id']) . "',\n                            '" . Database::escape_string($form_content['answers'][$i]) . "',\n                            '" . Database::escape_string($form_content['values'][$i]) . "',\n                            '" . Database::escape_string($counter) . "')";
             Database::query($sql);
             $counter++;
         }
     }
 }