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;
 }
 public function updateOptionalCareerSubject($widget, $value)
 {
     $school_year_id = array_shift($value);
     $criteria = new Criteria();
     if ($school_year_id != "") {
         $career_subject = $this->getObject()->getCareerSubject();
         $school_year = SchoolYearPeer::retrieveByPK($school_year_id);
         $career_subject_school_year = CareerSubjectSchoolYearPeer::retrieveByCareerSubjectAndSchoolYear($career_subject, $school_year);
         $opcions = array();
         foreach ($career_subject_school_year->getChoices() as $optional_career_subject_school_year) {
             $cs = CareerSubjectPeer::retrieveByCareerSubjectSchoolYearId($optional_career_subject_school_year->getChoiceCareerSubjectSchoolYearId());
             $opcions[] = $cs->getId();
         }
         //$opcions es un arreglo con todas las posibles optativas
         $criteria->add(CareerSubjectPeer::ID, $opcions, Criteria::IN);
         $widget->getOption('widget')->setOption('criteria', $criteria);
     }
 }