Ejemplo n.º 1
0
 public function setUp()
 {
     parent::setUp();
     $this->contentQueryExecutor = $this->prophesize('Sulu\\Component\\Content\\Query\\ContentQueryExecutorInterface');
     $this->contentQueryBuilder = $this->prophesize('Sulu\\Component\\Content\\Query\\ContentQueryBuilderInterface');
     $this->logger = $this->prophesize('Psr\\Log\\LoggerInterface');
     $this->property = $this->prophesize('Sulu\\Component\\Content\\Compat\\PropertyInterface');
     $this->type = new InternalLinks($this->contentQueryExecutor->reveal(), $this->contentQueryBuilder->reveal(), $this->logger->reveal(), 'some_template.html.twig');
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function execute($webspaceKey, $locales, ContentQueryBuilderInterface $contentQueryBuilder, $flat = true, $depth = -1, $limit = null, $offset = null, $moveUp = false)
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('ContentQuery::execute.build-query');
     }
     list($sql2, $fields) = $contentQueryBuilder->build($webspaceKey, $locales);
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.build-query');
         $this->stopwatch->start('ContentQuery::execute.execute-query');
     }
     $query = $this->createSql2Query($sql2, $limit, $offset);
     $queryResult = $query->execute();
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.execute-query');
         $this->stopwatch->start('ContentQuery::execute.preload-nodes.get-paths');
     }
     // this preloads all node which should are selected in the statement before
     // prevent the system to load each node individual
     $rootDepth = substr_count($this->sessionManager->getContentPath($webspaceKey), '/');
     $paths = [];
     /** @var Row $row */
     foreach ($queryResult as $row) {
         $pageDepth = substr_count($row->getPath('page'), '/') - $rootDepth;
         if ($depth === null || $depth < 0 || $depth > 0 && $pageDepth <= $depth) {
             $paths[] = $row->getPath('page');
         }
     }
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.preload-nodes.get-paths');
         $this->stopwatch->start('ContentQuery::execute.preload-nodes.execute');
     }
     $this->sessionManager->getSession()->getNodes($paths);
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.preload-nodes.execute');
         $this->stopwatch->start('ContentQuery::execute.rowsToList');
     }
     $result = $this->contentMapper->convertQueryResultToArray($queryResult, $webspaceKey, $locales, $fields, $depth, $contentQueryBuilder->getPublished());
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.rowsToList');
     }
     if (!$flat) {
         if ($this->stopwatch) {
             $this->stopwatch->start('ContentQuery::execute.build-tree');
         }
         $converter = new ListToTreeConverter($moveUp);
         $result = $converter->convert($result);
         if ($this->stopwatch) {
             $this->stopwatch->stop('ContentQuery::execute.build-tree');
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getFilteredNodes(array $filterConfig, $languageCode, $webspaceKey, $preview = false, $api = false, $exclude = [])
 {
     $limit = isset($filterConfig['limitResult']) ? $filterConfig['limitResult'] : null;
     $initParams = ['config' => $filterConfig];
     if ($exclude) {
         $initParams['excluded'] = $exclude;
     }
     $this->queryBuilder->init($initParams);
     $data = $this->queryExecutor->execute($webspaceKey, [$languageCode], $this->queryBuilder, true, -1, $limit);
     if ($api) {
         if (isset($filterConfig['dataSource'])) {
             if ($this->webspaceManager->findWebspaceByKey($filterConfig['dataSource']) !== null) {
                 $node = $this->sessionManager->getContentNode($filterConfig['dataSource']);
             } else {
                 $node = $this->sessionManager->getSession()->getNodeByIdentifier($filterConfig['dataSource']);
             }
         } else {
             $node = $this->sessionManager->getContentNode($webspaceKey);
         }
         $parentNode = $this->getParentNode($node->getIdentifier(), $webspaceKey, $languageCode);
         $result = $this->prepareNode($parentNode, $webspaceKey, $languageCode, 1, false);
         $result['_embedded']['nodes'] = $data;
         $result['total'] = count($result['_embedded']['nodes']);
     } else {
         $result = $data;
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getRootNavigation($webspaceKey, $locale, $depth = 1, $flat = false, $context = null, $loadExcerpt = false)
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('NavigationMapper::getRootNavigation.query');
     }
     $this->queryBuilder->init(['context' => $context, 'excerpt' => $loadExcerpt]);
     $result = $this->contentQuery->execute($webspaceKey, [$locale], $this->queryBuilder, $flat, $depth);
     for ($i = 0; $i < count($result); ++$i) {
         if (!isset($result[$i]['children'])) {
             $result[$i]['children'] = [];
         }
     }
     if ($this->stopwatch) {
         $this->stopwatch->stop('NavigationMapper::getRootNavigation.query');
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * lazy load data.
  */
 private function loadData($config, $excludeUuids, $limit, $offset)
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('SmartContent:loadData');
     }
     $result = [];
     if (array_key_exists('dataSource', $config) && $config['dataSource'] !== '') {
         $this->contentQueryBuilder->init(['config' => $config, 'properties' => $this->params['properties']->getValue(), 'excluded' => $excludeUuids]);
         $result = $this->contentQueryExecutor->execute($this->webspaceKey, [$this->languageCode], $this->contentQueryBuilder, true, -1, $limit, $offset);
     }
     if ($this->stopwatch) {
         $this->stopwatch->stop('SmartContent:loadData');
     }
     return $result;
 }
Ejemplo n.º 6
0
 /**
  * Resolves filters.
  */
 private function resolveFilters(array $filters, array $propertyParameter, array $options = [], $limit = null, $page = 1, $pageSize = null)
 {
     if (!array_key_exists('dataSource', $filters) || $filters['dataSource'] === '' || $limit !== null && $limit < 1) {
         return [[], false];
     }
     $properties = array_key_exists('properties', $propertyParameter) ? $propertyParameter['properties']->getValue() : [];
     $this->contentQueryBuilder->init(['config' => $filters, 'properties' => $properties, 'excluded' => $filters['excluded'], 'published' => !$this->showDrafts]);
     $hasNextPage = false;
     if ($pageSize !== null) {
         $result = $this->loadPaginated($options, $limit, $page, $pageSize);
         $hasNextPage = count($result) > $pageSize;
         $items = array_splice($result, 0, $pageSize);
     } else {
         $items = $this->load($options, $limit);
     }
     return [$items, $hasNextPage];
 }
Ejemplo n.º 7
0
 /**
  * lazy load data.
  */
 private function loadData()
 {
     $result = [];
     if ($this->ids !== null && count($this->ids) > 0) {
         $this->contentQueryBuilder->init(['ids' => $this->ids, 'properties' => isset($this->params['properties']) ? $this->params['properties']->getValue() : []]);
         $pages = $this->contentQueryExecutor->execute($this->webspaceKey, [$this->languageCode], $this->contentQueryBuilder);
         // init vars
         $map = [];
         // map pages
         foreach ($pages as $page) {
             $map[$page['uuid']] = $page;
         }
         foreach ($this->ids as $id) {
             if (isset($map[$id])) {
                 $result[] = $map[$id];
             }
         }
     }
     return $result;
 }