Newscoop\NewscoopBundle\Entity\Topic::setTranslatableLocale PHP Метод

setTranslatableLocale() публичный Метод

Sets the Used locale to override Translation listener`s locale.
public setTranslatableLocale ( mixed $locale ) : self
$locale mixed the locale
Результат self
    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * Saves new topic. Possibility to overwrite AUTO strategy (set custom ids).
  *
  * @param Topic       $node   Topic object
  * @param string|null $locale Language code
  *
  * @return bool
  *
  * @throws ResourcesConflictException When Topic already exists
  */
 public function saveNewTopic(Topic $node, $locale = null)
 {
     $node->setTranslatableLocale($locale ?: $node->getTranslatableLocale());
     $topicTranslation = $this->getTopicRepository()->createQueryBuilder('t')->join('t.translations', 'tt')->where('tt.locale = :locale')->andWhere('tt.content = :title')->andWhere("tt.field = 'title'")->setParameters(array('title' => $node->getTitle(), 'locale' => $node->getTranslatableLocale()))->getQuery()->getOneOrNullResult();
     if ($topicTranslation) {
         throw new ResourcesConflictException('Topic already exists', 409);
     }
     if (!$node->getParent()) {
         $qb = $this->getTopicRepository()->createQueryBuilder('t');
         $maxOrderValue = $qb->select('MAX(t.topicOrder)')->setMaxResults(1)->getQuery()->getSingleScalarResult();
         $node->setOrder((int) $maxOrderValue + 1);
     }
     $node->addTranslation(new TopicTranslation($locale ?: $node->getTranslatableLocale(), 'title', $node->getTitle(), true));
     $this->em->persist($node);
     $metadata = $this->em->getClassMetaData(get_class($node));
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $this->em->flush();
     $this->dispatcher->dispatch('topic.create', new GenericEvent($this, array('title' => $node->getTitle(), 'id' => array('id' => $node->getId()), 'diff' => (array) $node)));
     return true;
 }
All Usage Examples Of Newscoop\NewscoopBundle\Entity\Topic::setTranslatableLocale