Example #1
0
echo DetailView::widget(['model' => $model, 'attributes' => ['Message', 'MaxScore', 'NumQuestions']]);
?>
    
    
    <?php 
$result = ExamStudent::findOne(['ExamId' => $id, 'StudentId' => Yii::$app->user->identity->UserID]);
if ($result) {
    echo '<h3>Score: ' . $result->Score . '</h3>';
} else {
    echo '<h2>Questions</h2> <br />';
    $i = 1;
    $questions = ExamQuestion::findAll(['ExamId' => $id]);
    $form = ActiveForm::begin(['method' => 'post', 'action' => 'index.php?r=exams%2Fsubmitexam']);
    foreach ($questions as $question) {
        echo '<p> #' . $i . '. ' . $question->Question . '</p>';
        $choices = ExamQuestionChoices::findAll(['ExamQuestionId' => $question->ExamQuestionId]);
        foreach ($choices as $choice) {
            echo '<input type="radio" name="' . $question->ExamQuestionId . '" id="' . $choice->ExamQuestionChoicesId . '" value="' . $choice->ExamQuestionChoicesId . '" /><label for="' . $choice->ExamQuestionChoicesId . '"> ' . $choice->ChoiceDescription . '</label><br />';
        }
        echo '<br /><br />';
        $i++;
    }
    echo '<input type="hidden" name="ExamId" value="' . $model->ExamId . '">';
    ?>
        
        <div class="form-group">
            <?php 
    echo Html::submitButton('I am finished!', ['class' => 'btn btn-success']);
    ?>
        </div>
        
Example #2
0
echo Html::encode($this->title);
?>
</h1>
    
    <?php 
$user = Yii::$app->user->identity;
$examstudent = new ExamStudent();
$examstudent->ExamId = $_POST['ExamId'];
$examstudent->StudentId = $user->UserID;
$sql = "SELECT MAX(ExamStudentId) AS ExamStudentId FROM exam_student";
$max_id = ExamStudent::findBySql($sql)->one();
$examstudent->ExamStudentId = $max_id->ExamStudentId + 1;
$score = 0;
foreach ($_POST as $name => $val) {
    if ($name != '_csrf' && $name != 'ExamId') {
        $choice = ExamQuestionChoices::findOne($val);
        if ($choice->IsRightChoice == 1) {
            $score++;
        }
    }
}
$examstudent->Score = $score;
$examstudent->save();
foreach ($_POST as $name => $val) {
    if ($name != '_csrf' && $name != 'ExamId') {
        $answer = new ExamStudentAnswer();
        $answer->ExamQuestionChoiceId = $val;
        $answer->UserId = $user->UserID;
        $sql2 = "SELECT MAX(ExamStudentAnswerId) AS ExamStudentAnswerId FROM exam_student_answer";
        $max_id2 = ExamStudentAnswer::findBySql($sql)->one();
        $answer->ExamStudentAnswerId = $max_id->ExamStudentAnswerId + 1;
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getExamQuestionChoices()
 {
     return $this->hasMany(ExamQuestionChoices::className(), ['ExamQuestionId' => 'ExamQuestionId']);
 }
 /**
  * Finds the ExamQuestionChoices model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Posts the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ExamQuestionChoices::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
0
 public function actionSubmitexam()
 {
     $user = Yii::$app->user->identity;
     $examstudent = new ExamStudent();
     $examstudent->ExamId = $_POST['ExamId'];
     $examstudent->StudentId = $user->UserID;
     $sql = "SELECT MAX(ExamStudentId) AS ExamStudentId FROM exam_student";
     $max_id = ExamStudent::findBySql($sql)->one();
     $examstudent->ExamStudentId = $max_id->ExamStudentId + 1;
     $score = 0;
     foreach (Yii::$app->request->post() as $name => $val) {
         if ($name != '_csrf' && $name != 'ExamId') {
             $choice = ExamQuestionChoices::findOne($val);
             if ($choice->IsRightChoice == 1) {
                 $score++;
             }
         }
     }
     $examstudent->Score = $score;
     $examstudent->save();
     foreach (Yii::$app->request->post() as $name => $val) {
         if ($name != '_csrf' && $name != 'ExamId') {
             $answer = new ExamStudentAnswer();
             $answer->ExamQuestionChoiceId = $val;
             $answer->UserId = $user->UserID;
             $sql2 = "SELECT MAX(ExamStudentAnswerId) AS ExamStudentAnswerId FROM exam_student_answer";
             $max_id2 = ExamStudentAnswer::findBySql($sql2)->one();
             $answer->ExamStudentAnswerId = $max_id2->ExamStudentAnswerId + 1;
             $answer->save();
         }
     }
     return $this->redirect(['/site/feed']);
 }