} else { ?> <span class="glyphicon glyphicon-lock"></span> <?php } ?> </a> <?php } ?> <?php // Weburl ?> <a href="<?php echo Yii::getAlias('@baseUrl/') . MenuItem::findOne($item['item']->id)->getUrl(false, true); ?> " data-toggle="tooltip" target="_blank" title="<?php echo Yii::t('app', 'View'); ?> "> <span class="glyphicon glyphicon-globe"></span> </a> <?php // Manage page entity ?> <?php if ($item['item']->entity == MenuItem::ENTITY_PAGE) { ?> <a href="<?php
/** * Returns a recursive list of all parents of the item * * @param int|null The id of the item for which the parents have to be loaded. * When null is passed, the id of the loaded MenuItem instance is taken. */ public function getParents($id = null, $parents = []) { if ($id == null) { $item = $this; } else { $item = MenuItem::findOne($id); } if ($item->parent) { $parents[] = $item->parent; return $this->getParents($item->parent->id, $parents); } return $parents; }
/** * Updates the positions of the provided menu items * * @param array $items The menu items * @param infoweb\menu\models\MenuItem * @return boolean */ protected function updatePositions($items = [], $parent = null) { // Determine the parentId and level $parentId = $parent !== null ? $parent->id : 0; $level = $parent !== null ? $parent->level + 1 : 0; foreach ($items as $k => $item) { // Update the menu item $menuItem = MenuItem::findOne($item['id']); $menuItem->parent_id = $parentId; $menuItem->level = $level; $menuItem->position = $k + 1; if (!$menuItem->save()) { throw new \Exception("Error while saving menuItem #{$menuItem->id}"); } // Update the position of the item's children if (isset($item['children'])) { $this->updatePositions($item['children'], $menuItem); } } return true; }