Пример #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;
     }
 }
Пример #3
0
 public static function updateGivenTask($post, $model)
 {
     $newExersices = $post['exersices'];
     foreach ($newExersices as $key => $ex) {
         $newExersices[$key] = (int) $ex;
     }
     $task = $post['task'];
     $given_date = date('U');
     $noerror = true;
     $model->given_date = $given_date;
     $model->task_id = $task;
     if ($model->save()) {
         $lastEx = ArrayHelper::getColumn($model->exercises, 'exercise.id');
         $generalEx = array_intersect($newExersices, $lastEx);
         $newLast = array_diff($lastEx, $generalEx);
         $newEx = array_diff($newExersices, $generalEx);
         sort($newLast);
         sort($newEx);
         foreach ($newEx as $newExerc) {
             $eModel = new GivenExercise();
             $eModel->exercise_id = $newExerc;
             $eModel->given_task_id = $model->getPrimaryKey();
             $eModel->save();
         }
         foreach ($newLast as $delLast) {
             $eModel = GivenExercise::find()->where(['given_task_id' => $model->getPrimaryKey()])->andWhere(['exercise_id' => $delLast])->one();
             $eModel->delete();
         }
     } else {
         $noerror = false;
     }
     return $noerror;
 }
Пример #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;
 }