AttributeFilter::getTypeAttributesForSearchFromQuery PHP Метод

getTypeAttributesForSearchFromQuery() публичный Метод

public getTypeAttributesForSearchFromQuery ( CHttpRequest $request ) : array
$request CHttpRequest
Результат 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;
    }

Usage Example

Пример #1
0
 /**
  * @param $path
  * @throws CHttpException
  */
 public function actionView($path)
 {
     $category = StoreCategory::model()->published()->findByPath($path);
     if (null === $category) {
         throw new CHttpException(404);
     }
     $data = Yii::app()->getRequest()->getQueryString() ? $this->productRepository->getByFilter($this->attributeFilter->getMainAttributesForSearchFromQuery(Yii::app()->getRequest(), [AttributeFilter::MAIN_SEARCH_PARAM_CATEGORY => [$category->id]]), $this->attributeFilter->getTypeAttributesForSearchFromQuery(Yii::app()->getRequest())) : $this->productRepository->getListForCategory($category);
     $this->render('view', ['dataProvider' => $data, 'category' => $category]);
 }
All Usage Examples Of AttributeFilter::getTypeAttributesForSearchFromQuery