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 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'); } }