/** * @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); }
/** * 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; }
/** * @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; }
/** * {@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(); }
/** * @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); }
/** * @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]; }