public function column($type)
{
$type = (int) $type;
$map = [Attribute::TYPE_DROPDOWN => 'option_value', Attribute::TYPE_CHECKBOX => 'number_value', Attribute::TYPE_NUMBER => 'number_value', Attribute::TYPE_TEXT => 'text_value', Attribute::TYPE_SHORT_TEXT => 'string_value', Attribute::TYPE_CHECKBOX_LIST => 'option_value'];
return array_key_exists($type, $map) ? $map[$type] : 'string_value';
}
/** * @param CHttpRequest $request * @return array */ 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; }