Esempio n. 1
0
 function save_questions($quiz_id, $question_arr)
 {
     if (!$quiz_id || !$question_arr) {
         return false;
     }
     $question_ids = array();
     foreach ($question_arr as $question) {
         $question_id = $question['id'];
         $question_ids[] = $question_id;
         if ($question_id) {
             he_quiz::update_question($question['id'], $question['text']);
         } else {
             $question_id = he_quiz::create_question($quiz_id, $question['text']);
             $question_ids[] = $question_id;
         }
         $photo = $question['filename'];
         if (isset($_FILES[$photo]['error']) && $_FILES[$photo]['error'] == 0) {
             $tmp_file = $_FILES[$photo];
             he_quiz::save_photo($question_id, $tmp_file, 'question', $photo, 200);
         }
         foreach ($question['answers'] as $answer) {
             $answer_id = $answer['id'];
             if ($answer_id) {
                 he_quiz::update_answer($answer_id, $answer['label']);
             } else {
                 $answer_id = he_quiz::create_answer($question_id, $answer['result_id'], $answer['label']);
             }
         }
     }
     if (!$question_ids) {
         return false;
     }
     $question_str = implode(', ', $question_ids);
     //get removed questions
     $query = he_database::placeholder("SELECT `id` FROM `se_he_quiz_question`\r\n            WHERE `id` NOT IN ({$question_str}) AND `quiz_id`=?", $quiz_id);
     $removed_ids = he_database::fetch_column($query);
     he_quiz::delete_questions($removed_ids);
 }