} $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("/", "Извините, этот вопрос уже удален."); } $title = "{$question->text}"; $answers = Answer::query("WHERE question_id = %s ORDER BY `order`", $question->id); }
<?php include '../lib/common.inc.php'; $test = new Test(); $test->name = trim($_REQUEST['name']); // validate $test->put(); jsdie('testCreated', $test->id);