Exemplo n.º 1
0
 public function actionCheck($id)
 {
     $model = GivenTask::findOne($id);
     //$givenTask = $model->givenTask;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // return $this->redirect(['view', 'id' => $givenTask->status]);
     }
     //$exersices_all = CompleteExercise::find()->indexBy('id')->all();
     //Model::loadMultiple($model->exercises, Yii::$app->request->post()) && Model::validateMultiple($model->exercises);
     //$exersices_all = CompleteExercise::find()->indexBy('id')->all();
     $exercises = \common\models\GivenExercise::find()->where(['given_task_id' => $model->id])->indexBy('id')->all();
     if (Model::loadMultiple($exercises, Yii::$app->request->post()) && Model::validateMultiple($exercises)) {
         foreach ($exercises as $exersice) {
             if ($model->status == 3) {
                 $exersice->remake = 0;
             }
             $exersice->save(false);
         }
         //return $this->redirect('given-list');
     }
     $model = $this->findModel($id);
     $exersices = $model;
     return $this->renderAjax('_check_form', ['model' => $model, 'exercises' => $exercises]);
 }
 protected function findModelByExercise($id, $gid)
 {
     if (($model = GivenExercise::find()->where(['exercise_id' => $id])->andWhere(['given_task_id' => $gid])->one()) !== null) {
         return $model;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         GivenExercise::deleteAll(['given_task_id' => $this->id]);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 public function CTask($id)
 {
     $gtask = GivenTask::findOne($id);
     $exercises = ArrayHelper::getColumn($gtask->exercises, 'id');
     if (\common\models\GivenExerciseTestAnswers::find()->where(['in', 'given_exercise_id', $exercises]) || !GivenExercise::find()->where(['given_task_id' => $gtask->id])->andWhere(['solution' => ''])->all()) {
         $gtask->status = 1;
         $gtask->complete_date = date('U');
         $gtask->save();
         return false;
     }
     return true;
 }