public function actionCreateQuestionLib() { $question_cat_id = $_REQUEST["question_cat_id"]; $question_type = $_REQUEST["question_type"]; $question_text = $_REQUEST["question_text"]; $question_true = $_REQUEST["answerTrue"]; $AnswerList = $_REQUEST["answerA"]; $model = new WQuestionLib(); $model->question_text = $question_text; $model->question_type = $question_type; $model->question_cat_id = $question_cat_id; $model->status = 1; $model->created_by = Yii::app()->user->id; $idQuestion = ""; if ($model->save()) { $idQuestion = $model->id; if ($question_type != 2) { if (!empty($AnswerList)) { //neu la nhieu dap an $dataAnswTrue = array(); if ($question_type != 2 and !empty($question_true)) { $dataAnswTrue = explode(",", $question_true); unset($dataAnswTrue[count($dataAnswTrue) - 1]); } foreach ($AnswerList as $key => $itemAns) { $modelAnsw = new WQuestionAnswerLib(); $modelAnsw->answer = $itemAns; $modelAnsw->question_id = $idQuestion; if ($question_type != 2) { if (in_array($key, $dataAnswTrue)) { $modelAnsw->is_correct_answer = 1; } else { $modelAnsw->is_correct_answer = 0; } } $modelAnsw->save(); } } } echo json_encode(array("result" => "true", "id" => $idQuestion)); } else { echo json_encode(array("result" => "false", "message" => "Lỗi thao tác, Mời bạn thao tác lại")); } }