/** * Assign a new instance of QueryBuilder to the loader and build the main query for * loading pages * * @param $replace bool Set to replace the existing query builder if it exists */ private function _buildQuery($replace = false) { if (null === $this->_queryBuilder || $replace === true) { $this->_queryBuilder = $this->_queryBuilderFactory->getQueryBuilder()->select(['page.page_id AS id', 'page.title AS title', 'page.type AS type', 'page.publish_at AS publishAt', 'page.unpublish_at AS unpublishAt', 'page.created_at AS createdAt', 'page.created_by AS createdBy', 'page.updated_at AS updatedAt', 'page.created_by AS updatedBy', 'page.deleted_at AS deletedAt', 'page.deleted_by AS deletedBy', 'IFNULL(CONCAT(( SELECT CONCAT(\'/\',GROUP_CONCAT(p.slug ORDER BY p.position_depth ASC SEPARATOR \'/\')) FROM page AS p WHERE p.position_left < page.position_left AND p.position_right > page.position_right),\'/\',page.slug),page.slug) AS slug', 'page.position_left AS `left`', 'page.position_right AS `right`', 'page.position_depth AS depth', 'page.meta_title AS metaTitle', 'page.meta_description AS metaDescription', 'page.meta_html_head AS metaHtmlHead', 'page.meta_html_foot AS metaHtmlFoot', 'page.visibility_search AS visibilitySearch', 'page.visibility_menu AS visibilityMenu', 'page.visibility_aggregator AS visibilityAggregator', 'page.password AS password', 'page.access AS access', 'GROUP_CONCAT(page_access_group.group_name SEPARATOR \',\') AS accessGroups'])->from('page')->leftJoin('page_access_group', 'page_access_group.page_id = page.page_id')->groupBy('page.page_id'); if ($this->_order !== PageOrder::NONE) { $this->_queryBuilder->orderBy($this->_getOrderStatement()); } if (!$this->_loadDeleted) { $this->_queryBuilder->where('page.deleted_at IS NULL'); } if (!$this->_loadUnpublished) { $this->_queryBuilder->where('page.publish_at <= ?d', [new DateTimeImmutable()]); $this->_queryBuilder->where('(page.unpublish_at > ?d OR page.unpublish_at IS NULL)', [new DateTimeImmutable()]); } if ($this->_filters instanceof FilterCollection) { foreach ($this->_filters as $filter) { $filter->apply($this->_queryBuilder); } } } }
/** * Will not apply the filter if both values are null. * If the filter is applied and the content field is not set on the page, it will not show up in the results * * {@inheritDoc} */ protected function _applyFilter(QueryBuilderInterface $queryBuilder) { $joinedContent = false; foreach ($this->_value as $key => $value) { if (false === $joinedContent && null !== $value) { $queryBuilder->leftJoin($this->_getContentAlias(), $this->_getJoinStatement(), 'page_content')->where($this->_getContentAlias() . '.field_name = ?s', [$this->_field]); $joinedContent = true; } if (null !== $value) { if ($key === RangeFilterForm::MIN) { $queryBuilder->where($this->_castSQLValue($this->_getContentAlias() . '.value_string') . ' >= ' . $this->_castSQLValue('?s'), [$this->_value[RangeFilterForm::MIN]]); } elseif ($key === RangeFilterForm::MAX) { $queryBuilder->where($this->_castSQLValue($this->_getContentAlias() . '.value_string') . ' <= ' . $this->_castSQLValue('?s'), [$this->_value[RangeFilterForm::MAX]]); } else { throw new \LogicException('Key `' . $key . '` should not exist on value!'); } } } }