当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getSortAttributes方法代码示例

本文整理汇总了PHP中common\models\Product::getSortAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getSortAttributes方法的具体用法?PHP Product::getSortAttributes怎么用?PHP Product::getSortAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Product的用法示例。


在下文中一共展示了Product::getSortAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: watchedSearch

 public function watchedSearch($params)
 {
     $query = Yii::$app->user->identity->getRecentlyProducts()->select(['{{product}}.*', 'IF(round(sum(product_review.rating) / count(product.reviews_count)) IS NULL, 0, rating) as rating'])->joinWith(['productReviews', 'recentProducts'])->groupBy('{{product}}.id');
     $sort = new Sort(['defaultOrder' => ['recent' => SORT_ASC], 'attributes' => ArrayHelper::merge(['recent' => ['asc' => ['recent_product.created_at' => SORT_DESC], 'label' => 'Recently', 'defaultOrder' => SORT_ASC], 'old' => ['asc' => ['recent_product.created_at' => SORT_ASC], 'label' => 'Old', 'defaultOrder' => SORT_ASC]], Product::getSortAttributes())]);
     $viewSort = new Sort(['sortParam' => 'view', 'attributes' => [Product::VIEW_SORT_LIST, Product::VIEW_SORT_BLOCK]]);
     $this->load($params);
     $sortParam = Yii::$app->request->getQueryParam('view');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => $sort, 'pagination' => ['pageSizeParam' => false, 'pageSize' => $sortParam === Product::VIEW_SORT_BLOCK ? self::FAVORITES_PAGINATION_SIZE_BLOCK : self::FAVORITES_PAGINATION_SIZE_LIST]]);
     Yii::$app->controller->view->params['viewSort'] = $viewSort;
     Yii::$app->controller->view->params['sort'] = $sort;
     Yii::$app->controller->view->params['searchModel'] = $this;
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'active' => $this->active, 'reviews_count' => $this->reviews_count, 'brand_id' => $this->brand_id, 'comment_count' => $this->comment_count, 'category_id' => $this->category_id, 'UI' => $this->ui]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'full_description', $this->full_description])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'ui', $this->ui]);
     return $dataProvider;
 }
开发者ID:ninetor,项目名称:yii-classifield,代码行数:20,代码来源:ProductSearch.php


注:本文中的common\models\Product::getSortAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。