示例#1
0
 protected function findModel($id)
 {
     if (($model = FilterVariant::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
文件: Filter.php 项目: oakcms/oakcms
 public function beforeDelete()
 {
     foreach ($this->hasMany(FieldRelationValue::className(), ['filter_id' => 'id'])->all() as $frv) {
         $frv->delete();
     }
     foreach ($this->hasMany(FilterVariant::className(), ['filter_id' => 'id'])->all() as $fv) {
         $fv->delete();
     }
     return true;
 }
示例#3
0
 public function search($params)
 {
     $query = FilterVariant::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'filter_id' => $this->filter_id]);
     $query->andFilterWhere(['like', 'value', $this->value]);
     return $dataProvider;
 }
示例#4
0
 public function filtered($filterIds = false, $mode = 0)
 {
     if (!$filterIds) {
         $filterIds = Yii::$app->request->get($this->fieldName);
     }
     if (empty($filterIds)) {
         return $this->owner;
     }
     $condition = ['OR'];
     $variantCount = 0;
     $filterCount = count($filterIds);
     foreach ($filterIds as $filterId => $value) {
         $filter = Filter::findOne($filterId);
         if ($filter->type == 'range' && is_string($value)) {
             $value = explode(';', $value);
             if ($value[0] != $value[1]) {
                 $variants = FilterVariant::find()->where('filter_id = :filterId AND (numeric_value >= :min AND numeric_value <= :max)', [':filterId' => $filterId, ':min' => $value[0], ':max' => $value[1]])->select('id')->all();
             } else {
                 $variants = FilterVariant::find()->where('filter_id = :filterId AND numeric_value = :value', [':filterId' => $filterId, ':value' => $value[0]])->select('id')->all();
             }
             $variantIds = ArrayHelper::map($variants, 'id', 'id');
         } else {
             $variantIds = $value;
         }
         $condition[] = ['filter_id' => $filterId, 'variant_id' => $variantIds];
         if ($mode == 1) {
             $variantCount += count($variantIds);
         } else {
             $variantCount++;
         }
     }
     $filtered = FilterValue::find()->select('item_id')->groupBy('item_id')->andHaving("COUNT(DISTINCT `filter_id`) = {$variantCount}")->andFilterWhere($condition);
     if ($filtered->count() > 0) {
         $this->owner->andWhere(['id' => $filtered]);
     } else {
         $this->owner->andWhere(['id' => 0]);
     }
     return $this->owner;
 }
示例#5
0
 public static function saveEdit($id, $name, $value)
 {
     $setting = FilterVariant::findOne($id);
     $setting->{$name} = $value;
     $setting->save();
 }
示例#6
0
 public function getVariant()
 {
     return $this->hasOne(FilterVariant::className(), ['id' => 'variant_id']);
 }
示例#7
0
 public function actionEditVariant()
 {
     $name = yii::$app->request->post('name');
     $value = yii::$app->request->post('value');
     $pk = unserialize(base64_decode(yii::$app->request->post('pk')));
     FilterVariant::saveEdit($pk, $name, $value);
 }