Sets the Used locale to override Translation listener`s locale.
public setTranslatableLocale ( mixed $locale ) : self | ||
$locale | mixed | the locale |
Résultat | self |
/** * 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; }
if (count($row) > 1) { try { $topicToInsert = end($row); $topicToInsertDetails = $app['db']->fetchAll($topicSql, array($topicToInsert)); $parentTopic = prev($row); $parentTopicDetails = $app['db']->fetchAll($topicSql, array($parentTopic)); if (empty($parentTopicDetails) || empty($topicToInsertDetails)) { continue; } $params = array('parent' => $parentTopic, 'last' => true); try { $locale = $app['orm.em']->getReference("Newscoop\\Entity\\Language", $topicToInsertDetails[0]['languageId'])->getCode(); $topic = new Topic(); $topic->setId($topicToInsertDetails[0]['id']); $topic->setTitle($topicToInsertDetails[0]['name']); $topic->setTranslatableLocale($locale); $app['topics_service']->saveTopicPosition($topic, $params); } catch (\Exception $e) { //topic already exists or language can not be found continue; } if (count($topicToInsertDetails) > 1) { unset($topicToInsertDetails[0]); foreach ($topicToInsertDetails as $key => $translation) { $locale = $app['orm.em']->getReference("Newscoop\\Entity\\Language", $translation['languageId'])->getCode(); $topicTranslation = new TopicTranslation($locale, 'title', $translation['name']); $topic->addTranslation($topicTranslation); } $app['orm.em']->flush(); } } catch (EntityNotFoundException $e) {