/** * Конфигурирование объекта запроса поиска по элементам. * * @param \yii\db\ActiveQuery $activeQuery * @param null $modelClassName * @return $this */ public function buildElementsQuery(\yii\db\ActiveQuery $activeQuery) { $where = []; //Нужно учитывать связанные дополнительные данные if ($this->enabledElementProperties == Cms::BOOL_Y) { $activeQuery->joinWith('cmsContentElementProperties'); //Нужно учитывать настройки связанные дополнительные данных if ($this->enabledElementPropertiesSearchable == Cms::BOOL_Y) { $activeQuery->joinWith('cmsContentElementProperties.property'); $where[] = ['and', ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false], [CmsContentProperty::tableName() . ".searchable" => Cms::BOOL_Y]]; } else { $where[] = ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false]; } } //Поиск по основному набору полей if ($this->searchElementFields) { foreach ($this->searchElementFields as $fieldName) { $where[] = ['like', CmsContentElement::tableName() . "." . $fieldName, '%' . $this->searchQuery . '%', false]; } } if ($where) { $where = array_merge(['or'], $where); $activeQuery->andWhere($where); } //Отфильтровать только конкретный тип if ($this->searchElementContentIds) { $activeQuery->andWhere([CmsContentElement::tableName() . ".content_id" => (array) $this->searchElementContentIds]); } return $this; }