Esempio n. 1
0
            // If the post value key contains the string 'question' then it is an answer to a question
            if (strpos($key, 'question') !== false) {
                // Finding the question id by removing 'question'
                $survey_question_id = str_replace('question', '', $key);
                // We select the correct answer and the puntuacion
                $sql = "SELECT value FROM $table_survey_question_option
                        WHERE c_id = $course_id AND question_option_id='".intval($value)."'";
                $result = Database::query($sql);
                $row = Database::fetch_array($result, 'ASSOC');
                $option_value = $row['value'];
                //$option_value = 0;
                $survey_question_answer = $value;
                // We save the answer after making sure that a possible previous attempt is deleted
                SurveyUtil::remove_answer(
                    $survey_invitation['user'],
                    $survey_invitation['survey_id'],
                    $survey_question_id,
                    $course_id
                );

                SurveyUtil::store_answer(
                    $survey_invitation['user'],
                    $survey_invitation['survey_id'],
                    $survey_question_id,
                    $value,
                    $option_value,
                    $survey_data
                );
            }
        }
    } else {
        // In case it's another type than 0 or 1