public function save($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (is_null($con)) { $con = Propel::getConnection(CareerStudentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } try { $con->beginTransaction(); $values = $this->getValues(); $career = CareerPeer::retrieveByPK($values["career_id"]); $orientation = OrientationPeer::retrieveByPK($values["orientation_id"]); $sub_orientation = SubOrientationPeer::retrieveByPK($values["sub_orientation_id"]); $start_year = $values["start_year"]; unset($values["career_id"]); unset($values["orientation_id"]); unset($values["sub_orientation_id"]); unset($values["start_year"]); foreach ($values as $student_id) { $student = StudentPeer::retrieveByPk($student_id, $con); if (!$student->isRegisteredToCareer($career, $con)) { $student->registerToCareer($career, $orientation, $sub_orientation, $start_year, $con); } } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } }
public function preExecute() { if (!$this->getUser()->getReferenceFor('orientation')) { $this->getUser()->setFlash('warning', 'Debe seleccionar una orientación para poder administrar sus sub orientaciones.'); $this->redirect('@orientation'); } $this->orientation = OrientationPeer::retrieveByPK($this->getUser()->getReferenceFor('orientation')); if (is_null($this->orientation)) { $this->getUser()->setFlash('warning', 'Debe seleccionar una orientación para poder administrar sus sub orientaciones.'); $this->redirect('@orientation'); } parent::preExecute(); }