Example #1
0
 /**
  * Creates a new code.
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function postAction(Request $request)
 {
     $c = $request->get('code');
     $backend = $request->get('backend');
     $frontend = $request->get('frontend');
     $length = $request->get('length');
     $package = $request->get('package');
     $location = $request->get('location');
     $translations = $request->get('translations');
     if ($c != null && $backend != null && $frontend != null && $location != null && $package != null) {
         $em = $this->getDoctrine()->getManager();
         $code = new Code();
         $code->setCode($c);
         $code->setBackend($backend);
         $code->setFrontend($frontend);
         $code->setLength($length);
         $code->setCode($c);
         $code->setPackage($em->getReference(self::$packageEntity, $package['id']));
         $code->setLocation($em->getReference(self::$locationEntity, $location['id']));
         $em->persist($code);
         $em->flush();
         if ($translations != null) {
             foreach ($translations as $translation) {
                 $t = new Translation();
                 $t->setValue($translation['value']);
                 $t->setCode($code);
                 $code->addTranslation($t);
                 // TODO Catalogue: which format?
                 $t->setCatalogue($em->getReference(self::$catalogueEntity, $translation['catalogue']['id']));
                 $em->persist($t);
             }
         }
         $em->flush();
         $view = $this->view($code, 200);
     } else {
         $view = $this->view(null, 400);
     }
     return $this->handleView($view);
 }
Example #2
0
 public function setUp()
 {
     $this->em = $this->db('ORM')->getOm();
     $this->purgeDatabase();
     $this->export = new Export($this->em);
     //
     // Package - id 1
     // -------------------------------
     //Insert some data in the database
     $package = new Package();
     $package->setName('Export');
     $this->package1 = $package;
     $this->em->persist($package);
     $catalogue = new Catalogue();
     $catalogue->setPackage($package);
     $catalogue->setIsDefault(false);
     $catalogue->setLocale('en');
     $this->em->persist($catalogue);
     $location1 = new Location();
     $location1->setName('Newsletter');
     $location1->setPackage($package);
     $this->em->persist($location1);
     $location2 = new Location();
     $location2->setName('Portals');
     $location2->setPackage($package);
     $this->em->persist($location2);
     $code1 = new Code();
     $code1->setPackage($package);
     $code1->setCode('export.easy');
     $code1->setBackend(true);
     $code1->setFrontend(true);
     $code1->setLocation($location1);
     $this->em->persist($code1);
     $code2 = new Code();
     $code2->setPackage($package);
     $code2->setCode('export.great');
     $code2->setBackend(true);
     $code2->setFrontend(false);
     $code2->setLocation($location1);
     $this->em->persist($code2);
     $code3 = new Code();
     $code3->setPackage($package);
     $code3->setCode('export.configurable');
     $code3->setBackend(false);
     $code3->setFrontend(true);
     $code3->setLocation($location2);
     $this->em->persist($code3);
     $this->em->flush();
     $translation1 = new Translation();
     $translation1->setCatalogue($catalogue);
     $translation1->setCode($code1);
     $translation1->setValue('Exports made easy');
     $this->em->persist($translation1);
     $translation2 = new Translation();
     $translation2->setCatalogue($catalogue);
     $translation2->setCode($code2);
     $translation2->setValue('Exports are great');
     $this->em->persist($translation2);
     $translation3 = new Translation();
     $translation3->setCatalogue($catalogue);
     $translation3->setCode($code3);
     $translation3->setValue('Exports are configurable');
     $this->em->persist($translation3);
     //
     // Package - id 2
     // -------------------------------
     //Insert some data in the database
     $package2 = new Package();
     $package2->setName('Export2');
     $this->em->persist($package2);
     $catalogue2 = new Catalogue();
     $catalogue2->setPackage($package2);
     $catalogue2->setIsDefault(false);
     $catalogue2->setLocale('en');
     $this->em->persist($catalogue2);
     $location21 = new Location();
     $location21->setName('Newsletter');
     $location21->setPackage($package2);
     $this->em->persist($location21);
     $location22 = new Location();
     $location22->setName('Portals');
     $location22->setPackage($package2);
     $this->em->persist($location22);
     $code21 = new Code();
     $code21->setPackage($package2);
     $code21->setCode('export.easy2');
     $code21->setBackend(true);
     $code21->setFrontend(true);
     $code21->setLocation($location21);
     $this->em->persist($code21);
     $code22 = new Code();
     $code22->setPackage($package2);
     $code22->setCode('export.great2');
     $code22->setBackend(true);
     $code22->setFrontend(false);
     $code22->setLocation($location21);
     $this->em->persist($code22);
     $code23 = new Code();
     $code23->setPackage($package2);
     $code23->setCode('export.configurable2');
     $code23->setBackend(false);
     $code23->setFrontend(true);
     $code23->setLocation($location22);
     $this->em->persist($code23);
     $this->em->flush();
     $translation21 = new Translation();
     $translation21->setCatalogue($catalogue2);
     $translation21->setCode($code21);
     $translation21->setValue('Exports made super easy');
     $this->em->persist($translation21);
     $translation22 = new Translation();
     $translation22->setCatalogue($catalogue2);
     $translation22->setCode($code22);
     $translation22->setValue('Exports are super great');
     $this->em->persist($translation22);
     $translation23 = new Translation();
     $translation23->setCatalogue($catalogue2);
     $translation23->setCode($code23);
     $translation23->setValue('Exports are super configurable');
     $this->em->persist($translation23);
     $this->em->flush();
 }