public function search(ActiveDataProvider $activeDataProvider, $tableName = 'cms_content_element')
{
$classSearch = $this->propertyElementClassName;
/**
* @var $activeQuery ActiveQuery
*/
$activeQuery = $activeDataProvider->query;
$elementIdsGlobal = [];
$applyFilters = false;
foreach ($this->toArray() as $propertyCode => $value) {
//TODO: add to validator related properties
if ($propertyCode == 'properties') {
continue;
}
if ($property = $this->getProperty($propertyCode)) {
if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_NUMBER) {
$elementIds = [];
$query = $classSearch::find()->select(['element_id'])->where(["property_id" => $property->id])->indexBy('element_id');
if ($fromValue = $this->{$this->getAttributeNameRangeFrom($propertyCode)}) {
$applyFilters = true;
$query->andWhere(['>=', 'value_num', (double) $fromValue]);
}
if ($toValue = $this->{$this->getAttributeNameRangeTo($propertyCode)}) {
$applyFilters = true;
$query->andWhere(['<=', 'value_num', (double) $toValue]);
}
if (!$fromValue && !$toValue) {
continue;
}
$elementIds = $query->all();
} else {
if (!$value) {
continue;
}
$applyFilters = true;
if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_STRING) {
$elementIds = $classSearch::find()->select(['element_id'])->where(["property_id" => $property->id])->andWhere(['like', 'value', $value])->indexBy('element_id')->all();
} else {
$elementIds = $classSearch::find()->select(['element_id'])->where(["value" => $value, "property_id" => $property->id])->indexBy('element_id')->all();
}
}
$elementIds = array_keys($elementIds);
\Yii::beginProfile('array_intersect');
if (!$elementIds) {
$elementIdsGlobal = [];
}
if ($elementIdsGlobal) {
$elementIdsGlobal = array_intersect($elementIds, $elementIdsGlobal);
} else {
$elementIdsGlobal = $elementIds;
}
\Yii::endProfile('array_intersect');
}
}
if ($applyFilters) {
$activeQuery->andWhere([$tableName . '.id' => $elementIdsGlobal]);
}
}