public function it_should_return_a_path_of_the_topic(JsonSerializationVisitor $visitor, Topic $topic, $topicRepository) { $topic->getId()->willReturn(1); $topic->getTitle()->willReturn("Test topic"); $topic->getParent()->willReturn("Parent topic"); $topicRepository->getReadablePath($topic)->willReturn(" / Parent topic / Test topic"); $type = array('name' => "topic_path", 'params' => array()); $this->serializeToJson($visitor, $topic, $type)->shouldReturn(" / Parent topic / Test topic"); }
/** * 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; }