public function run() { if (empty($this->template)) { return; } $url = trim(Yii::app()->request->url, '/'); $items = MenuItem::model()->onSite()->byParent(0)->byMenuId($this->menuId)->orderDefault()->findAll(); $itemsArr = array(); foreach ($items as $item) { // Убираем язык из урла $domains = explode('/', ltrim($url, '/')); if (in_array($domains[0], array_keys(Yii::app()->params['languages']))) { array_shift($domains); $url = implode('/', $domains); } $select = strpos($url, trim($item->link, '/')) === 0 ? true : false; $blank = 0; if (strpos($item->link, 'http://') === 0 || strpos($item->link, 'https://') === 0) { $link = $item->link; $blank = 1; } else { $link = isset(Yii::app()->params['routes'][$item->link]) ? array('/' . Yii::app()->params['routes'][$item->link]) : '/' . $item->link; // Ссылка без языка, будет вести на дефолтную страницу $link = CHtml::normalizeUrl($link); } $iconUrl = $item->getIconUrl(); $itemsArr[] = array('name' => $item->name, 'link' => $link, 'select' => $select, 'iconUrl' => $iconUrl, 'blank' => $blank, 'enabled' => $item->active); } $this->beforeRender($itemsArr); $this->render($this->template, array('items' => $itemsArr)); }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id = null, $path = null) { //if path is given, find the content_id from the menu item if ($path) { $Content = Content::model()->findByAttributes(array('path' => $path)); } else { $Content = $this->loadModel($id); } $Content = $this->loadModel($id); $MI = MenuItem::model()->findByAttributes(array('content_id' => $Content->id)); if (!Yii::app()->user->checkAccess('Update Content')) { $today = new DateTime(); $publish_on = new DateTime($Content->publish_on); $unpublish_on = new DateTime($Content->unpublish_on); if (!$Content->published || $publish_on > $today || $unpublish_on < $today) { throw new CHttpException(403, Yii::t('yii', 'You are not authorized to perform this action.')); } } //$this->layout = '//layouts/column1'; $view = 'view'; if ($this->getLayoutFile('//layouts/content_types/' . $Content->type)) { $this->layout = '//layouts/content_types/' . $Content->type; } if ($this->getViewFile($Content->type)) { $view = $Content->type; } $this->meta_keywords = CHtml::value($Content, 'meta_keywords'); $this->meta_description = CHtml::value($Content, 'meta_description'); $this->meta_author = CHtml::value($Content, 'UserCreated.full_name'); //Used by the admin bar $this->Content = $Content; $this->render($view, array('Content' => $Content, 'MenuItem' => $MI)); }
/** * Возвращает модель по указанному идентификатору * Если модель не будет найдена - возникнет HTTP-исключение. * * @param integer идентификатор нужной модели * * @return void * * @throws CHttpException If MenuItem record not found */ public function loadModel($id) { if (($model = MenuItem::model()->findByPk($id)) === null) { throw new CHttpException(404, Yii::t('MenuModule.menu', 'Page was not found!')); } return $model; }
public function loadModel($id) { if (($model = MenuItem::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
protected function deleteMenu($menuId) { $menuItems = MenuItem::model()->findAllByAttributes(array('menuId' => $menuId)); foreach ($menuItems as $item) { $item->delete(); } Menu::model()->deleteByPk($menuId); }
public static function getMenuItems($parent_id, $menu_id) { $menu_items = MenuItem::model()->findAll(array('condition' => 'parent=:pid AND menu_id=:mid', 'params' => array(':pid' => $parent_id, ':mid' => $menu_id), 'order' => ' t.order ASC ')); $result = array(); foreach ($menu_items as $menu_item) { $result[] = array('name' => $menu_item->name, 'link' => self::buildLink($menu_item), 'id' => $menu_item->menu_item_id); } return $result; }
protected function getSubItems($item_id) { $dependencia = new CDbCacheDependency("SELECT GREATEST(MAX(creado), MAX(modificado)) FROM menuItem WHERE estado = 1"); $c = new CDbCriteria(); $c->addCondition('t.estado <> 0'); $c->order = 't.orden ASC'; $menu_items = MenuItem::model()->cache(21600, $dependencia)->findAllByAttributes(array('item_id' => $this->id), $c); return $menu_items ? $menu_items : false; }
public function up() { Yii::app()->getModule('menu'); $Menu = Menu::model()->findByAttributes(['code' => 'top-menu-cabinet']); $menuItems = $Menu->menuItems(['condition' => 'href=:href', 'params' => ['href' => '/cabinet/deal']]); if (!is_null($menuItems) && count($menuItems)) { $menuItem = $menuItems[0]; MenuItem::model()->deleteByPk($menuItem->id); } }
public function parseUrl($request) { $path = '/' . Yii::app()->request->pathInfo; $MI = MenuItem::model()->findByAttributes(array('path' => $path)); if ($MI && $MI->content_id) { $route = 'content/view/id/' . $MI->content_id; } else { $route = parent::parseUrl($request); } return lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $route)))); }
public function safeDown() { if (Yii::app()->hasModule('menu')) { Yii::import('application.modules.menu.models.*'); Yii::import('application.modules.menu.MenuModule'); $item = MenuItem::model()->find('href = :href', [':href' => '/store/product/index']); if ($item !== null) { $item->delete(); } } }
public function safeUp() { if (Yii::app()->hasModule('menu')) { Yii::import('application.modules.menu.models.*'); Yii::import('application.modules.menu.MenuModule'); $item = MenuItem::model()->find('href = :href', [':href' => '/store/catalog/index']); if (null !== $item) { $item->href = '/store/product/index'; $item->save(); } } }
public static function getMenuItemFromMenu($menu_id, $render = true) { $menus = MenuItem::model()->findAll('menu_id = :id', array(':id' => $menu_id)); $data = array(0 => t('cms', "None")); if ($menus && count($menus) > 0) { $data = CMap::mergeArray($data, CHtml::listData($menus, 'menu_item_id', 'name')); } if ($render) { foreach ($data as $value => $name) { echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true); } } else { return $data; } }
protected function beforeDelete() { try { foreach ($this->menuItems as $menuItem) { $mi = MenuItem::model()->findByPk($menuItem->id); $mi->delete(); } foreach ($this->micrositios as $micrositio) { $m = $micrositio->findByPk($micrositio->id); $m->menu_id = NULL; $m->save(); } return parent::beforeDelete(); } catch (Exception $e) { return false; } }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id = null, $path = null) { if ($path) { $MI = MenuItem::model()->findByAttributes(array('path' => $path)); $id = $MI ? $MI->content_id : null; } $Content = $this->loadModel($id); $this->layout = '//layouts/column1'; $view = 'view'; if ($this->getLayoutFile('//layouts/content_types/' . $Content->type)) { $this->layout = '//layouts/content_types/' . $Content->type; } if ($this->getViewFile('content_types/' . $Content->type)) { $view = 'content_types/' . $Content->type; } $this->render($view, array('Content' => $Content)); }
public function actionSave() { foreach ($_POST['list'] as $item) { print_r($_POST); if ($item['item_id'] == 'root') { continue; } if ($item['parent_id'] == "root") { $item['parent_id'] = "0"; } $menuItem = MenuItem::model()->findByPk($item['item_id']); $menuItem->parent = $item['parent_id']; $menuItem->depth = $item['depth']; $menuItem->lft = $item['left']; $menuItem->rgt = $item['right']; $menuItem->save(); } }
/** * Menu initialization */ public function init() { $this->id = $this->name; $this->activateParents = true; if ($menu = Menu::model()->findByAttributes(array('name' => $this->name))) { if ($menu->firstitem_class) { $this->firstItemCssClass = $menu->firstitem_class; } if ($menu->lastitem_class) { $this->lastItemCssClass = $menu->lastitem_class; } if ($menu->items_template) { $this->itemTemplate = $menu->items_template; } if ($menu->activeitem_class) { $this->activeCssClass = $menu->activeitem_class; } $criteria = new CDbCriteria(); $criteria->compare('t.menu_id', $menu->id); $criteria->compare('t.parent_id', 0); $criteria->order = 't.sort_order'; $criteria->with = 'childs'; if ($this->limit) { $criteria->limit = $this->limit; } if ($this->offset) { $criteria->offset = $this->offset; } if ($items = MenuItem::model()->findAll($criteria)) { $this->items = $this->parseMenuItems($items); } } else { $this->items = array(array('label' => 'Меню с именем ' . $this->name . ' не существует!', 'url' => '#', 'active' => false)); } $this->items = $this->normalizeItems($this->items, Yii::app()->request->url, $hasActiveChild); }
protected function renderContent() { $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel('Menu', $id); //Guid of the Object $guid = $model->guid; //List of language that should exclude not to translate $lang_exclude = array(); //List of translated versions $versions = array(); $list_items = array(); //Look for the Term Items belong to this Taxonomy $list_menu_items = MenuItem::model()->findAll(array('select' => '*', 'condition' => 'menu_id=:id', 'order' => 't.parent ASC, t.order ASC', 'params' => array(':id' => $id))); if ($list_menu_items) { foreach ($list_menu_items as $menu_item) { $temp_item['id'] = $menu_item->menu_item_id; $temp_item['name'] = CHtml::encode($menu_item->name); $temp_item['parent'] = $menu_item->parent; //Add Item here to make sure Chrome not change the order of Json Object $list_items['item_' . $menu_item->menu_item_id] = $temp_item; } } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'menu-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['Menu'])) { $model->attributes = $_POST['Menu']; if ($model->save()) { user()->setFlash('success', t('cms', 'Update Menu Successfully!')); } } $this->render('cmswidgets.views.menu.menu_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions, 'list_items' => $list_items)); }
public function getItems() { $tree = array(); if ($this->enabled) { $ref = array(); $items = MenuItem::model()->findAllByAttributes(array('menu_id' => $this->id, 'enabled' => 1), array('order' => 'lft')); foreach ($items as $item) { $menuItem = array(); $menuItem['label'] = $item->name; $menuItem['url'] = $item->link; $menuItem['role'] = $item->role; $menuItem['target'] = $item->target; $menuItem['description'] = $item->description; if (!$item->parent_id) { $tree[$item->id] = $menuItem; $ref[$item->id] =& $tree[$item->id]; } else { $ref[$item->parent_id]['items'][$item->id] = $menuItem; $ref[$item->id] =& $ref[$item->parent_id]['items'][$item->id]; } } } return $tree; }
<?php echo CHtml::checkBox('MenuItem[target]', $model->target == '_blank', array('value' => '_blank')); ?> <?php echo $form->error($model, 'target'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'parent_id'); ?> <?php //show all menu items but current one $allModels = MenuItem::model()->findAll(); foreach ($allModels as $key => $aModel) { if ($aModel->id == $model->id) { unset($allModels[$key]); } } echo $form->dropDownList($model, 'parent', CHtml::listData($allModels, 'id', 'name'), array('prompt' => 'None')); ?> <?php echo $form->error($model, 'parent_id'); ?> </div><!-- row --> <?php //menu selection available only for edit if (isset($menuId)) {
public function actionDeleteitem($id) { $menuItem = MenuItem::model()->findByPk($id); if ($menuItem->delete()) { $this->redirect(Yii::app()->request->urlReferrer); } }
<?php echo TbHtml::buttonGroup(MenuItem::model()->findByPk($id)->getItems());
<?php $this->widget('bootstrap.widgets.TbNav', array('type' => TbHtml::NAV_TYPE_TABS, 'items' => MenuItem::model()->findByPk($id)->getItems(), 'stacked' => true));
protected function afterDelete() { MenuItem::model()->deleteAll('menu_id = :id', array(':id' => $this->menu_id)); }
<?php echo TbHtml::navList(MenuItem::model()->findByPk($id)->getItems());
/** * Метод изменения пункта меню. * @param $oldTitle Старое название элемента (по нему осуществяется поиск) * @param $newTitle Новое название * @param $href Новая ссылка * @param $parentId id меню * @return bool статус выполнения */ public function changeItem($oldTitle, $newTitle, $href, $parentId) { $menuItem = MenuItem::model()->findByAttributes(array("title" => $oldTitle)); if ($menuItem === null) { return $this->addItem($newTitle, $href, $parentId); } $menuItem->parent_id = (int) $parentId; $menuItem->menu_id = $this->id; $menuItem->title = $newTitle; $menuItem->href = $href; if ($menuItem->save()) { Yii::app()->cache->clear(array('menu', $this->code)); return true; } return false; }
/** * Метод изменения пункта меню. * @param $oldTitle string Старое название элемента (по нему осуществяется поиск) * @param $newTitle string Новое название * @param $href string Новая ссылка * @param $parentId int id меню * @param $regularLink bool Обычная ссылка * @return bool статус выполнения */ public function changeItem($oldTitle, $newTitle, $href, $parentId, $regularLink = false) { $menuItem = MenuItem::model()->findByAttributes(['title' => $oldTitle]); if ($menuItem === null) { return $this->addItem($newTitle, $href, $parentId, $regularLink); } $menuItem->parent_id = (int) $parentId; $menuItem->menu_id = $this->id; $menuItem->title = $newTitle; $menuItem->href = $href; $menuItem->regular_link = $regularLink; if ($menuItem->save()) { Yii::app()->getCache()->clear(['menu', $this->code]); return true; } return false; }
<?php $this->widget('zii.widgets.CMenu', array('items' => MenuItem::model()->findByPk($id)->getItems()));
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'index' page * * @param int $id - record ID * * @return void * * @throws CHttpException */ public function actionDelete($id = null) { if (Yii::app()->getRequest()->getIsPostRequest()) { $model = $this->loadModel($id); if (Yii::app()->hasModule('menu')) { $menuItem = MenuItem::model()->findByAttributes(["title" => $model->title]); if ($menuItem !== null) { $menuItem->delete(); } } // we only allow deletion via POST request $model->delete(); Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('PageModule.page', 'Record was removed!')); // если это AJAX запрос ( кликнули удаление в админском grid view), мы не должны никуда редиректить Yii::app()->getRequest()->getParam('ajax') !== null || $this->redirect((array) Yii::app()->getRequest()->getPost('returnUrl', 'index')); } else { throw new CHttpException(404, Yii::t('PageModule.page', 'Bad request. Please don\'t repeat similar requests anymore!')); } }
<?php echo TbHtml::pills(MenuItem::model()->findByPk($id)->getItems());
<?php $links = array(); foreach (MenuItem::model()->findByPk($id)->getItems() as $item) { $url = isset($item['url']) ? $item['url'] : null; $links[] = CHtml::link($item['label'], $url, array('class' => 'btn btn-default')); } echo implode(' ', $links);