public function doSave($con = null) { if (is_null($con)) { $con = $this->getConnection(); } $course_subject = $this->getObject(); $values = $this->getValues(); $c = new Criteria(); if ($this->getCourseType() == CourseType::BIMESTER) { $c->add(CareerSchoolYearPeriodPeer::CAREER_SCHOOL_YEAR_PERIOD_ID, $values['quaterly_id']); } else { $c->add(CareerSchoolYearPeriodPeer::ID, $values['quaterly_id']); } $periods = CareerSchoolYearPeriodPeer::doSelect($c); try { $con->beginTransaction(); $cscs = CourseSubjectConfigurationPeer::retrieveBySubject($course_subject); foreach ($cscs as $csc) { $csc->delete($con); } foreach ($periods as $period) { $csc = new CourseSubjectConfiguration(); $csc->setCourseSubject($course_subject); $csc->setCareerSchoolYearPeriod($period); $csc->save($con); } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } }
public function configure() { $sf_formatter_revisited = new sfWidgetFormSchemaFormatterRevisited($this); $this->getWidgetSchema()->addFormFormatter('Revisited', $sf_formatter_revisited); $this->getWidgetSchema()->setFormFormatterName('Revisited'); $course_subject = $this->getObject(); $course_type = $course_subject->getCareerSubjectSchoolYear()->getConfiguration()->getCourseType(); if (!$course_subject->getCourseSubjectConfigurations()) { $c = new Criteria(); $c->add(CareerSchoolYearPeriodPeer::COURSE_TYPE, $course_type); $c->add(CareerSchoolYearPeriodPeer::CAREER_SCHOOL_YEAR_ID, $course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYearId()); $c->addAscendingOrderByColumn('start_at'); $periods = CareerSchoolYearPeriodPeer::doSelect($c); foreach ($periods as $period) { $csc = new CourseSubjectConfiguration(); $csc->setCareerSchoolYearPeriod($period); $course_subject->addCourseSubjectConfiguration($csc); $csc->save(); } } foreach ($course_subject->getCourseSubjectConfigurations() as $course_configuration) { $name = 'course_configuration_' . $course_configuration->getId(); $this->setWidget($name, new dcWidgetI18nNumberInput()); $this->getWidget($name)->setDefault($course_configuration->getMaxAbsence()); $this->setValidator($name, new dcValidatorI18NDecimal()); $this->getWidgetSchema()->setLabel($name, $course_configuration->getCareerSchoolYearPeriod()); } $this->getWidgetSchema()->setNameFormat('course_subject[%s]'); }
public function setCourseTypes($course_type) { $division = $this->getObject(); if (!$division->getCourseSubjectConfigurations()) { $c = new Criteria(); $c->add(CareerSchoolYearPeriodPeer::CAREER_SCHOOL_YEAR_ID, $division->getCareerSchoolYearId()); $c->add(CareerSchoolYearPeriodPeer::COURSE_TYPE, $course_type); $c->addAscendingOrderByColumn('start_at'); $periods = CareerSchoolYearPeriodPeer::doSelect($c); foreach ($periods as $period) { $csc = new CourseSubjectConfiguration(); $csc->setCareerSchoolYearPeriod($period); $division->addCourseSubjectConfiguration($csc); $csc->save(); } } }