/** * @inheritdoc */ public function getValuesTree() { return TreeFacetHelper::buildValuesTree($this->getValues()); }
/** * @inheritdoc */ public function getValuesTree() { $values = $this->getValues(); if ($values) { /** @var Category[]|NestedSetsBehavior[] $categories */ $categories = array_map(function (EntityFacetValueInterface $value) { return $value->getEntity(); }, $values); /** @var \im\catalog\models\CategoryQuery $query */ $query = null; /** @var Category|NestedSetsBehavior $root */ $root = ($context = $this->getContext()) && $context instanceof Category ? $context : null; foreach ($categories as $category) { $parentsQuery = $category->parents(); if ($root) { $parentsQuery->andWhere(['and', ['>', $category->leftAttribute, $root->getAttribute($root->leftAttribute)], ['<', $category->rightAttribute, $root->getAttribute($root->rightAttribute)]]); } $query = $query ? $query->union($parentsQuery) : $parentsQuery; } $parents = $query->all(); $parentsValues = []; $attribute = $this->attribute_name ?: 'id'; foreach ($parents as $parent) { $parentsValues[] = $this->getValueInstance(['entity' => $parent, 'key' => $parent->{$attribute}, 'facet' => $this]); } $parentsValues = $this->applyContext($parentsValues); $values = array_merge($values, $parentsValues); } return $values ? TreeFacetHelper::buildValuesTree($values) : []; }