Sulu\Component\Content\Query\ContentQueryBuilder::build PHP Method

build() public method

public build ( $webspaceKey, $locales )
    public function build($webspaceKey, $locales)
    {
        $additionalFields = [];
        $where = '';
        $select = ['page.*'];
        $order = [];
        foreach ($locales as $locale) {
            $this->setLocale($locale);
            $additionalFields[$locale] = [];
            if ($this->excerpt) {
                $this->buildSelectorForExcerpt($locale, $additionalFields);
            }
            $customSelect = $this->buildSelect($webspaceKey, $locale, $additionalFields);
            if ($customSelect !== '') {
                $select[] = $customSelect;
            }
            if ($this->published) {
                $where .= sprintf('%s ((page.[%s] = %s OR page.[%s] = %s)', $where !== '' ? 'OR ' : '', $this->getPropertyName('state'), Structure::STATE_PUBLISHED, $this->getPropertyName('shadow-on'), 'true');
            }
            $customWhere = $this->buildWhere($webspaceKey, $locale);
            if ($customWhere !== null && $customWhere !== '') {
                $where = $where . ($where !== '' ? ' AND ' : '') . $customWhere;
            }
            if ($this->published) {
                $where .= ')';
            }
            $customOrder = $this->buildOrder($webspaceKey, $locale);
            if (!empty($customOrder)) {
                $order[] = $customOrder;
            } else {
                $order = ['[jcr:path] ASC'];
            }
        }
        // build sql2 query string
        $sql2 = sprintf("SELECT %s\n             FROM [nt:unstructured] AS page\n             WHERE (page.[jcr:mixinTypes] = 'sulu:page' OR page.[jcr:mixinTypes] = 'sulu:home')\n                AND (%s)\n                %s %s", implode(', ', $select), $where, count($order) > 0 ? 'ORDER BY' : '', implode(', ', $order));
        return [$sql2, $additionalFields];
    }