コード例 #1
0
ファイル: FilterWidget.php プロジェクト: buildshop/bs-common
 /**
  * @return array of category manufacturers
  */
 public function getCategoryManufacturers()
 {
     $cr = new CDbCriteria();
     $cr->select = 't.manufacturer_id, t.id';
     $cr->group = 't.manufacturer_id';
     $cr->addCondition('t.manufacturer_id IS NOT NULL');
     //@todo: Fix manufacturer translation
     $mdl = $this->model;
     $dependency = new CDbCacheDependency('SELECT MAX(date_update) FROM {{shop_product}}');
     //$dependency = new CChainedCacheDependency();
     $manufacturers = ShopProduct::model()->cache($this->controller->cacheTime, $dependency)->active()->applyCategories($mdl, null)->with(array('manufacturer' => array('with' => array('productsCount' => array('scopes' => array('active', 'applyCategories' => array($mdl, null), 'applyAttributes' => array($this->getOwner()->activeAttributes), 'applyMinPrice' => array($this->convertCurrency(Yii::app()->request->getQuery('min_price'))), 'applyMaxPrice' => array($this->convertCurrency(Yii::app()->request->getQuery('max_price')))))))))->findAll($cr);
     $data = array('title' => Yii::t('default', 'Производитель'), 'selectMany' => true, 'filters' => array());
     if ($manufacturers) {
         foreach ($manufacturers as $m) {
             $m = $m->manufacturer;
             if ($m) {
                 $model = new ShopProduct(null);
                 $model->attachBehaviors($model->behaviors());
                 $model->active()->cache($this->controller->cacheTime, $dependency)->applyCategories($this->model)->applyMinPrice($this->convertCurrency(Yii::app()->request->getQuery('min_price')))->applyMaxPrice($this->convertCurrency(Yii::app()->request->getQuery('max_price')))->applyAttributes($this->getOwner()->activeAttributes)->applyManufacturers($m->id);
                 $data['filters'][] = array('title' => $m->name, 'count' => $model->count(), 'queryKey' => 'manufacturer', 'queryParam' => $m->id);
             }
         }
     }
     return $data;
 }