You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by Error202
|
|
|
|
* Date: 11.07.2018
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace backend\components\menu\widgets;
|
|
|
|
|
|
|
|
use core\entities\menu\Menu;
|
|
|
|
use core\entities\menu\MenuItem;
|
|
|
|
use yii\base\Widget;
|
|
|
|
|
|
|
|
class MenuEditorWidget extends Widget
|
|
|
|
{
|
|
|
|
public $menu_id;
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$menu = Menu::findOne($this->menu_id);
|
|
|
|
$items = $menu->items;
|
|
|
|
|
|
|
|
return $this->render('menu', [
|
|
|
|
'items' => $this->getMenu($items),
|
|
|
|
'menu' => $menu,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $items MenuItem[]
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getMenu($items, $paren_id = null)
|
|
|
|
{
|
|
|
|
$array = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if ($item->parent_id != $paren_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$array[$item->id]['item'] = $item;
|
|
|
|
if ($children = $item->children) {
|
|
|
|
$array[$item->id]['children'] = $this->getMenu($children, $item->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|