protected function getTerritoryContainment($level = 1, $locale = null)
{
static $tree;
if (null === $tree) {
$tree = [];
$data = $this->getGeneric('territoryContainment');
$build = function ($code, &$tree) use(&$build, $data) {
$tree[$code] = [];
if (isset($data[$code])) {
foreach ($data[$code] as $node) {
$build($node, $tree[$code]);
}
}
};
$build('001', $tree);
}
$getLevel = function ($node, $depth = 1) use(&$getLevel, $level) {
if ($level === $depth) {
return $node;
}
$result = [];
foreach ($node as $child) {
$result += $getLevel($child, $depth + 1);
}
return $result;
};
return array_intersect_key($this->getTerritories($locale), $getLevel($tree['001']));
}