/**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete()
 {
     $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
     $model = $this->loadModel($id);
     $arrJson = array();
     WTest::updatePoint($model['test_id'], $model['point']);
     if (WQuestionAnswer::deleteQuesAns($id) && $this->loadModel($id)->delete()) {
         $arrJson = array('status' => true, 'msg' => 'Success');
     } else {
         $arrJson = array('status' => false, 'msg' => 'UnSuccess');
     }
     echo CJSON::encode($arrJson);
     exit;
 }
 public static function getIDAnswerCorrect($question_id)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'question_id=:question_id and is_correct_answer=:is_correct_answer';
     $criteria->params = array(':question_id' => $question_id, ':is_correct_answer' => 1);
     $rs = WQuestionAnswer::model()->findAll($criteria);
     if ($rs) {
         $arrId = array();
         foreach ($rs as $r) {
             $arrId[] = $r['id'];
         }
         return $arrId;
     } else {
         return null;
     }
 }
Example #3
0
                            echo "(correct)";
                        }
                        ?>
</span></p>
                                            <?php 
                    }
                    $k++;
                }
            } elseif ($ques['question_type'] == 2) {
                ?>
                                        <div class="view_answer" style="margin-top: 10px;">
                                            <textarea disabled="disabled" class="form-control" rows="2" placeholder="Type your answer" style="width:600px;"></textarea>
                                        </div>
                                        <?php 
            } elseif ($ques['question_type'] == 4) {
                $arrAns = WQuestionAnswer::getAnswerByQuesId($ques['id']);
                $k = 1;
                foreach ($arrAns as $ans) {
                    if ($ans['answer'] != '') {
                        ?>
                                            <p><input type="checkbox" disabled="disabled" <?php 
                        if ($ans['is_correct_answer'] == 1) {
                            echo "checked";
                        }
                        ?>
 /> <b style="text-transform: uppercase;"><?php 
                        echo chr(($k - 1) % 26 + 97) . '. ';
                        ?>
</b> <?php 
                        echo $ans['answer'];
                        ?>
 public function loadModelQuestionAnswer($id)
 {
     $model = WQuestionAnswer::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
<?php

if (isset($question)) {
    $k = 1;
    foreach ($question as $q) {
        if ($q->test->if_random == 0) {
            $arrAs = WQuestionAnswer::model()->findAll('question_id=:question_id', array(':question_id' => $q['id']));
        } else {
            $arrAs = WQuestionAnswer::model()->findAll('question_id=:question_id order by rand()', array(':question_id' => $q['id']));
        }
        if ($q['question_type'] == 1 || $q['question_type'] == 2) {
            $ua = WUserAnswers::getIDTextAnswer($q['id'], $user_test_id, $q['question_type']);
        } else {
            $arrUA = WUserAnswers::getIDAnswer($q['id'], $user_test_id);
        }
        ?>
<div id='question<?php 
        echo $page_number;
        ?>
' class='cont'>
    <div class="cont1">
        <p class='questions' id="qname<?php 
        echo $page_number;
        ?>
"> <?php 
        echo '<b>Question ' . $page_number . '</b> (' . $q['point'] . ' points)';
        ?>
: <br /><?php 
        echo $q['question_text'];
        ?>
</p>