Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function assertLangTranslationDocumentData(Translation $translation)
 {
     $this->assertMongoId($translation->getId());
     $this->assertTrue(strlen($translation->getKey()) > 0);
     $this->assertTrue(strlen($translation->getValue()) > 0);
     $this->assertTrue($translation->getLanguage() instanceof Language);
 }
Ejemplo n.º 2
0
 /**
  * @param $key
  * @param $value
  * @param $reference
  * @return Translation
  */
 protected function createTranslateObj($key, $value, $reference)
 {
     $translation = new Translation();
     $translation->setLanguage($reference);
     $translation->setKey($key);
     $translation->setValue($value);
     return $translation;
 }
Ejemplo n.º 3
0
 /**
  * @return object
  */
 public function testLang()
 {
     $language = new Language();
     $language->setKey(static::LANG);
     $language->setLastUpdate(new \MongoDate());
     $translation = new Translation();
     $translation->setKey(static::TRANSLATION_KEY);
     $translation->setValue(static::TRANSLATION_VALUE);
     $translation->setLanguage($language);
     $language->addTranslation($translation);
     $this->documentManager->persist($language);
     $this->documentManager->persist($translation);
     $this->documentManager->flush();
     $this->assertLangDocument($language);
     $this->assertLangDocumentData($language);
     $this->assertLangTranslationDocument($translation);
     $this->assertLangTranslationDocumentData($translation);
     $this->assertLangTranslationDocumentData($language->getTranslations()->getIterator()[0]);
     return (object) ['language' => $language, 'translation' => $translation];
 }
Ejemplo n.º 4
0
 /**
  * @param Request $request
  * @param $lang
  * @param $key
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function postLangKeyAction(Request $request, $lang, $key)
 {
     $language = $this->getLang($lang, true);
     $documentManager = $this->get('doctrine_mongodb')->getManager();
     $translation = new Translation();
     $translation->setLanguage($language);
     $translation->setKey($key);
     $translation->setValue($request->get('value'));
     $documentManager->persist($translation);
     try {
         $documentManager->flush();
     } catch (\Exception $e) {
         if ($e instanceof \MongoCursorException) {
             throw new ConflictHttpException('Duplicate entry for lang: ' . $lang . ' with key: ' . $key, $e);
         }
     }
     $language->setLastUpdate(new \MongoDate());
     $documentManager->getRepository('TranslateBundle:Language');
     $documentManager->flush($language);
     $view = $this->view($translation);
     return $this->handleView($view);
 }