Example #1
0
 public function actionEditExam($id)
 {
     $exam = Exam::findOne(['id' => $id]);
     $examType = \common\models\ExamType::findAll(['exam_id' => $id]);
     $examTypeArr = [];
     if (!empty($examType)) {
         foreach ($examType as $examTypeVal) {
             $examTypeArr[] = $examTypeVal['name'];
         }
     }
     $examSec = \common\models\ExamSection::findAll(['exam_id' => $id]);
     $examSecArr = [];
     if (!empty($examSec)) {
         foreach ($examSec as $examSecVal) {
             $examSecArr[] = $examSecVal['name'];
         }
     }
     $model = new \common\models\ExamForm();
     $model->attributes = $exam->attributes;
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         $model->editExam($id);
         \Yii::$app->session->setFlash('success', 'Exam Added Successfully');
         return $this->redirect(['/exam']);
     }
     return $this->render('edit-exam', ['model' => $model, 'examTypeArr' => $examTypeArr, 'examSecArr' => $examSecArr]);
 }
Example #2
0
 public function saveExamSection($exam)
 {
     $exam_section = $this->exam_section;
     foreach ($exam_section as $value) {
         $model = new ExamSection();
         $model->name = $value;
         $model->exam_id = $exam->id;
         $res = ExamSection::findOne(['name' => $value, 'exam_id' => $exam->id]);
         if ($model->validate()) {
             if (empty($res)) {
                 $model->save();
             }
         } else {
             foreach ($model->errors as $key => $value) {
                 $this->addError($key, $model->getFirstError($key));
             }
         }
     }
     return $model;
 }