Esempio n. 1
0
 public function testGetId()
 {
     $this->client->request('GET', '/api/codes/' . $this->code3->getId());
     $response = json_decode($this->client->getResponse()->getContent());
     $this->assertNotNull($this->code3->getId(), $response->id);
     $this->assertEquals($this->code3->getCode(), $response->code);
     $this->assertEquals($this->code3->getBackend(), $response->backend);
     $this->assertEquals($this->code3->getFrontend(), $response->frontend);
     $this->assertEquals($this->code3->getLength(), $response->length);
     $this->assertNotNull($this->code3->getLocation()->getId(), $response->location->id);
     $this->assertEquals($this->code3_t1->getValue(), $response->translations[0]->value);
     $this->assertEquals($this->code3_t2->getValue(), $response->translations[1]->value);
 }
Esempio n. 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);
 }
Esempio n. 3
0
 /**
  * Updates the code for the given id.
  *
  * @param Request $request
  * @param int     $id      The id of the package to update
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function putAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var Code $code */
     $code = $this->getDoctrine()->getRepository(self::$entityName)->getCodeById($id);
     $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');
     $translationRepository = $this->getDoctrine()->getRepository(self::$translationEntity);
     if (!$code) {
         // No Code exists
         $view = $this->view(null, 404);
     } else {
         $code->setCode($c);
         $code->setBackend($backend);
         $code->setFrontend($frontend);
         $code->setLength($length);
         $code->setPackage($em->getReference(self::$packageEntity, $package['id']));
         $code->setLocation($em->getReference(self::$locationEntity, $location['id']));
         if ($translations != null && count($translations) > 0) {
             foreach ($translations as $translationData) {
                 /** @var Translation $translation */
                 $translation = $translationRepository->findOneBy(['code' => $code->getId(), 'catalogue' => $translationData['catalogue']['id']]);
                 if ($translation != null) {
                     $translation->setValue($translationData['value']);
                     $translation->setCode($code);
                     $translation->setCatalogue($em->getReference(self::$catalogueEntity, $translationData['catalogue']['id']));
                 } else {
                     // Create a new Translation
                     $translation = new Translation();
                     $translation->setValue($translationData['value']);
                     $translation->setCode($code);
                     $code->addTranslation($translation);
                     $translation->setCatalogue($em->getReference(self::$catalogueEntity, $translationData['catalogue']['id']));
                     $em->persist($translation);
                 }
             }
         }
         $em->flush();
         $view = $this->view($code, 200);
     }
     return $this->handleView($view);
 }
 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();
 }
Esempio n. 5
0
 /**
  * Imports a single file.
  *
  * @param Package         $package  the package to import the file into
  * @param LoaderInterface $loader
  * @param string          $path     The path to the file
  * @param string          $filename The filename
  * @param bool            $backend  True to make the file available in the backend
  * @param bool            $frontend True to make the file available in the frontend
  * @param bool            $throw    If true the methods throws exception if the a file cannot be found
  *
  * @throws \Exception
  * @throws \InvalidArgumentException
  * @throws \Symfony\Component\Translation\Exception\NotFoundResourceException
  */
 private function importFile($package, $loader, $path, $filename, $backend = true, $frontend = false, $throw = false)
 {
     try {
         $this->output->writeln($filename);
         $filePath = $path ? $path . '/' . $filename : $filename;
         $file = $loader->load($filePath, $this->locale);
         // find the catalogue from this package matching the given locale
         $catalogue = null;
         $newCatalogue = true;
         foreach ($package->getCatalogues() as $packageCatalogue) {
             /** @var $packageCatalogue Catalogue */
             if ($packageCatalogue->getLocale() === $this->locale) {
                 $catalogue = $packageCatalogue;
                 $newCatalogue = false;
             }
         }
         // if no catalogue is found create a new one
         if ($newCatalogue === true) {
             $catalogue = new Catalogue();
             if ($this->locale === $this->defaultLocale) {
                 $catalogue->setIsDefault(true);
             } else {
                 $catalogue->setIsDefault(false);
             }
             $catalogue->setPackage($package);
             $package->addCatalogue($catalogue);
             $catalogue->setLocale($this->locale);
             $this->em->persist($catalogue);
             $this->em->flush();
         }
         $allMessages = $file->all()['messages'];
         $progress = new ProgressHelper();
         $progress->start($this->output, count($allMessages));
         // loop through all translation units in the file
         foreach ($allMessages as $key => $message) {
             // Check if code is already existing in current catalogue
             if (!$newCatalogue && ($translate = $catalogue->findTranslation($key))) {
                 // Update the old translate
                 $translate->setValue($message);
             } else {
                 // Create new code, if not already existing
                 $code = $package->findCode($key);
                 if (!$code) {
                     $code = new Code();
                     $code->setPackage($package);
                     $code->setCode($key);
                     $code->setBackend($backend);
                     $code->setFrontend($frontend);
                     $this->em->persist($code);
                     $this->em->flush();
                 }
                 // Create new translate
                 $translate = new Translation();
                 $translate->setCode($code);
                 $translate->setValue($message);
                 $translate->setCatalogue($catalogue);
                 $this->em->persist($translate);
             }
             $progress->advance();
         }
         $this->em->flush();
         $progress->finish();
     } catch (\InvalidArgumentException $e) {
         if ($e instanceof NotFoundResourceException) {
             if ($throw === true) {
                 throw $e;
             }
         } else {
             throw $e;
         }
     }
 }
Esempio n. 6
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();
 }