]" value="<?php echo $ans['id']; ?> " /> <b style="text-transform: uppercase;"><?php echo chr(($k - 1) % 26 + 97) . '. '; ?> </b> <?php echo $ans['answer']; ?> </p> <?php $k++; } } } elseif ($ques['question_type'] == 2) { $UA = WUserAnswers::getIDTextAnswer($ques['id'], $user_test_id, $ques['question_type']); if (!isset($UA)) { $UA = $answer; } ?> <div class="view_answer" style="margin-top: 10px;"> <textarea class="form-control" rows="2" placeholder="Type your answer" name="txtFree[<?php echo $i; ?> ]" style="width:600px;"><?php echo $UA; ?> </textarea> </div> <?php } elseif ($ques['question_type'] == 4) {
public function actionDoingtest() { $per_page = 1; $page_number = isset($_POST['page']) ? $_POST['page'] : 0; //echo $page_number; $test_id = isset($_POST['test_id']) ? $_POST['test_id'] : ''; $course_id = isset($_POST['course_id']) ? $_POST['course_id'] : ''; $lecture_id = isset($_POST['lecture_id']) ? $_POST['lecture_id'] : ''; $oneUT = WUserTest::model()->find('test_id=:test_id and course_id=:course_id and lecture_id=:lecture_id and user_id=:user_id', array(':test_id' => $test_id, ':course_id' => $course_id, ':lecture_id' => $lecture_id, ':user_id' => Yii::app()->user->id)); $position = ($page_number - 1) * $per_page; $total = WQuestion::totalQuestion($test_id); $pagination = WFunction::paging_question($total, $per_page); $question = WQuestion::listQuestion($test_id, $position, $per_page); $nameButton = isset($_POST['nameButton']) ? $_POST['nameButton'] : ''; $UA = ''; $arrUA = array(); if ($nameButton == 'next') { $ques_type = isset($_POST['question_type']) ? $_POST['question_type'] : ''; $ques_id = isset($_POST['question_id']) ? $_POST['question_id'] : ''; $point = isset($_POST['point']) ? $_POST['point'] : ''; $total_point = $oneUT['pass_score_point']; if ($ques_type == 1) { $answer = $_POST['rdAns']; //echo $answer;exit(); if ($answer != '') { $modelUserAnswers = new WUserAnswers(); $modelUserAnswers->user_test_id = $oneUT['id']; $modelUserAnswers->question_id = $ques_id; $modelUserAnswers->answer_id = $answer; $modelUserAnswers->user_answer_id = $answer; $modelUserAnswers->user_answer_text = ''; $modelUserAnswers->created_date = date('Y-m-d H:i:s'); $oneAns = WUserAnswers::model()->find('user_test_id=:user_test_id and question_id=:question_id', array(':user_test_id' => $oneUT['id'], ':question_id' => $ques_id)); if (is_null($oneAns)) { $modelUserAnswers->save(); //Yii::app()->session['ans_id'.$ques_id] = $modelUserAnswers->id; } else { //echo $oneAns['id'];exit(); //$modelUserAnswers->updateByPk($oneAns['id'], array($answer)); WUserAnswers::updateUA($oneAns['id'], $answer); } if (WUserAnswers::checkAnswer($ques_id, $ques_type)) { $point_user = $point + $total_point; } else { $point_user = $total_point; } WUserTest::updatePointTrainee($test_id, $course_id, Yii::app()->user->id, $point_user, $ques_type); } else { } } elseif ($ques_type == 4) { $stranswer = $_POST['chkAns']; $answers = explode(',', $stranswer); //var_dump($answers); exit(); $modelUserAnswersM = new WUserAnswers(); if (count($answers) > 0) { $arrValues = array(); foreach ($answers as $a) { //echo $a.' '.$ques_id;exit(); //$modelUserAnswersM->user_test_id = $oneUT['id']; // $modelUserAnswersM->question_id = $ques_id; // $modelUserAnswersM->answer_id = $a; // $modelUserAnswersM->user_answer_id = $a; // $modelUserAnswersM->user_answer_text = ''; // $modelUserAnswersM->created_date = date('Y-m-d H:i:s'); // $oneAns1 = WUserAnswers::model()->find( // 'user_test_id=:user_test_id and // question_id=:question_id and // answer_id=:answer_id', // array( // ':user_test_id'=> $oneUT['id'], // ':question_id' => $ques_id, // ':answer_id'=> $a // )); // if(isset($oneAns1)){ // $modelUserAnswersM->save(); // }else{ // WUserAnswers::updateUA($oneAns1['id'], $a); // } $arrValues[] = '("", ' . $oneUT['id'] . ', ' . $ques_id . ', ' . $a . ', ' . $a . ', "", "' . date("Y-m-d H:i:s") . '")'; } $sql = "INSERT INTO {{user_answers}} (`id`, `user_test_id`, `question_id`, `answer_id`, `user_answer_id`, `user_answer_text`, `created_date`) VALUES " . implode(',', $arrValues) . ""; WUserAnswers::insertAnswerM($sql); if (WUserAnswers::checkAnswer($ques_id, $ques_type)) { $point_user = $point + $total_point; } else { $point_user = $total_point; } WUserTest::updatePointTrainee($test_id, $course_id, Yii::app()->user->id, $point_user, $ques_type); } } elseif ($ques_type == 2) { $answer = $_POST['txtFree']; if ($answer != '') { $modelUserAnswers = new WUserAnswers(); $modelUserAnswers->user_test_id = $oneUT['id']; $modelUserAnswers->question_id = $ques_id; $modelUserAnswers->answer_id = ''; $modelUserAnswers->user_answer_id = ''; $modelUserAnswers->user_answer_text = $answer; $modelUserAnswers->created_date = date('Y-m-d H:i:s'); $oneAns = WUserAnswers::model()->find('user_test_id=:user_test_id and question_id=:question_id', array(':user_test_id' => $oneUT['id'], ':question_id' => $ques_id)); if (is_null($oneAns)) { $modelUserAnswers->save(); } else { WUserAnswers::updateUA($oneAns['id'], $answer); } } } WUserTest::updateStatusTest($test_id, $course_id, 1); } elseif ($nameButton == 'previous') { $ques_id = isset($_POST['question_id']) ? $_POST['question_id'] : ''; $ques_type = isset($_POST['question_type']) ? $_POST['question_type'] : ''; if ($ques_type == 1 || $ques_type == 2) { $UA = WUserAnswers::getIDTextAnswer($ques_id, $oneUT['id'], $ques_type); //echo $UA;exit(); } else { $arrUA = WUserAnswers::getIDAnswer($ques_id, $oneUT['id']); } } elseif ($nameButton == 'finished') { $ques_type = isset($_POST['question_type']) ? $_POST['question_type'] : ''; $ques_id = isset($_POST['question_id']) ? $_POST['question_id'] : ''; $point = isset($_POST['point']) ? $_POST['point'] : ''; $total_point = $oneUT['pass_score_point']; if ($ques_type == 1) { $answer = $_POST['rdAns']; if ($answer != '') { $modelUserAnswers = new WUserAnswers(); $modelUserAnswers->user_test_id = $oneUT['id']; $modelUserAnswers->question_id = $ques_id; $modelUserAnswers->answer_id = $answer; $modelUserAnswers->user_answer_id = $answer; $modelUserAnswers->user_answer_text = ''; $modelUserAnswers->created_date = date('Y-m-d H:i:s'); $oneAns = WUserAnswers::model()->find('user_test_id=:user_test_id and question_id=:question_id', array(':user_test_id' => $oneUT['id'], ':question_id' => $ques_id)); if (is_null($oneAns)) { $modelUserAnswers->save(); //Yii::app()->session['ans_id'.$ques_id] = $modelUserAnswers->id; } else { //echo $oneAns['id'];exit(); //$modelUserAnswers->updateByPk($oneAns['id'], array($answer)); WUserAnswers::updateUA($oneAns['id'], $answer); } if (WUserAnswers::checkAnswer($ques_id, $ques_type)) { $point_user = $total_point + $point; } else { $point_user = $total_point; } WUserTest::updatePointTrainee($test_id, $course_id, Yii::app()->user->id, $point_user, $ques_type); } else { } } elseif ($ques_type == 4) { $stranswer = $_POST['chkAns']; $answermm = explode(',', $stranswer); $modelUserAnswersMM = new WUserAnswers(); if (count($answermm) > 0) { $arrValues = array(); foreach ($answermm as $a) { //$modelUserAnswersMM->user_test_id = $oneUT['id']; // $modelUserAnswersMM->question_id = $ques_id; // $modelUserAnswersMM->answer_id = $a; // $modelUserAnswersMM->user_answer_id = $a; // $modelUserAnswersMM->user_answer_text = ''; // $modelUserAnswersMM->created_date = date('Y-m-d H:i:s'); $arrValues[] = '("", ' . $oneUT['id'] . ', ' . $ques_id . ', ' . $a . ', ' . $a . ', "" , "' . date("Y-m-d H:i:s") . '")'; //$oneAns2 = WUserAnswers::model()->find('user_test_id=:user_test_id and question_id=:question_id and answer_id=:answer_id', array(':user_test_id'=> $oneUT['id'], ':question_id' => $ques_id, ':answer_id'=> $a)); // if(is_null($oneAns2)){ // // $modelUserAnswersMM->save(); // // }else{ // WUserAnswers::updateUA($oneAns2['id'], $a); // } } $sql = "INSERT INTO {{user_answers}} (`id`, `user_test_id`, `question_id`, `answer_id`, `user_answer_id`, `user_answer_text`, `created_date`) VALUES " . implode(',', $arrValues) . ""; WUserAnswers::insertAnswerM($sql); if (WUserAnswers::checkAnswer($ques_id, $ques_type)) { $point_user = $total_point + $point; } else { $point_user = $total_point; } WUserTest::updatePointTrainee($test_id, $course_id, Yii::app()->user->id, $point_user, $ques_type); } } elseif ($ques_type == 2) { $answer = $_POST['txtFree']; if ($answer != '') { $modelUserAnswers = new WUserAnswers(); $modelUserAnswers->user_test_id = $oneUT['id']; $modelUserAnswers->question_id = $ques_id; $modelUserAnswers->answer_id = ''; $modelUserAnswers->user_answer_id = ''; $modelUserAnswers->user_answer_text = $answer; $modelUserAnswers->created_date = date('Y-m-d H:i:s'); $oneAns = WUserAnswers::model()->find('user_test_id=:user_test_id and question_id=:question_id', array(':user_test_id' => $oneUT['id'], ':question_id' => $ques_id)); if (is_null($oneAns)) { $modelUserAnswers->save(); } else { WUserAnswers::updateUA($oneAns['id'], $answer); } } } $url = Yii::app()->params->url_base . '/index.php?r=wTest/result&test_id=' . $test_id . '&course_id=' . $course_id . '&lecture_id=' . $lecture_id . '&total=' . $total; echo "<script type='text/javascript'>top.location.href = '{$url}';</script>"; exit; } else { $ques1 = $question[0]; if ($ques1['question_type'] == 1 || $ques1['question_type'] == 2) { $UA = WUserAnswers::getIDTextAnswer($ques1['id'], $oneUT['id'], $ques1['question_type']); //echo $UA;exit(); } else { $arrUA = WUserAnswers::getIDAnswer($ques1['id'], $oneUT['id']); } } $html = $this->renderPartial('/wTest/trainee/_doingtest', array('question' => $question, 'ua' => $UA, 'arrUA' => $arrUA, 'page_number' => $page_number, 'total' => $total, 'test_id' => $test_id, 'course_id' => $course_id, 'lecture_id' => $lecture_id)); echo $html; exit; }