/**
  * Creates career_subject_school_year if the career has already have an instance of career_school_year of the actual school year.
  *
  * @param CareerSubject $career_subject
  * @param PropelPDO $con
  */
 public function updateCareerSubjectSchoolYear(CareerSubject $career_subject, PropelPDO $con)
 {
     if ($career_subject->isNew()) {
         $school_year = SchoolYearPeer::retrieveCurrent();
         $career_school_year = CareerSchoolYearPeer::retrieveByCareerAndSchoolYear($career_subject->getCareer(), $school_year);
         if (!is_null($career_school_year) && !$career_school_year->getIsProcessed()) {
             $career_subject_school_year = new CareerSubjectSchoolYear();
             $career_subject_school_year->setCareerSubjectId($career_subject->getId());
             $career_subject_school_year->setCareerSchoolYearId($career_school_year->getId());
             $career_subject_school_year->save($con);
         }
     }
 }
 /**
  * This method try to find if there are new CareerSubjects for our Career, recently
  * created but without a CareerSubjectSchoolYear created
  *
  */
 public function checkCareerSubjectOptionsIntegrity()
 {
     $criteria = new Criteria();
     $criteria->addJoin(CareerSubjectSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, CareerSchoolYearPeer::ID, Criteria::INNER_JOIN);
     $criteria->addAnd(CareerSchoolYearPeer::CAREER_ID, $this->getCareerId());
     $all_career_subjects_sy = array_map(create_function('$cs', 'return $cs->getCareerSubjectId();'), CareerSubjectSchoolYearPeer::doSelect($criteria));
     $criteria->clear();
     $criteria->addAnd(CareerSubjectPeer::CAREER_ID, $this->getCareerId());
     $criteria->addAnd(CareerSubjectPeer::ID, $all_career_subjects_sy, Criteria::NOT_IN);
     $con = Propel::getConnection(SchoolYearPeer::DATABASE_NAME);
     try {
         foreach (CareerSubjectPeer::doSelect($criteria) as $career_subject) {
             $career_subject_school_year = new CareerSubjectSchoolYear();
             $career_subject_school_year->setCareerSchoolYear($this);
             $career_subject_school_year->setCareerSubject($career_subject);
             $career_subject_school_year->save($con);
         }
         $con->commit();
     } catch (PropelPDOException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemple #3
0
 public function addToCurrentCareerSchoolYear(PropelPDO $con = null)
 {
     if (is_null($con)) {
         $con = Propel::getConnection();
     }
     $career_school_year = $this->getCareerSchoolYear();
     try {
         $con->beginTransaction();
         $career_subject_school_year = new CareerSubjectSchoolYear();
         $career_subject_school_year->setCareerSubject($this);
         $career_subject_school_year->setCareerSchoolYear($career_school_year);
         $career_subject_school_year->save($con);
         $students = StudentPeer::retrieveForCareerSchoolYearAndYear($career_school_year, $this->getYear());
         foreach ($students as $student) {
             $student_career_subject_allowed = new StudentCareerSubjectAllowed();
             $student_career_subject_allowed->setCareerSubject($this);
             $student_career_subject_allowed->setStudent($student);
             $student_career_subject_allowed->save($con);
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }
Exemple #4
0
 public function createCareerSchoolYear($career)
 {
     $con = Propel::getConnection(SchoolYearPeer::DATABASE_NAME);
     try {
         $con->beginTransaction();
         $career_school_year = new CareerSchoolYear();
         $career_school_year->setSchoolYear($this);
         $career_school_year->setCareer($career);
         $subject_configuration = $this->createOrCopyLastYearSubjectConfiguration($career, $con);
         $career_school_year->setSubjectConfiguration($subject_configuration);
         $career_school_year->save($con);
         foreach ($career->getCareerSubjects() as $career_subject) {
             $career_subject_school_year = new CareerSubjectSchoolYear();
             $career_subject_school_year->setCareerSchoolYear($career_school_year);
             $career_subject_school_year->setCareerSubject($career_subject);
             $career_subject_school_year->copyLastYearConfiguration();
             $career_subject_school_year->copyLastYearSort();
             $career_subject_school_year->save($con);
         }
         $con->commit();
     } catch (PropelPDOException $e) {
         $con->rollBack();
         throw $e;
     }
 }