コード例 #1
0
ファイル: CodeController.php プロジェクト: Silwereth/sulu
 /**
  * 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);
 }
コード例 #2
0
 /**
  * create a new code.
  *
  * @param $catalogueId
  * @param $item
  */
 private function newCode($catalogueId, $item)
 {
     /** @var Catalogue $catalogue */
     $catalogue = $this->getDoctrine()->getRepository('SuluTranslateBundle:Catalogue')->getCatalogueById($catalogueId);
     $code = new Code();
     $code->setCode($item['code']['code']);
     $code->setBackend($item['code']['backend']);
     $code->setFrontend($item['code']['frontend']);
     $code->setLength($item['code']['length']);
     $code->setPackage($catalogue->getPackage());
     $this->getDoctrine()->getManager()->persist($code);
     $this->getDoctrine()->getManager()->flush();
     $translation = new Translation();
     $translation->setValue($item['value']);
     $translation->setCode($code);
     $translation->setCatalogue($catalogue);
     $this->getDoctrine()->getManager()->persist($translation);
 }
コード例 #3
0
 public function setUp()
 {
     $this->em = $this->db('ORM')->getOm();
     $this->purgeDatabase();
     $package1 = new Package();
     $package1->setName('Package1');
     $this->em->persist($package1);
     $this->package1 = $package1;
     $package2 = new Package();
     $package2->setName('Package2');
     $this->em->persist($package2);
     $catalogue1 = new Catalogue();
     $catalogue1->setLocale('de');
     $catalogue1->setIsDefault(true);
     $catalogue1->setPackage($package1);
     $this->em->persist($catalogue1);
     $this->catalogue1 = $catalogue1;
     $catalogue2 = new Catalogue();
     $catalogue2->setLocale('fr');
     $catalogue2->setIsDefault(false);
     $catalogue2->setPackage($package1);
     $this->em->persist($catalogue2);
     $this->catalogue2 = $catalogue2;
     $catalogue3 = new Catalogue();
     $catalogue3->setLocale('fr');
     $catalogue3->setIsDefault(false);
     $catalogue3->setPackage($package2);
     $this->em->persist($catalogue3);
     $code1 = new Code();
     $code1->setCode('code.1');
     $code1->setLength(100);
     $code1->setBackend(1);
     $code1->setFrontend(1);
     $code1->setPackage($package1);
     $this->em->persist($code1);
     $this->code1 = $code1;
     $code2 = new Code();
     $code2->setCode('code.2');
     $code2->setLength(100);
     $code2->setBackend(1);
     $code2->setFrontend(1);
     $code2->setPackage($package1);
     $this->em->persist($code2);
     $code3 = new Code();
     $code3->setCode('code.3');
     $code3->setLength(100);
     $code3->setBackend(1);
     $code3->setFrontend(1);
     $code3->setPackage($package2);
     $this->em->persist($code3);
     $this->em->flush();
     $t1_1 = new Translation();
     $t1_1->setValue('Code 1.1');
     $t1_1->setCatalogue($catalogue1);
     $t1_1->setCode($code1);
     $this->em->persist($t1_1);
     $this->catalogue1Translation1 = $t1_1;
     $t1_2 = new Translation();
     $t1_2->setValue('Code 1.2');
     $t1_2->setCatalogue($catalogue2);
     $t1_2->setCode($code1);
     $this->em->persist($t1_2);
     $this->catalogue1Translation2 = $t1_2;
     $t2_2 = new Translation();
     $t2_2->setValue('Code 2.2');
     $t2_2->setCatalogue($catalogue2);
     $t2_2->setCode($code2);
     $this->em->persist($t2_2);
     $this->em->flush();
 }