/** * @param $id * @return \yii\web\Response * @throws NotFoundHttpException * @throws \yii\db\Exception */ public function actionPreregister($id) { $model = $this->findModel($id); $user = User::find()->where("id=" . Yii::$app->user->id)->one(); $user_id = $user->id; $student = Student::find()->where("user_id=" . $user_id)->one(); $student_id = $student->id; $vacancy = ProjectVacancy::find()->where("project_id=" . $id)->one(); $vacancyValue = $vacancy->vacancy; if ($existe = StudentProfile::find()->where(['project_id' => $id, 'degree_id' => $student->degree_id])->one()) { if (Registration::find()->where(['student_id' => $student_id])->one()) { Yii::$app->getSession()->setFlash('danger', 'Ya te has pre-registrado a un proyecto'); return $this->redirect(['view', 'id' => $model->id]); } else { if ($vacancyValue > 0) { $newRegistration = new Registration(); $newRegistration->project_id = $id; $newRegistration->student_id = $student_id; $newRegistration->student_status = "preregistered"; $newRegistration->save(); Yii::$app->db->createCommand()->update('project_vacancy', ['vacancy' => $vacancy->vacancy - 1], 'project_id=' . $id)->execute(); Yii::$app->getSession()->setFlash('success', 'Te has pre-registrado al proyecto'); return $this->redirect(['view', 'id' => $model->id]); } else { Yii::$app->getSession()->setFlash('danger', 'No hay cupo para este proyecto. Escoge otro.'); return $this->redirect(['view', 'id' => $model->id]); } } } else { Yii::$app->getSession()->setFlash('danger', 'No cuentas con el perfil solicitado'); return $this->redirect(['view', 'id' => $model->id]); } }
/** * @return \yii\db\ActiveQuery */ public function getStudentProfiles() { return $this->hasMany(StudentProfile::className(), ['degree_id' => 'id']); }