Sulu\Component\Content\Query\ContentQueryExecutor::execute PHP Method

execute() public method

public execute ( $webspaceKey, $locales, Sulu\Component\Content\Query\ContentQueryBuilderInterface $contentQueryBuilder, $flat = true, $depth, $limit = null, $offset = null, $moveUp = false )
$contentQueryBuilder Sulu\Component\Content\Query\ContentQueryBuilderInterface
    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;
    }

Usage Example

 public function testOrder()
 {
     $this->executor->execute('default', ['en'], $this->builder)->willReturn([['uuid' => 1], ['uuid' => 2], ['uuid' => 3]]);
     $this->container = new InternalLinksContainer([2, 3, 1], $this->executor->reveal(), $this->builder->reveal(), [], new NullLogger(), 'default', 'en');
     $result = $this->container->getData();
     $this->assertEquals([['uuid' => 2], ['uuid' => 3], ['uuid' => 1]], $result);
 }
All Usage Examples Of Sulu\Component\Content\Query\ContentQueryExecutor::execute