示例#1
0
 public function search($params)
 {
     // USER ID
     $userId = Yii::$app->user->id;
     // FAVORITES ANNOUNCEMENTS IDS
     $rows = FavoritesModel::find()->select(['announcement_id'])->andFilterWhere(['user_id' => $userId])->asArray()->all();
     if (!count($rows)) {
         return;
     }
     $favoritesIds = [];
     foreach ($rows as $row) {
         $favoritesIds[] = $row['announcement_id'];
     }
     // BASE QUERY
     $query = AutoBaseQuery::queryLongBlockFull();
     $query->andFilterWhere(['in', 'announcement.id', $favoritesIds]);
     // SORT
     if (isset($params['sort'])) {
         switch ($params['sort']) {
             case 'created_asc':
                 $query->orderBy("announcement.id DESC");
                 break;
             case 'price_cheap':
                 $query->orderBy("announcement.price ASC");
                 break;
             case 'price_expensive':
                 $query->orderBy("announcement.price DESC");
                 break;
             default:
                 $query->orderBy("announcement.id DESC");
                 break;
         }
     } else {
         $query->orderBy("announcement.id DESC");
     }
     // PER PAGE
     $perPage = Yii::$app->params['catalogSettings']['defaultPageSize'];
     if (isset($params['pp']) && in_array($params['pp'], Yii::$app->params['catalogSettings']['pageSize'])) {
         $perPage = $params['pp'];
     }
     // DATA PROVIDER
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $perPage, 'pageSizeParam' => 'pp']]);
     return $dataProvider;
 }
示例#2
0
 public function search($params)
 {
     // USER ID
     $userId = Yii::$app->user->id;
     // BASE QUERY
     $query = AutoBaseQuery::queryLongBlockFull();
     $query->andFilterWhere(['announcement.user_id' => $userId]);
     $query->andWhere(['in', 'announcement.status', [Announcement::STATUS_ENABLED, Announcement::STATUS_SALES]]);
     // SORT
     if (isset($params['sort'])) {
         switch ($params['sort']) {
             case 'created_asc':
                 $query->orderBy("announcement.id DESC");
                 break;
             case 'price_cheap':
                 $query->orderBy("announcement.price ASC");
                 break;
             case 'price_expensive':
                 $query->orderBy("announcement.price DESC");
                 break;
             default:
                 $query->orderBy("announcement.id DESC");
                 break;
         }
     } else {
         $query->orderBy("announcement.id DESC");
     }
     // PER PAGE
     $perPage = Yii::$app->params['catalogSettings']['defaultPageSize'];
     if (isset($params['pp']) && in_array($params['pp'], Yii::$app->params['catalogSettings']['pageSize'])) {
         $perPage = $params['pp'];
     }
     // DATA PROVIDER
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $perPage, 'pageSizeParam' => 'pp']]);
     return $dataProvider;
 }
示例#3
0
 public function addExchangeAutoToProposition($propositions)
 {
     if (!count($propositions)) {
         return;
     }
     // EXCHANGE IDS
     $exchangeIds = [];
     foreach ($propositions as $row) {
         if ($row['announcement_exchange_id']) {
             $exchangeIds[] = $row['announcement_exchange_id'];
         }
     }
     // EXCHANGE AUTOS
     $query = AutoBaseQuery::queryLongBlockBase();
     $query->andFilterWhere(['announcement.status' => Announcement::STATUS_ENABLED]);
     $query->andFilterWhere(['in', 'announcement.id', $exchangeIds]);
     $rows = $query->orderBy('announcement.id ASC')->all();
     $exchangeAutos = [];
     foreach ($rows as $row) {
         $exchangeAutos[$row['id']] = $row;
     }
     // EXCHANGE AUTOS TO PROPOSITIONS
     foreach ($propositions as $key => $row) {
         if ($row['announcement_exchange_id']) {
             $propositions[$key]['exchange_auto'] = $exchangeAutos[$row['announcement_exchange_id']];
         }
     }
     return $propositions;
 }