コード例 #1
0
ファイル: SiteController.php プロジェクト: sapgv/distributive
 public function actionIndex()
 {
     $countOrders = Orders::find()->count();
     $countCatalogs = Catalogs::find()->where(['not', ['name' => 'ROOT']])->count();
     $countProducts = Products::find()->count();
     return $this->render('index', ['countOrders' => $countOrders, 'countCatalogs' => $countCatalogs, 'countProducts' => $countProducts]);
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param Catalogs $catalog
  *
  * @return ActiveDataProvider
  */
 public function search($params, $catalog)
 {
     $viewList = CookieController::getViewList();
     $productsID = [];
     $productsID = array_merge($productsID, $catalog->getProducts()->select('product_id')->asArray()->all());
     foreach ($catalog->children()->all() as $child) {
         $productsID = array_merge($productsID, $child->getProducts()->select('product_id')->asArray()->all());
     }
     $query = Products::find()->where(['product_id' => $productsID]);
     $price_min = $query->min('price');
     $price_max = $query->max('price');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $viewList == 'panel' ? 6 : 5]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name]);
     // print_r($this->price_min);
     $query->andFilterWhere(['>=', 'price', $this->price_min]);
     $query->andFilterWhere(['<=', 'price', $this->price_max]);
     //print_r($params['ProductsCatalogSearch']);
     if ($params['ProductsCatalogSearch']['count'] == self::ALL) {
         // echo "всееее";
         // $query->andWhere('a > :a', ['a' => 'a'])
     } elseif ($params['ProductsCatalogSearch']['count'] == self::AVAILABLE) {
         // echo "в наличиbbи";
         $query->andWhere('count > 0');
     } elseif ($params['ProductsCatalogSearch']['count'] == self::NOT_AVAILABLE) {
         // echo "нетууу";
         $query->andWhere('count <= 0');
     }
     return ['dataProvider' => $dataProvider, 'price_min' => $price_min, 'price_max' => $price_max];
 }
コード例 #3
0
ファイル: ProductsSearch.php プロジェクト: sapgv/distributive
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find()->select('products.product_id as product_id, products.name as name, catalogs.name as name_catalog')->leftJoin('catalogs as catalogs', 'Products.id_catalog = catalogs.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['product_id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'catalogs.name', $this->name_catalog]);
     return $dataProvider;
 }
コード例 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $products
  *
  * @return ActiveDataProvider
  */
 public function search($products)
 {
     $productsID = [];
     foreach ($products as $product) {
         $productsID[] = $product->product_id;
     }
     $query = Products::find()->where(['product_id' => $productsID]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     return $dataProvider;
 }
コード例 #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $viewList = CookieController::getViewList();
     $query = Products::find()->select(['product_id', 'name', 'price', 'gallery_id', "IF (LENGTH(precontent) > 200,\n                CONCAT(LEFT(TRIM(TRAILING '.' FROM precontent),150),'...'),\n                LEFT(TRIM(TRAILING '.' FROM precontent),150))\n             as precontent"])->where(['popular' => true]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $viewList == 'panel' ? 6 : 5]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         return $dataProvider;
     }
     if (isset($params['ProductsPopularSearch']['count'])) {
         if ($params['ProductsPopularSearch']['count'] == Products::AVAILABLE) {
             // echo "в наличии";
             $query->andWhere('count > 0');
         } elseif ($params['ProductsPopularSearch']['count'] == Products::NOT_AVAILABLE) {
             // echo "нетууу";
             $query->andWhere('count <= 0');
         }
     }
     return $dataProvider;
 }