protected function findModelByExercise($id, $gid) { if (($model = CompleteExercise::find()->where(['exercise_id' => $id])->andWhere(['given_task_id' => $gid])->one()) !== null) { return $model; } else { return false; } }
/** * */ public function actionCheck($id) { $model = $this->findModel($id); $givenTask = $model->givenTask; if ($model->load(Yii::$app->request->post()) && $model->save() && $givenTask->load(Yii::$app->request->post()) && $givenTask->save()) { // return $this->redirect(['view', 'id' => $givenTask->status]); } $exersices_all = CompleteExercise::find()->indexBy('id')->all(); if (Model::loadMultiple($exersices_all, Yii::$app->request->post()) && Model::validateMultiple($exersices_all)) { foreach ($exersices_all as $exersice) { if ($givenTask->status == 3) { $exersice->remake = 0; } $exersice->save(false); } return $this->redirect('given-list'); } $model = CompleteTask::findOne($id); $exersices = $model->completeExersices; return $this->renderAjax('_check_form', ['model' => $model, 'exersices' => $exersices, 'givenTask' => $givenTask]); }
public function getCompleteExersices() { return $this->hasMany(CompleteExercise::className(), ['given_task_id' => 'given_task_id']); }