Inheritance: extends Prezent\Doctrine\Translatable\Entity\AbstractTranslation, use trait Ojs\CoreBundle\Entity\DisplayTrait
コード例 #1
0
ファイル: Period.php プロジェクト: hasantayyar/ojs
 /**
  * Translation helper method
  * @param null $locale
  * @return mixed|null|\Ojs\JournalBundle\Entity\PeriodTranslation
  */
 public function translate($locale = null)
 {
     if (null === $locale) {
         $locale = $this->currentLocale;
     }
     if (!$locale) {
         throw new \RuntimeException('No locale has been set and currentLocale is empty');
     }
     if ($this->currentTranslation && $this->currentTranslation->getLocale() === $locale) {
         return $this->currentTranslation;
     }
     $defaultTranslation = $this->translations->get($this->getDefaultLocale());
     if (!($translation = $this->translations->get($locale))) {
         $translation = new PeriodTranslation();
         if (!is_null($defaultTranslation)) {
             $translation->setPeriod($defaultTranslation->getPeriod());
         }
         $translation->setLocale($locale);
         $this->addTranslation($translation);
     }
     $this->currentTranslation = $translation;
     return $translation;
 }
コード例 #2
0
 private function normalizePeriods()
 {
     $this->io->newLine();
     $this->io->text('normalizing periods');
     $this->getContainer()->getParameter('locale');
     $this->io->progressStart();
     $periods = $this->em->getRepository('OjsJournalBundle:Period')->findAll();
     foreach ($periods as $period) {
         $getTranslation = $this->em->getRepository('OjsJournalBundle:PeriodTranslation')->findOneBy(['translatable' => $period, 'locale' => $this->locale]);
         if (!$getTranslation) {
             $this->io->progressAdvance();
             $newPeriodTranslation = new PeriodTranslation();
             $newPeriodTranslation->setTranslatable($period);
             $newPeriodTranslation->setLocale($this->locale);
             $newPeriodTranslation->setPeriod('-');
             $this->em->persist($newPeriodTranslation);
         }
     }
     $this->em->flush();
     $this->io->newLine();
 }