public function getTypeAttributesForSearchFromQuery(CHttpRequest $request)
{
$attributes = Yii::app()->getCache()->get('Store::filter::attributes');
if (false === $attributes) {
$attributes = [];
$models = Attribute::model()->findAll(['select' => ['name', 'id', 'type']]);
foreach ($models as $model) {
$attributes[$model->name] = $model;
}
Yii::app()->getCache()->set('Store::filter::attributes', $attributes);
}
$result = [];
$attributeValue = new AttributeValue();
foreach ($attributes as $name => $attribute) {
$searchParams = $request->getQuery($attribute->name);
//пропускаем пустые значения
if (null === $searchParams) {
continue;
}
if (is_array($searchParams)) {
if (isset($searchParams['from']) && null == $searchParams['from']) {
unset($searchParams['from']);
}
if (isset($searchParams['to']) && null == $searchParams['to']) {
unset($searchParams['to']);
}
if (empty($searchParams)) {
continue;
}
}
$result[$attribute->name] = ['value' => $searchParams, 'attribute_id' => (int) $attribute->id, 'column' => $attributeValue->column($attribute->type)];
}
return $result;
}