public function menuItemsReset() { /** @var Page|Category $model */ $model = $this->owner; if ($model->menuItemContents) { foreach ($model->menuItemContents as $menuItemContent) { /** @var MenuItemRecord $menuItem */ $menuItem = MenuItemRecord::findOne($menuItemContent->menu_item_id); $menuItem->layout_id = null; $menuItem->link_url = '#'; $menuItem->content_type = MenuItemRecord::CONTENT_LINK; $menuItem->save(false); } } }
public function getTree() { /** @var MenuItemRecord $menuItem */ $menuItem = MenuItemRecord::findOne($this->parent_id); if ($menuItem) { ++$this->_iterator; $linkRoute = ['menu-item/index']; if ($menuItem->parent_id) { $linkRoute['pid'] = $menuItem->parent_id; } $linkTitle = $menuItem->parent_id ? $menuItem->title . ' - ' . Yii::t('back', 'level') : Yii::t('back', 'Top level'); $this->_tree[] = Html::a($linkTitle, $linkRoute, ['title' => Yii::t('back', $linkTitle)]); if ($menuItem->parent_id) { $this->parent_id = $menuItem->parent_id; $this->getTree(); } } }
/** * Lists Menu items in one level. * * @param null $pid parent item ID * @return string * @throws \Exception */ public function actionIndex($pid = null) { $model = new MenuItemForm($this->_menu->id, $pid); $model->scenario = 'index'; if ($model->load(Yii::$app->request->post())) { foreach ($item_order = explode(',', $model->item_order) as $key => $value) { /** @var $item MenuItemRecord */ $item = MenuItemRecord::findOne($value); $item->item_order = $key + 1; $item->update(false, ['item_order']); } $session = Yii::$app->session; $session->setFlash('info', Yii::t('back', 'Menu items order successfully saved!')); } $menu_id = $this->_menu->id; $web_id = $this->_menu->web_id; return $this->render('index', compact('model', 'menu_id', 'web_id')); }
/** * @return \yii\db\ActiveQuery */ public function getChildrenItems() { return $this->hasMany(MenuItemRecord::className(), ['parent_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getMenuItems() { return $this->hasMany(MenuItemRecord::className(), ['menu_id' => 'id']); }
/** * Creates array for breadcrumbs widget * * @param $id * @param array $items * @param bool|true $urls * * @return array */ public static function getBreadCrumbs($id, $items = [], $urls = false) { /** @var MenuItemRecord $model */ $model = MenuItemRecord::findOne($id); if ($model) { $items[] = $urls === true ? ['label' => $model->title, 'url' => $model->content_type == MenuItemRecord::CONTENT_LINK ? $model->link_url != '#!' ?: null : ['page/menu', 'web' => \Yii::$app->request->get('web'), 'language' => \Yii::$app->request->get('language'), 'name' => Inflector::slug(strip_tags($model->title)), 'id' => $model->id]] : $model->title; if ($model->parent_id) { $urls = true; return self::getBreadCrumbs($model->parent_id, $items, $urls); } } return array_reverse($items); }
/** * Returns menu id of given page id * @param $pageId * @return bool|integer */ public static function getMenuItemIdFromPageId($pageId) { $menuId = MenuItemRecord::find()->select('menu_item.id')->joinWith(['menu.web', 'menuItemContent'])->where(['menu_item.content_type' => MenuItemRecord::CONTENT_PAGE, 'web.weburl' => \Yii::$app->request->get('web', \Yii::$app->params['defaultWeb']), 'menu_item_content.content_id' => $pageId])->scalar(); return $menuId; }
/** * Returns parent menu item * @return MenuItemRecord */ public function getParentItem() { return MenuItemRecord::findOne($this->parent_id); }