/**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $this->repo = $manager->getRepository('Kunstmaan\\TranslatorBundle\\Entity\\Translation');
     $helloWorld = new Model();
     $helloWorld->setKeyword('heading.hello_world');
     $helloWorld->setDomain('messages');
     $translations = array('en' => 'Hello World!', 'fr' => 'Bonjour tout le monde', 'nl' => 'Hallo wereld!');
     $needForFlush = false;
     foreach ($translations as $language => $text) {
         if ($this->hasFixtureInstalled('messages', 'heading.hello_world', $language)) {
             continue;
         }
         $helloWorld->addText($language, $text);
         $needForFlush = true;
     }
     $this->repo->createTranslations($helloWorld);
     if ($needForFlush === true) {
         $manager->flush();
     }
 }
 public function updateTranslations(\Kunstmaan\TranslatorBundle\Model\Translation $translationModel, $translationId)
 {
     $this->getEntityManager()->beginTransaction();
     try {
         /**
          * @var TextWithLocale $textWithLocale
          */
         foreach ($translationModel->getTexts() as $textWithLocale) {
             if ($textWithLocale->getId()) {
                 $translation = $this->find($textWithLocale->getId());
                 $translation->setLocale($textWithLocale->getLocale())->setText($textWithLocale->getText());
                 $this->getEntityManager()->persist($translation);
             } else {
                 $text = $textWithLocale->getText();
                 if (empty($text)) {
                     continue;
                 }
                 $translation = new Translation();
                 $translation->setDomain($translationModel->getDomain())->setKeyword($translationModel->getKeyword())->setTranslationId($translationId)->setLocale($textWithLocale->getLocale())->setText($textWithLocale->getText());
                 $this->getEntityManager()->persist($translation);
             }
         }
         $this->getEntityManager()->commit();
     } catch (\Exception $e) {
         $this->getEntityManager()->rollback();
     }
 }