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; } }
/** * * @param <int> $start_year */ public function createStudentsCareerSubjectAlloweds($start_year = null, PropelPDO $con = null) { if (is_null($start_year)) { $start_year = CareerSubjectPeer::FIRST_YEAR; } if ($con == null) { $con = Propel::getConnection(StudentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } try { $con->beginTransaction(); $c = new Criteria(); $c->add(CareerSubjectPeer::YEAR, $start_year); //This criterion checks if the careerSubject has orientation, if has an orientation then filters for studentCareer orientation. $criterion = $c->getNewCriterion(CareerSubjectPeer::ORIENTATION_ID, null, Criteria::ISNULL); $criterion->addOr($c->getNewCriterion(CareerSubjectPeer::ORIENTATION_ID, $this->getOrientationId())); $c->add($criterion); $career_subjects = $this->getCareer()->getCareerSubjects($c, $con); CareerSubjectPeer::clearInstancePool(); unset($c); foreach ($career_subjects as $career_subject) { $student_career_subject_allowed = new StudentCareerSubjectAllowed(); $student_career_subject_allowed->setStudent($this->getStudent($con)); $student_career_subject_allowed->setCareerSubject($career_subject); $student_career_subject_allowed->save($con); unset($student_career_subject_allowed); } $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } }