/** * Updates an existing Project model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $user_id = User::find()->where("id=" . Yii::$app->user->id)->one()->id; $manager_id = ProjectManager::find()->where("user_id=" . $user_id)->one()->id; $model->manager_id = $manager_id; $degreeIds = StudentProfile::find()->where("project_id=" . $model->id)->all(); $cupoValor = ProjectVacancy::find()->where("project_id=" . $model->id)->all(); $ids = ArrayHelper::getColumn($degreeIds, 'degree_id'); $cupo = ArrayHelper::getColumn($cupoValor, 'vacancy')[0]; $model->degrees1 = $ids; $model->vacancy = $cupo; if ($model->load(Yii::$app->request->post()) && $model->save()) { StudentProfile::deleteAll('project_id=' . $model->id); ProjectVacancy::deleteAll('project_id=' . $model->id); $vacancyValue = $_POST['Project']['vacancy']; $newVacancy = new ProjectVacancy(); $newVacancy->project_id = $model->id; $newVacancy->vacancy = $vacancyValue; $newVacancy->save(); $degreesList = $_POST['Project']['degrees1']; foreach ($degreesList as $value) { $this->createStudentProfile($model->id, $value); } Yii::$app->getSession()->setFlash('success', 'Los cambios se han guardado exitosamente'); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }