protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); // add your code here $this->createContextInstance(); $i = 0; $students = StudentPeer::doSelect(new Criteria()); $career_school_year = CareerSchoolYearPeer::retrieveByPK(4); foreach ($students as $student) { $this->logSection("Evaluando student ID = ", $student->getId()); $career_student = $student->getCareerStudent(); if ($career_student == null) { $this->logSection("ceando CarrerStudent", $student->getId()); $career_student = new CareerStudent(); $career_student->setStudent($student); $career_student->setCareerId(1); $career_student->setStartYear(1); $career_student->setFileNumber($student->getGlobalFileNumber()); $career_student->save($connection); #$career_student->createStudentsCareerSubjectAlloweds(1, $connection); $this->logSection("Fin creacion careerStudent", $career_student->getId()); } $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $career_school_year); if ($student_career_school_year == null) { $i++; $this->logSection("Creando studentCareerSchoolYear", $student->getId()); $student_career_school_year = new StudentCareerSchoolYear(); $student_career_school_year->setCareerSchoolYear($career_school_year); $student_career_school_year->setStudent($student); $student_career_school_year->setYear($student->getCareerStudent()->getStartYear()); $student_career_school_year->save($connection); $this->logSection("Fin creacion studentCareerSchoolYear", $career_student->getId()); $this->logSection("Guardando", $student); echo $i; } } }
/** * this method creates the alloweds for this career_student * * @see createStudentCareerSubjectAlloweds in CareerStudent. * * @param CareerStudent $career_student * @param Integet $start_year * @param PropelPDO $con * */ public function createStudentCareerSubjectAlloweds(CareerStudent $career_student, $start_year, PropelPDO $con) { $career_student->createStudentsCareerSubjectAlloweds($start_year, $con); }
/** * Registers the student for the given career. * * @param Career $career * @param Orientation $orientation * @param integer $start_year */ public function registerToCareer(Career $career, Orientation $orientation = null, SubOrientation $sub_orientation = null, $start_year, $con = null) { if ($con == null) { $con = Propel::getConnection(StudentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $career_student = new CareerStudent(); $career_student->setCareerId($career->getId()); if ($orientation) { $career_student->setOrientationId($orientation->getId()); } if ($sub_orientation) { $career_student->setSubOrientationId($sub_orientation->getId()); } $career_student->setStudentId($this->getId()); $career_student->setStartYear($start_year); SchoolBehaviourFactory::getInstance()->setStudentFileNumberForCareer($career_student, $con); $career_student->save($con); SchoolBehaviourFactory::getInstance()->createStudentCareerSubjectAlloweds($career_student, $start_year, $con); }
/** * This action saves a new career registration for selected student * @see executeRegisterForCareer * @param sfWebRequest $request */ public function executeUpdateRegistrationForCareer(sfWebRequest $request) { $this->student = StudentPeer::retrieveByPK($request->getParameter('id')); if (null === $this->student) { $this->getUser()->setFlash('error', 'No student selected'); $this->redirect('@student'); } $career_student = new CareerStudent(); $career_student->setStudent($this->student); $class = SchoolBehaviourFactory::getInstance()->getFormFactory()->getRegisterStudentForCareerForm(); $this->form = new $class($career_student); $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { try { $career_student = $this->form->save(); } catch (PropelException $e) { $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } $this->getUser()->setFlash('info', 'The item was updated successfully.'); $this->redirect('student/registerForCareer?id=' . $this->student->getId()); } else { $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); $this->setTemplate('registerForCareer'); } }