예제 #1
0
        }
        foreach ($answer_data as $k => $v) {
            $answer->{$k} = $v;
        }
        $answer->points = intval($answer->points);
        $answers[] = $answer;
    }
    $question->put();
    foreach ($answers as $answer) {
        $answer->question_id = $question->id;
        $answer->test_id = $question->test_id;
        $answer->normalize();
        $answer->put_or_delete();
        if (!$answer->is_empty()) {
            $answer->normalize();
            $answer->put();
        }
    }
    jsdie("questionSaved", $question->id, $is_new);
}
if ($is_new) {
    $title = "Новый вопрос";
    $question = new Question();
    $question->id = 'new';
    $question->test_id = $_REQUEST['test_id'];
    $question->wakeup();
    $answers = array();
} else {
    if (!($question = Question::get("WHERE id = %s", $id))) {
        redirect("/", "Извините, этот вопрос уже удален.");
    }
예제 #2
0
 function add_question($test, $text, $answers)
 {
     if (!isset($test->question_count)) {
         $test->question_count = 0;
     }
     $question = new Question();
     $question->test_id = $test->id;
     $question->order = ++$test->question_count;
     $question->text = $text;
     $question->put();
     $question->all_answers = array();
     $answer_count = 0;
     foreach ($answers as $answer_text) {
         $answer = new Answer();
         $answer->question_id = $question->id;
         $answer->order = ++$answer_count;
         $answer->text = $answer_text;
         $answer->put();
         $question->all_answers[] = $answer;
     }
     $test->all_questions[] = $question;
 }