/** * @param array $tree * @param array $options * @return array */ public static function menu(array $tree = [], array $options = []) { $array = []; $attributes = !empty($options['attributes']) ? $options['attributes'] : ['icon' => 'fa fa-circle-o']; $lkey = !empty($options['lkey']) ? $options['lkey'] : 'lft'; $levelkey = !empty($options['level']) ? $options['level'] : 'lvl'; $label = !empty($options['label']) ? $options['label'] : 'title'; $level = 0; $i = 0; $_path = $i; $delimiter = '.'; foreach ($tree as $child) { $menu = ['label' => $child->{$label}, 'url' => [$child->url()], 'level' => $child->{$levelkey}]; if ($child->{$levelkey} > $level) { $i = 0; $_path = $_path . $delimiter . 'items'; } if ($child->{$levelkey} > 0) { $path = $_path . $delimiter . $i; } else { $path = $i; } ArrayHelper::setValue($array, $path, $menu, $delimiter); $level = $child->{$levelkey}; $i++; } return $array; }