本文整理汇总了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;
}