public function createByName($name)
 {
     print_r('[' . $name . ']');
     $document = new Division();
     $document->setName($name);
     $document->setSlug();
     $document->save();
     $document = $this->findOneBySlug($document->getSlug());
     return $document;
 }
 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');
     }
 }
 public function setName($name)
 {
     $this->__load();
     return parent::setName($name);
 }
示例#4
0
 function initDivision()
 {
     $division = new Division();
     $division->setName("Sindhudurg");
     $sub1 = new Subdivision();
     $sub1->setName("Devgad");
     $sub1->setDivision($division);
     $sub2 = new Subdivision();
     $sub2->setName("Vaibhavvadi");
     $sub2->setDivision($division);
     $sub3 = new Subdivision();
     $sub3->setName("Malwan");
     $sub3->setDivision($division);
     $sub4 = new Subdivision();
     $sub4->setName("Kudal");
     $sub4->setDivision($division);
     $sub5 = new Subdivision();
     $sub5->setName("Vengurla");
     $sub5->setDivision($division);
     $sub6 = new Subdivision();
     $sub6->setName("Sawantwadi");
     $sub6->setDivision($division);
     $sub7 = new Subdivision();
     $sub7->setName("Dodamarg");
     $sub7->setDivision($division);
     $division->getSubdivisions()->add($sub1);
     $division->getSubdivisions()->add($sub2);
     $division->getSubdivisions()->add($sub3);
     $division->getSubdivisions()->add($sub4);
     $division->getSubdivisions()->add($sub5);
     $division->getSubdivisions()->add($sub6);
     $division->getSubdivisions()->add($sub7);
     $this->em->persist($division);
     $this->em->flush();
     echo "Locations Created..";
 }