public function saveDivisionStudentList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['division_student_list'])) {
         // somebody has unset this widget
         return;
     }
     if (is_null($con)) {
         $con = $this->getConnection();
     }
     $con->beginTransaction();
     try {
         $values = $this->getValue('division_student_list');
         $this->getObject()->deleteStudents($con, $values);
         if (is_array($values)) {
             foreach ($values as $value) {
                 $division_student = new DivisionStudent();
                 $division_student->setDivision($this->getObject());
                 $division_student->setStudentId($value);
                 $division_student->save($con);
             }
         }
         $con->commit();
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
示例#2
0
 public function createStudentsForNextYear(PropelPDO $con = null, CareerSchoolYear $last_career_school_year)
 {
     //$old_division = DivisionPeer::retrieveByDivisionTitleAndYearAndSchoolYear($this->getDivisionTitle(), $this->getYear() - 1, $last_career_school_year);
     //$students = $old_division->getStudents();
     $c = new Criteria();
     $c->addJoin(StudentPeer::ID, DivisionStudentPeer::STUDENT_ID, Criteria::INNER_JOIN);
     $c->addJoin(DivisionStudentPeer::DIVISION_ID, DivisionPeer::ID, Criteria::INNER_JOIN);
     $c->addAnd(DivisionPeer::YEAR, $this->getYear() - 1);
     $c->addAnd(DivisionPeer::DIVISION_TITLE_ID, $this->getDivisionTitleId());
     $c->addAnd(DivisionPeer::CAREER_SCHOOL_YEAR_ID, $last_career_school_year->getId());
     $c->addAnd(StudentPeer::ID, SchoolYearStudentPeer::retrieveStudentIdsForSchoolYear($last_career_school_year->getSchoolYear()), Criteria::IN);
     $students = StudentPeer::doSelect($c);
     foreach ($students as $student) {
         $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $this->getCareerSchoolYear());
         StudentCareerSchoolYearPeer::clearInstancePool();
         //If the student has not repeated last year.
         if (!is_null($student_career_school_year) && !$student_career_school_year->getIsRepproved()) {
             $division_student = new DivisionStudent();
             $division_student->setStudent($student);
             $division_student->setDivision($this);
             $division_student->save($con);
             $division_student->clearAllReferences(true);
             unset($division_student);
             $student_career_school_year->clearAllReferences(true);
             unset($student_career_school_year);
         }
         $student->clearAllReferences(true);
         unset($student);
     }
     StudentPeer::clearInstancePool();
     unset($students);
 }