Ejemplo n.º 1
0
 /**
  * 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.');
     }
 }
Ejemplo n.º 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;
Ejemplo n.º 3
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']);
 }