コード例 #1
0
 public function actionDelete()
 {
     $itemId = yii::$app->request->post('item_id');
     $variantId = yii::$app->request->post('variant_id');
     $filterId = yii::$app->request->post('filter_id');
     if ($value = FilterValue::find()->where(['item_id' => $itemId, 'variant_id' => $variantId])->one()) {
         $value->delete();
     } else {
         FilterValue::deleteAll(['item_id' => $itemId, 'filter_id' => $filterId]);
     }
     return json_encode(['result' => 'success']);
 }
コード例 #2
0
ファイル: Filtered.php プロジェクト: oakcms/oakcms
 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;
 }
コード例 #3
0
ファイル: AttachFilterValues.php プロジェクト: oakcms/oakcms
 public function deleteValues()
 {
     foreach (FilterValue::find()->where(['item_id' => $this->owner->id])->all() as $value) {
         $value->delete();
     }
     return true;
 }
コード例 #4
0
ファイル: Filter.php プロジェクト: oakcms/oakcms
 public function getVariantsByFindModel($findModel)
 {
     $variantIds = FilterValue::find()->select('variant_id')->distinct()->where(['item_id' => $findModel->select('id')]);
     return $this->hasMany(FilterVariant::className(), ['filter_id' => 'id'])->where(['id' => $variantIds]);
 }