コード例 #1
0
 /**
  * @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]);
     }
 }
コード例 #2
0
ファイル: view.php プロジェクト: RomarioLopezC/RobotSS
?>
</p>
                        </div>
                    </div>

                </div>
            </div>

            <div class="pull-right">
                <?php 
echo Html::a('Cancelar', ['index'], ['class' => 'btn btn-danger']);
?>

                <?php 
if (Yii::$app->user->can('student')) {
    $vacancy = ProjectVacancy::find()->where("project_id=" . $model->id)->one();
    //$vacancyValue=ArrayHelper::getColumn($vacancy, 'vacancy')[0];
    $vacancyValue = $vacancy->vacancy;
    if ($vacancyValue > 0) {
        $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;
        if (Registration::find()->where(['student_id' => $student_id])->one()) {
            echo Html::a('Pre-registrarse al proyecto', ['preregister', 'id' => $model->id], ['class' => 'btn btn-success', 'disabled' => 'disabled']);
        } else {
            echo Html::a('Pre-registrarse al proyecto', ['preregister', 'id' => $model->id], ['class' => 'btn btn-success']);
        }
    } else {
        echo Html::a('Pre-registrarse al proyecto', ['preregister', 'id' => $model->id], ['class' => 'btn btn-success', 'disabled' => 'disabled']);
    }
コード例 #3
0
 /**
  * @param $id
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function actionAssignStudent($project_id, $student_id)
 {
     if (($model = Registration::find()->where(['project_id' => $project_id, 'student_id' => $student_id])->one()) !== null) {
         if ($model->student_status != Registration::ASSIGNED) {
             //Se registra como asignado
             $model->student_status = Registration::ASSIGNED;
             $model->save();
             //Se resta un vacante del proyecto
             $projectVacancy = ProjectVacancy::find()->where(['project_id' => $model->project->id])->one();
             $projectVacancy->vacancy = $projectVacancy->vacancy - 1;
             $projectVacancy->update();
             //Se envia el correo al estudiante
             Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($model->student->user->email)->setSubject('Asignación de alumno al proyecto' . ' ' . $model->project->name)->setTextBody('Asignación exitosa')->setHtmlBody('<b>Asignación exitosa</b>')->send();
             //Se envia el correo al project manager
             Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($model->project->projectManager->user->email)->setSubject('Asignación de alumno al proyecto' . ' ' . $model->project->name)->setTextBody('Asignación exitosa')->setHtmlBody('<b>Asignación exitosa</b>')->send();
             Yii::$app->getSession()->setFlash('success', 'Alumno asignado exitosamente.');
             $this->redirect('view-preregistered-students');
         } else {
             Yii::$app->getSession()->setFlash('danger', 'El alumno ya ha sido asignado previamente.');
             $this->redirect('view-preregistered-students');
         }
     } else {
         throw new NotFoundHttpException('El estudiante no ha sido encontrado.');
     }
 }