/** * @param $categoryId * @return FilterSets[] */ public static function getForCategoryId($categoryId) { Yii::beginProfile('FilterSets.GetForCategory ' . $categoryId); $category = Category::findById($categoryId); if ($category === null) { return []; } $categoryIds = $category->getParentIds(); $filter_sets = FilterSets::find()->where(['in', 'category_id', $categoryIds])->andWhere(['delegate_to_children' => 1])->orWhere(['category_id' => $category->id])->orderBy(['sort_order' => SORT_ASC])->all(); Yii::endProfile('FilterSets.GetForCategory ' . $categoryId); return $filter_sets; }
/** * @param $categoryId * @return FilterSets[] */ public static function getForCategoryId($categoryId) { Yii::beginProfile('FilterSets.GetForCategory ' . $categoryId); $category = Category::findById($categoryId); if ($category === null) { return []; } $categoryIds = $category->getParentIds(); $filter_sets = Yii::$app->db->cache(function ($db) use($categoryIds, $category) { return FilterSets::find()->where(['in', 'category_id', $categoryIds])->andWhere(['delegate_to_children' => 1])->orWhere(['category_id' => $category->id])->orderBy(['sort_order' => SORT_ASC])->all(); }, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(static::className())]])); Yii::endProfile('FilterSets.GetForCategory ' . $categoryId); return $filter_sets; }
private function loadModel($id) { $model = FilterSets::find()->where(['id' => $id])->one(); if ($model === null) { throw new NotFoundHttpException(); } return $model; }