Beispiel #1
0
 public function hasActiveReserve()
 {
     //tiene reserva de banco activa.
     $c = new Criteria();
     $c->add(StudentReserveStatusRecordPeer::STUDENT_ID, $this->getId());
     $c->add(StudentReserveStatusRecordPeer::END_DATE, null, Criteria::ISNULL);
     return StudentReserveStatusRecordPeer::doSelectOne($c);
 }
Beispiel #2
0
 public function executeUpdateChangeStudentStatus(sfWebRequest $request)
 {
     $this->student = StudentPeer::retrieveByPK($request->getParameter('student_id'));
     $this->status = $request->getParameter('student_career_school_year[status]');
     $this->motive = $request->getParameter('student_career_school_year[change_status_motive_id]');
     $student_career_school_year = $this->student->getLastStudentCareerSchoolYear();
     if (is_null($student_career_school_year)) {
         $this->getUser()->setFlash('error', 'Ocurrió un error al guardar los datos');
     } else {
         switch ($this->status) {
             case StudentCareerSchoolYearStatus::WITHDRAWN:
                 //Retirado
                 //cambio el estado
                 $this->form = new StudentCareerSchoolYearForm($student_career_school_year);
                 $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
                 $a = $this->form->save();
                 //desmatricular
                 $s = $this->student->getSchoolYearStudentForSchoolYear($student_career_school_year->getCareerSchoolYear()->getSchoolYear());
                 if (!is_null($s)) {
                     $s->delete();
                 }
                 //deshabilito la persona
                 $this->student->getPerson()->setIsActive(false);
                 $this->student->getPerson()->save();
                 //seteo en sus course_subject_student_mark is_closed en TRUE;
                 $this->student->setCourseSubjectStudentMarksForSchoolYear($student_career_school_year->getCareerSchoolYear()->getSchoolYear(), true);
                 $this->getUser()->setFlash('info', 'The item was updated successfully.');
                 break;
             case StudentCareerSchoolYearStatus::WITHDRAWN_WITH_RESERVE:
                 //Retirado con reserva de banco
                 $this->start_date = $request->getParameter('student_career_school_year[start_date_reserve]');
                 //Si no existe la reserva la creo.
                 $student_reserve = $this->student->hasActiveReserve();
                 if (is_null($student_reserve)) {
                     if (is_null($this->start_date) || $this->start_date == '') {
                         $this->getUser()->setFlash('error', 'El campo Fecha de inicio de la reserva es obligatorio.');
                     } else {
                         $this->start_date = str_replace('/', '-', $this->start_date);
                         $this->start_date = date('Y-m-d', strtotime($this->start_date));
                         $student_reserve = new StudentReserveStatusRecord();
                         $student_reserve->setStudentId($this->student->getId());
                         $student_reserve->setStartDate(new DateTime($this->start_date));
                         StudentReserveStatusRecordPeer::doInsert($student_reserve);
                         //cambio el estado
                         $this->form = new StudentCareerSchoolYearForm($student_career_school_year);
                         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
                         $a = $this->form->save();
                         //desmatricular
                         $s = $this->student->getSchoolYearStudentForSchoolYear($student_career_school_year->getSchoolYear());
                         if (!is_null($s)) {
                             $s->delete();
                         }
                         //seteo en sus course_subject_student_mark is_closed en TRUE;
                         $this->student->setCourseSubjectStudentMarksForSchoolYear($student_career_school_year->getCareerSchoolYear()->getSchoolYear(), true);
                         $this->getUser()->setFlash('info', 'The item was updated successfully.');
                     }
                 } else {
                     //Ya existe la reserva solo modifico la fecha
                     $this->start_date = str_replace('/', '-', $this->start_date);
                     $this->start_date = date('Y-m-d', strtotime($this->start_date));
                     $student_reserve->setStartDate(new DateTime($this->start_date));
                     $student_reserve->save();
                     $this->getUser()->setFlash('info', 'The item was updated successfully.');
                 }
                 break;
             case StudentCareerSchoolYearStatus::FREE:
                 //Libre
                 $max_year = $student_career_school_year->getCareerSchoolYear()->getCareer()->getMaxYear();
                 //chequeo que sea el ultimo año.
                 if ($student_career_school_year->getYear() == $max_year) {
                     //chequeo que deba materias.
                     if ($this->student->getCountStudentRepprovedCourseSubject() > 0) {
                         //cambio el estado
                         $this->form = new StudentCareerSchoolYearForm($student_career_school_year);
                         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
                         $a = $this->form->save();
                         //si no esta activo, lo activo
                         if (!$this->student->getPerson()->getIsActive()) {
                             $this->student->getPerson()->setIsActive(true);
                             $this->student->getPerson()->save();
                         }
                         //desmatricular
                         $s = $this->student->getSchoolYearStudentForSchoolYear($student_career_school_year->getSchoolYear());
                         if (!is_null($s)) {
                             $s->delete();
                         }
                         $this->getUser()->setFlash('info', 'The item was updated successfully.');
                     } else {
                         $this->getUser()->setFlash('error', 'El alumno no debe materias.');
                     }
                 } else {
                     $this->getUser()->setFlash('error', 'El alumno debe estar en el ultimo año de la carrera.');
                 }
                 break;
             case StudentCareerSchoolYearStatus::IN_COURSE:
                 //En curso
                 //Chequeo que el estado anterior sea Retirado con Reserva de Banco.
                 if ($student_career_school_year->getStatus() != StudentCareerSchoolYearStatus::WITHDRAWN_WITH_RESERVE) {
                     $this->getUser()->setFlash('error', 'El estado anterior debe ser Retirado con reserva de Banco.');
                 } else {
                     $this->end_date = $request->getParameter('student_career_school_year[end_date_reserve]');
                     if (is_null($this->end_date) || $this->end_date == '') {
                         $this->getUser()->setFlash('error', 'El campo Fecha de fin de la reserva es obligatorio.');
                     } else {
                         //guardo la fecha de fin de la reserva.
                         $this->end_date = str_replace('/', '-', $this->end_date);
                         $this->end_date = date('Y-m-d', strtotime($this->end_date));
                         $student_reserve = $this->student->hasActiveReserve();
                         $student_reserve->setEndDate(new DateTime($this->end_date));
                         $student_reserve->save();
                         //cambio el estado
                         $this->form = new StudentCareerSchoolYearForm($student_career_school_year);
                         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
                         $a = $this->form->save();
                         $this->getUser()->setFlash('info', 'The item was updated successfully.');
                     }
                 }
                 break;
             case StudentCareerSchoolYearStatus::APPROVED:
                 if ($student_career_school_year->getStatus() == StudentCareerSchoolYearStatus::IN_COURSE || $student_career_school_year->getStatus() == StudentCareerSchoolYearStatus::FREE) {
                     if ($student_career_school_year->getStatus() == StudentCareerSchoolYearStatus::FREE) {
                         //no debe materias.
                         if ($this->student->getCountStudentRepprovedCourseSubject() == 0) {
                             //cambio el estado
                             $this->form = new StudentCareerSchoolYearForm($student_career_school_year);
                             $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
                             $a = $this->form->save();
                             //cambio el estado de la carrera.
                             $career = $student_career_school_year->getCareerSchoolYear()->getCareer();
                             $career_student = CareerStudentPeer::retrieveByCareerAndStudent($career->getId(), $this->student->getId());
                             $career_student->setStatus(CareerStudentStatus::GRADUATE);
                             $current_school_year = SchoolYearPeer::retrieveCurrent();
                             $career_student->setGraduationSchoolYearId($current_school_year->getId());
                             $career_student->save(Propel::getConnection());
                             //deshabilito la persona
                             $this->student->getPerson()->setIsActive(false);
                             $this->student->getPerson()->save();
                             $this->getUser()->setFlash('info', 'The item was updated successfully.');
                         } else {
                             $this->getUser()->setFlash('error', 'El alumno tiene materias previas sin aprobar.');
                         }
                     } else {
                         /*SOLO CHEQUEA QUE TENGA LAS MATERIAS CERRADAS*/
                         $course_subject_students = $this->student->getCourseSubjectStudentsForSchoolYear($student_career_school_year->getCareerSchoolYear()->getSchoolYear());
                         $css = array_shift($course_subject_students);
                         /* Si tengo alguna materia sin cerrar */
                         if (!$css->areAllMarksClosed()) {
                             $this->getUser()->setFlash('error', "El alumno tiene cursadas sin cerrar.");
                         } else {
                             //cambio el estado
                             $this->form = new StudentCareerSchoolYearForm($student_career_school_year);
                             $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
                             $a = $this->form->save();
                             $this->getUser()->setFlash('info', 'The item was updated successfully.');
                         }
                     }
                 } else {
                     $this->getUser()->setFlash('error', 'El alumno debe estar cursando o estar Libre.');
                 }
                 break;
         }
     }
     $this->redirect('student/changeStudentStatus?id=' . $this->student->getId());
 }