示例#1
0
 public function matriculateLastYearStudents()
 {
     $con = Propel::getConnection();
     try {
         $con->beginTransaction();
         $criteria = StudentCareerSchoolYearPeer::retrieveLastYearStudentNotGraduatedCriteria($this);
         $last_school_year = SchoolYearPeer::retrieveLastYearSchoolYear($this->getSchoolYear());
         $pager = new sfPropelPager('Student', 100);
         $pager->setCriteria($criteria);
         $pager->init();
         $last_page = $pager->getLastPage();
         for ($i = 1; $i <= $last_page; $i++) {
             $pager->setPage($i);
             $pager->init();
             $students = $pager->getResults();
             foreach ($students as $student) {
                 //no tiene reserva de banco y no es libre
                 if ($student->getLastStudentCareerSchoolYear()->getStatus() != StudentCareerSchoolYearStatus::WITHDRAWN && $student->getLastStudentCareerSchoolYear()->getStatus() != StudentCareerSchoolYearStatus::FREE) {
                     if ($student->getPerson()->getIsActive()) {
                         $shift = $student->getShiftForSchoolYear($last_school_year);
                         if (!$student->getIsRegistered($this->getSchoolYear())) {
                             $student->registerToSchoolYear($this->getSchoolYear(), $shift, $con);
                         }
                         if (!is_null($shift)) {
                             $shift->clearAllReferences(true);
                         }
                         $student->clearAllReferences(true);
                         unset($student);
                         unset($shift);
                     }
                 }
             }
             StudentPeer::clearInstancePool();
             unset($students);
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }