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 $courses = CoursePeer::doSelect(new Criteria()); foreach ($courses as $course) { $division = new Division(); $division->setName($course->getName()); $division->setSchoolYearId($course->getSchoolYearId()); foreach ($course->getCourseSubjects() as $course_subject) { $course_students = $course->getCourseStudents(); if (isset($course_students[0])) { $division->setCareerId($course_students[0]->getCareerSubject()->getCareerId()); } else { $division->setCareerId(1); } $new_course = new Course(); $course->copyInto($new_course); $new_course->setName($course_subject->getSubject() . ' - ' . $course->getName()); $new_course->save(); $new_course_subject = new CourseSubject(); $course_subject->copyInto($new_course_subject); $new_course_subject->setCourseId($new_course->getId()); $new_course_subject->setCourseId($new_course->getId()); $new_course_subject->save(); $course_subject->delete(); $c = new Criteria(); $c->add(CourseStudentPeer::COURSE_ID, $course->getId()); $c->addJoin(CourseStudentPeer::CAREER_SUBJECT_ID, CareerSubjectPeer::ID); $c->add(CareerSubjectPeer::SUBJECT_ID, $new_course_subject->getSubjectId()); $course_students = CourseStudentPeer::doSelect($c); foreach ($course_students as $course_student) { $new_course_student = new CourseStudent(); $course_student->copyInto($new_course_student); $new_course_student->setCourseId($new_course->getId()); $new_course_student->save(); $course_student->delete(); } $division_course = new DivisionCourse(); $division_course->setCourse($new_course); $division->addDivisionCourse($division_course); } try { $course->delete(); } catch (Exception $e) { } try { $division->save(); } catch (Exception $e) { } $this->logSection('division+', 'Division ' . $division . ' created'); } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $con = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $this->createContextInstance('backend'); $criteria = new Criteria(); $criteria->add(CoursePeer::IS_CLOSED, false); $criteria->addJoin(CoursePeer::ID, CourseSubjectPeer::COURSE_ID, Criteria::INNER_JOIN); $criteria->addJoin(CourseSubjectPeer::ID, CourseSubjectStudentPeer::COURSE_SUBJECT_ID, Criteria::INNER_JOIN); $course_subject_students = CourseSubjectStudentPeer::doSelect($criteria); $this->log('Cant. Course Subject Students a procesar:'); $this->log(count($course_subject_students)); foreach ($course_subject_students as $course_subject_student) { $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId()); $this->log('Id del course subject student Actual:'); $this->log($course_subject_student->getId()); foreach ($course_subject_student_marks as $mark) { $mark->setIsClosed(true); $mark->save($con); } $student_approved_course_subject = new StudentApprovedCourseSubject(); $student_approved_course_subject->setCourseSubject($course_subject_student->getCourseSubject()); $student_approved_course_subject->setStudentId($course_subject_student->getStudentId()); $student_approved_course_subject->setSchoolYear($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear()); $student_approved_career_subject = new StudentApprovedCareerSubject(); $student_approved_career_subject->setStudentId($course_subject_student->getStudentId()); $student_approved_career_subject->setCareerSubject($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSubject()); $student_approved_career_subject->setSchoolYear($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear()); $student_approved_career_subject->save($con); $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject); $student_approved_course_subject->save($con); $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject); $course_subject_student->save($con); } $criteria = new Criteria(); $criteria->add(CoursePeer::IS_CLOSED, false); $courses = CoursePeer::doSelect($criteria); foreach ($courses as $c) { $c->setIsClosed(true); $c->save($con); } }
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(); echo "Leyendo cursos en la base de datos...[No se puede hacer mas lento :)]\n"; foreach (CoursePeer::doSelect(new Criteria()) as $course) { echo "Arreglando curso '" . $course . "'...\n"; $students_ids = array(); foreach ($course->getCourseStudents() as $course_student) { if (!in_array($course_student->getStudentId(), $students_ids)) { $students_ids[] = $course_student->getStudentId(); } $course_student->delete(); } foreach ($students_ids as $id) { if (!CourseStudentPeer::generateInscriptionToCourse($id, $course->getId())) { echo "Error. Curso con cupo maximo superado o inscripcion ya existente.\n"; } } } }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(CoursePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(CoursePeer::DATABASE_NAME); $criteria->add(CoursePeer::CODE, $pks, Criteria::IN); $objs = CoursePeer::doSelect($criteria, $con); } return $objs; }
protected function getCourselist(Criteria $c = null) { if ($c === null) { return CoursePeer::doSelect(new Criteria()); } else { return CoursePeer::doSelect($c); } }
public function fixComissions($connection) { $c = new Criteria(); //$c->add(CoursePeer::DIVISION_ID, null, Criteria::ISNULL); $c->add(CoursePeer::SCHOOL_YEAR_ID, 1); foreach (CoursePeer::doSelect($c) as $course) { $course_subjects = $course->getCourseSubjects(); foreach ($course->getCourseSubjects() as $course_subject) { foreach ($course_subject->getCourseSubjectStudents() as $course_subject_student) { $result = $course_subject_student->getCourseResult(); if (is_null($result->getStudentApprovedCareerSubjectId())) { if (is_null($result->getId())) { $result->save($connection); if ($result instanceof StudentApprovedCourseSubject) { $student_approved_career_subject = StudentApprovedCareerSubjectPeer::retrieveOrCreateByCareerSubjectAndStudent($course_subject_student->getCourseSubject()->getCareerSubject()->getId(), $course_subject_student->getStudentId()); $student_approved_career_subject->setSchoolYearId(1); $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject); $student_approved_course_subject->save($connection); $student_approved_career_subject->save($connection); } } } } } } }
public function index() { Session::set('myDbName', 'dokeos_main'); Propel::init(APP_PATH . 'config/propel/dokeos-conf.php'); $this->cursos = CoursePeer::doSelect(new Criteria()); }
public static function getCoursesForStudents($students_ids) { #Falta el año electivo actual $c = new Criteria(); $c->add(CourseSubjectStudentPeer::STUDENT_ID, $students_ids, Criteria::IN); $c->addJoin(CourseSubjectStudentPeer::COURSE_SUBJECT_ID, CourseSubjectPeer::ID); $c->addJoin(CourseSubjectPeer::COURSE_ID, CoursePeer::ID); $c->setDistinct(CoursePeer::ID); return CoursePeer::doSelect($c); }
public function getCourses($include_commissions = false) { $criteria = new Criteria(); $criterion = $criteria->getNewCriterion(CoursePeer::DIVISION_ID, $this->getId()); if ($include_commissions) { $criterion->addOr($criteria->getNewCriterion(CoursePeer::RELATED_DIVISION_ID, $this->getId())); } $criteria->add($criterion); return CoursePeer::doSelect($criteria); }
/** * Gets an array of Course objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this Department has previously been saved, it will retrieve * related Courses from storage. If this Department is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array Course[] * @throws PropelException */ public function getCourses($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(DepartmentPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collCourses === null) { if ($this->isNew()) { $this->collCourses = array(); } else { $criteria->add(CoursePeer::DEPT_ID, $this->id); CoursePeer::addSelectColumns($criteria); $this->collCourses = CoursePeer::doSelect($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(CoursePeer::DEPT_ID, $this->id); CoursePeer::addSelectColumns($criteria); if (!isset($this->lastCourseCriteria) || !$this->lastCourseCriteria->equals($criteria)) { $this->collCourses = CoursePeer::doSelect($criteria, $con); } } } $this->lastCourseCriteria = $criteria; return $this->collCourses; }