Esempio n. 1
0
 /**
  * Setup the temporary database with data from the real one
  * @param \Doctrine\ORM\EntityManager $em
  */
 protected function buildTemporaryDatabase(\Doctrine\ORM\EntityManager $em)
 {
     $classes = $this->_em->getMetadataFactory()->getAllMetadata();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $tool->dropDatabase();
     $tool->createSchema($classes);
     foreach ($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->findAll() as $type) {
         $newType = new \Jazzee\Entity\PageType();
         $newType->setClass($type->getClass());
         $newType->setName($type->getName());
         $em->persist($newType);
     }
     foreach ($this->_em->getRepository('\\Jazzee\\Entity\\ElementType')->findAll() as $type) {
         $newType = new \Jazzee\Entity\ElementType();
         $newType->setClass($type->getClass());
         $newType->setName($type->getName());
         $em->persist($newType);
     }
     foreach ($this->_em->getRepository('\\Jazzee\\Entity\\PaymentType')->findAll() as $type) {
         $newType = new \Jazzee\Entity\PaymentType();
         $newType->setClass($type->getClass());
         $newType->setName($type->getName());
         if ($type->isExpired()) {
             $newType->expire();
         }
         foreach ($type->getVariables() as $var) {
             $newVar = new Jazzee\Entity\PaymentTypeVariable();
             $newVar->setName($var->getName());
             $newVar->setValue($var->getValue());
             $newVar->setType($newType);
             $em->persist($newVar);
         }
         $em->persist($newType);
     }
     $em->flush();
     $em->clear();
     $count = 0;
     foreach ($this->_em->getRepository('\\Jazzee\\Entity\\School')->findAllArray() as $arr) {
         $newSchool = new \Jazzee\Entity\School();
         $newSchool->setCity($arr['city']);
         $newSchool->setCode($arr['code']);
         $newSchool->setCountry($arr['country']);
         $newSchool->setName($arr['name']);
         $newSchool->setPostalCode($arr['postalCode']);
         $newSchool->setSearchTerms($arr['searchTerms']);
         $newSchool->setState($arr['state']);
         $em->persist($newSchool);
         $count++;
         if ($count > 1000) {
             $count = 0;
             $em->flush();
             $em->clear();
         }
     }
     $em->flush();
 }
Esempio n. 2
0
 /**
  * Create a new virtual file
  */
 public function actionNew()
 {
     $form = new \Foundation\Form();
     $form->setCSRFToken($this->getCSRFToken());
     $form->setAction($this->path("manage/schools/new"));
     $field = $form->newField();
     $field->setLegend('New School');
     $element = $field->newElement('TextInput', 'name');
     $element->setLabel('Name');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $element = $field->newElement('TextInput', 'code');
     $element->setLabel('Code');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $element = $field->newElement('TextInput', 'city');
     $element->setLabel('City');
     $element->addValidator(new \Foundation\Form\Validator\MaximumLength($element, 64));
     $element = $field->newElement('TextInput', 'state');
     $element->setLabel('State');
     $element->addValidator(new \Foundation\Form\Validator\MaximumLength($element, 64));
     $element = $field->newElement('TextInput', 'country');
     $element->setLabel('Country');
     $element->addValidator(new \Foundation\Form\Validator\MaximumLength($element, 64));
     $element = $field->newElement('TextInput', 'postalCode');
     $element->setLabel('Postal Code');
     $element->addValidator(new \Foundation\Form\Validator\MaximumLength($element, 10));
     $element = $field->newElement('Textarea', 'searchTerms');
     $form->newButton('submit', 'Save');
     $this->setVar('form', $form);
     if ($input = $form->processInput($this->post)) {
         $school = new \Jazzee\Entity\School();
         $school->setName($input->get('name'));
         $school->setCode($input->get('code'));
         $school->setCity($input->get('city'));
         $school->setState($input->get('state'));
         $school->setCountry($input->get('country'));
         $school->setPostalCode($input->get('postalCode'));
         $school->setSearchTerms($input->get('searchTerms'));
         $this->_em->persist($school);
         $this->addMessage('success', "New School Saved");
         $this->redirectPath('manage/schools');
     }
 }