public static function retrieveOrCreateByCareerSubjectAndStudent($career_subject_id, $student_id) { $c = new Criteria(); $c->add(self::CAREER_SUBJECT_ID, $career_subject_id); $c->add(self::STUDENT_ID, $student_id); $sacs = self::doSelectOne($c); if ($sacs == null) { $criteria = new criteria(); $criteria->add(CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID, $career_subject_id); $career_subject_school_years = CareerSubjectSchoolYearPeer::doSelect($criteria); $opcions = array(); foreach ($career_subject_school_years as $career_subject_school_year) { foreach ($career_subject_school_year->getChoices() as $optional_career_subject_school_year) { $cs = CareerSubjectPeer::retrieveByCareerSubjectSchoolYearId($optional_career_subject_school_year->getChoiceCareerSubjectSchoolYearId()); $opcions[] = $cs->getId(); } } $criteria = new criteria(); $criteria->add(self::CAREER_SUBJECT_ID, $opcions, Criteria::IN); $sacs = self::doSelectOne($criteria); if ($sacs == null) { $sacs = new StudentApprovedCareerSubject(); $sacs->setCareerSubjectId($career_subject_id); } } $sacs->setStudentId($student_id); return $sacs; }