コード例 #1
0
 /**
  * @inheritdoc
  */
 public function assertLangDocumentData(Language $lang)
 {
     $this->assertMongoId($lang->getId());
     $this->assertTrue(strlen($lang->getKey()) > 0);
     $this->assertTrue(count($lang->getTranslations()) > 0);
     $this->assertTrue($lang->getLastUpdate() instanceof \MongoDate);
 }
コード例 #2
0
 /**
  * Look for the translate at Language Document in order to translate from DB registers
  *
  * @param $value
  * @param $lang
  * @return string
  */
 public function translateFilter($value, $lang)
 {
     if (!$this->language) {
         $langDM = $this->container->get('doctrine_mongodb')->getRepository('TranslateBundle:Language');
         $this->language = $langDM->findOneByKey($lang);
     }
     return ($trans = $this->language->findTranslationByKey($value)) ? $trans->getValue() : $value;
 }
コード例 #3
0
 /**
  * @param $key
  * @return string
  */
 protected function translate($key)
 {
     if (!$this->language) {
         $langDM = $this->get('doctrine_mongodb')->getRepository('TranslateBundle:Language');
         $this->language = $langDM->findOneByKey($this->languageKey);
     }
     return ($trans = $this->language->findTranslationByKey($key)) ? $trans->getValue() : $key;
 }
コード例 #4
0
ファイル: LoadLangs.php プロジェクト: renatomefidf/sammui
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     foreach (static::$default_langs as $lang) {
         $language = new Language();
         $language->setKey($lang);
         $language->setLastUpdate(new \MongoDate());
         $manager->persist($language);
         $this->addReference(static::$reference_prefix . $lang, $language);
     }
     $manager->flush();
 }
コード例 #5
0
 /**
  * @param $lang
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function postLangAction($lang)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $language = new Language();
     $language->setKey($lang);
     $language->setLastUpdate(new \MongoDate());
     $dm->persist($language);
     try {
         $dm->flush();
     } catch (\Exception $e) {
         if ($e instanceof \MongoCursorException) {
             throw new ConflictHttpException('Duplicate entry for lang: ' . $lang, $e);
         }
     }
     $view = $this->view($language);
     return $this->handleView($view);
 }
コード例 #6
0
ファイル: DocumentsTest.php プロジェクト: renatomefidf/sammui
 /**
  * @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];
 }