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");
 }
示例#2
0
 /**
  * Returns an article topics list based on the given parameters.
  *
  * @param array   $p_parameters
  *                              An array of ComparisonOperation objects
  * @param string  $p_order
  *                              An array of columns and directions to order by
  * @param integer $p_start
  *                              The record number to start the list
  * @param integer $p_limit
  *                              The offset. How many records from $p_start will be retrieved.
  * @param integer $p_count
  *                              The total count of the elements; this count is computed without
  *                              applying the start ($p_start) and limit parameters ($p_limit)
  *
  * @return array $articleTopicsList
  *               An array of Topic objects
  */
 public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false)
 {
     global $g_ado_db;
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $paramsArray['parameters'] = serialize($p_parameters);
         $paramsArray['order'] = is_null($p_order) ? 'null' : $p_order;
         $paramsArray['start'] = $p_start;
         $paramsArray['limit'] = $p_limit;
         $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
         $articleTopicsList = $cacheListObj->fetchFromCache();
         if ($articleTopicsList !== false && is_array($articleTopicsList)) {
             return $articleTopicsList;
         }
     }
     $selectClauseObj = new SQLSelectClause();
     $countClauseObj = new SQLSelectClause();
     $rootTopicIds = array();
     // processes the parameters
     $hasArticleNr = false;
     foreach ($p_parameters as $parameter) {
         $comparisonOperation = self::ProcessListParameters($parameter);
         if (sizeof($comparisonOperation) < 1) {
             break;
         }
         if (strpos($comparisonOperation['left'], 'NrArticle') !== false) {
             $hasArticleNr = true;
         }
         if (strpos($comparisonOperation['left'], 'RootTopic') !== false) {
             $rootTopicIds[] = (int) $comparisonOperation['right'];
             continue;
         }
         $whereCondition = $g_ado_db->escapeOperation($comparisonOperation);
         $selectClauseObj->addWhere($whereCondition);
         $countClauseObj->addWhere($whereCondition);
     }
     // validates whether article number was given
     if ($hasArticleNr === false) {
         CampTemplate::singleton()->trigger_error("missed parameter Article Number in statement list_article_topics");
         return array();
     }
     if (count($rootTopicIds) > 0) {
         $subtopicsQuery = Topic::BuildSubtopicsQueryWithoutDepth($rootTopicIds);
         $whereCondition = 'TopicId IN (' . $subtopicsQuery->buildQuery() . ')';
         $selectClauseObj->addWhere($whereCondition);
         $countClauseObj->addWhere($whereCondition);
     }
     // sets the main table and columns to be fetched
     $tmpArticleTopic = new ArticleTopic();
     $selectClauseObj->setTable($tmpArticleTopic->getDbTableName());
     $selectClauseObj->addColumn('TopicId');
     $countClauseObj->setTable($tmpArticleTopic->getDbTableName());
     $countClauseObj->addColumn('COUNT(*)');
     unset($tmpArticleTopic);
     if (!is_array($p_order)) {
         $p_order = array();
     }
     // sets the order condition if any
     foreach ($p_order as $orderColumn => $orderDirection) {
         $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
     }
     // sets the limit
     $selectClauseObj->setLimit($p_start, $p_limit);
     // builds the query and executes it
     $selectQuery = $selectClauseObj->buildQuery();
     $topics = $g_ado_db->GetAll($selectQuery);
     if (is_array($topics)) {
         $countQuery = $countClauseObj->buildQuery();
         $p_count = $g_ado_db->GetOne($countQuery);
         // builds the array of topic objects
         $articleTopicsList = array();
         foreach ($topics as $topic) {
             $articleTopicsList[] = $topic['TopicId'];
         }
     } else {
         $articleTopicsList = array();
         $p_count = 0;
     }
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($articleTopicsList);
     }
     return $articleTopicsList;
 }
示例#3
0
 /**
  * Get topic id
  *
  * @return int
  */
 public function getTopicId()
 {
     return $this->topic->getId();
 }
示例#4
0
 public function getTranslatableTopicLocale(Topic $topic)
 {
     foreach ($topic->getTranslations()->toArray() as $translation) {
         if ($translation->getField() == 'title' && $topic->getTitle() == $translation->getContent()) {
             return $translation->getLocale();
         }
     }
 }
示例#5
0
 /**
  * Deletes the topic. If topic is attached to any article
  * it is first detached and deleted.
  *
  * @param Topic $topic Topic
  *
  * @return bool
  */
 public function deleteTopic(Topic $topic)
 {
     if ($this->isAttached($topic->getId())) {
         $this->removeTopicFromAllArticles($topic->getId());
     }
     $this->removeTopicFromAllUsers($topic->getId());
     $this->em->remove($topic);
     $this->em->flush();
     $this->em->clear();
     return true;
 }
示例#6
0
 /**
  * Dispatch event
  *
  * @param Newscoop\Entity\User                 $user
  * @param Newscoop\NewscoopBundle\Entity\Topic $topic
  */
 private function notify(User $user, Topic $topic)
 {
     if (empty($this->dispatcher)) {
         return;
     }
     $this->dispatcher->dispatch('topic.follow', new \Newscoop\EventDispatcher\Events\GenericEvent($this, array('topic_name' => $topic->getName(), 'topic_id' => $topic->getTopicId(), 'user' => $user)));
 }
 public function its_unlinkFromUserAction_should_unlink_topic_from_user($request, $repository, $user)
 {
     $topic = new Topic();
     $topic->setId(10);
     $topic->setTitle('test');
     $topic->setParent(null);
     $userId = 1;
     $parameterBag = new ParameterBag();
     $parameterBag->set('links', array(array('object' => $topic)));
     $request->attributes = $parameterBag;
     $repository->findOneBy(array('id' => $userId))->shouldBeCalled()->willReturn($user);
     $this->unlinkFromUserAction($request, $userId)->shouldReturn(null);
 }
示例#8
0
     }
 }
 // if child
 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);
             }