setSubject() public method

public setSubject ( string $subject )
$subject string
コード例 #1
0
 private function normalizeSubjects()
 {
     $this->io->newLine();
     $this->io->text('normalizing subjects');
     $this->getContainer()->getParameter('locale');
     $this->io->progressStart();
     $subjects = $this->em->getRepository('OjsJournalBundle:Subject')->findAll();
     foreach ($subjects as $subject) {
         $getTranslation = $this->em->getRepository('OjsJournalBundle:SubjectTranslation')->findOneBy(['translatable' => $subject, 'locale' => $this->locale]);
         if (!$getTranslation) {
             $this->io->progressAdvance();
             $newSubjectTranslation = new SubjectTranslation();
             $newSubjectTranslation->setTranslatable($subject);
             $newSubjectTranslation->setLocale($this->locale);
             $newSubjectTranslation->setSubject('-');
             $this->em->persist($newSubjectTranslation);
         }
     }
     $this->em->flush();
     $this->io->newLine();
 }
コード例 #2
0
ファイル: Subject.php プロジェクト: beyzakokcan/ojs
 /**
  * Translation helper method
  * @param null $locale
  * @return mixed|null|\Ojs\JournalBundle\Entity\SubjectTranslation
  */
 public function translate($locale = null)
 {
     if (null === $locale) {
         $locale = $this->currentLocale;
     }
     if (!$locale && $this->parent !== null) {
         $locale = $this->parent->getCurrentLocale();
     }
     if (!$locale) {
         throw new \RuntimeException('No locale has been set and currentLocale is empty');
     }
     /** @var SubjectTranslation $currentTranslation */
     $currentTranslation = $this->currentTranslation;
     if ($currentTranslation && $currentTranslation->getLocale() === $locale) {
         return $currentTranslation;
     }
     /** @var SubjectTranslation $defaultTranslation */
     $defaultTranslation = $this->translations->get($this->getDefaultLocale());
     if (!($translation = $this->translations->get($locale))) {
         $translation = new SubjectTranslation();
         if (!is_null($defaultTranslation)) {
             $translation->setSubject($defaultTranslation->getSubject());
             $translation->setDescription($defaultTranslation->getDescription());
         }
         $translation->setLocale($locale);
         $this->addTranslation($translation);
     }
     $this->currentTranslation = $translation;
     return $translation;
 }