/** * @method GET */ function get() { // get token $token = Utilities::ValidateJWTToken(); // check if token is not null if ($token != NULL) { $list = MenuType::GetMenuTypes($token->SiteId); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($list); return $response; } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
/** * @method GET */ function get() { // get an authuser $authUser = new AuthUser(); if (isset($authUser->UserUniqId)) { // check if authorized $list = MenuType::GetMenuTypes($authUser->SiteId); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($list); return $response; } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
public function actionDisplay() { global $mainframe, $user; if (!$user->isSuperAdmin()) { YiiMessage::raseNotice("Your account not have permission to view menu"); $this->redirect(Router::buildLink("cpanel")); } $this->pageTitle = "Menu manager"; $model = MenuType::getInstance(); $obj_menu = YiiMenu::getInstance(); $task = Request::getVar('task', ""); if ($task == "hidden" or $task == 'publish' or $task == "unpublish") { $cids = Request::getVar('cid'); for ($i = 0; $i < count($cids); $i++) { $cid = $cids[$i]; if ($task == "publish") { $this->changeStatus($cid, 1); } else { if ($task == "hidden") { $this->changeStatus($cid, 2); } else { $this->changeStatus($cid, 0); } } } YiiMessage::raseSuccess("Successfully saved changes status for menu type"); } $this->addIconToolbar("Creat", Router::buildLink('menus', array("view" => "menutype", 'layout' => 'new')), "new"); $this->addIconToolbar("Edit", Router::buildLink('menus', array("view" => "menutype", 'layout' => 'edit')), "edit", 1, 1, "Please select a item from the list to edit"); $this->addIconToolbar("Publish", Router::buildLink('menus', array("view" => "menutype", 'layout' => 'publish')), "publish"); $this->addIconToolbar("Unpublish", Router::buildLink('menus', array("view" => "menutype", 'layout' => 'unpublish')), "unpublish"); $this->addIconToolbar("Delete", Router::buildLink('menus', array("view" => "menutype", 'layout' => 'remove')), "trash", 1, 1, "Please select a item from the list to Remove"); $this->addBarTitle("Menu type <small>[manager]</small>", "user"); $items = $obj_menu->loadMenus("*", false); $this->render('default', array("items" => $items)); }
public function actionUpdate($id) { $model = $this->loadModel($id); $langerror = 'vn'; $activetab = 0; $dataId = $model->url; $urlType = $model->url_type; $model->fake_url = Yii::app()->extraFunctions->getRelativeUrl($urlType, $dataId); $modelMenuLanguage = new MenuLanguage('update'); //fake model menu language $listMenutype = MenuType::model()->findAll('status=1 ORDER BY ordering ASC'); $listMenuLanguage = MenuLanguage::model()->getListMenuLanguage($this->getLanguageCode(), $model->id, '0,1,2'); $listLanguage = Language::model()->listLanguage(); $attributeInTab = $this->convertMenuLanguageToArray($listLanguage, $model->id); // store records of menu_language to array if (isset($_POST['Menu']) && isset($_POST['MenuLanguage'])) { if (!empty($_POST['Menu']['fake_url'])) { if ($_POST['Menu']['url_type'] != 'category' && $_POST['Menu']['url_type'] != 'post') { $_POST['Menu']['url_type'] = $_POST['Menu']['fake_url']; $_POST['Menu']['url'] = 1; } } else { $_POST['Menu']['url_type'] = NULL; $_POST['Menu']['url'] = NULL; } $model->attributes = $_POST['Menu']; // $model->url = str_replace(PHP_EOL, '', $model->url);; $postMenuLanguage = $_POST['MenuLanguage']; $this->validateMenuLanguage($listLanguage, $postMenuLanguage, $modelMenuLanguage, $errorMessage, $attributeInTab); if (empty($postMenuLanguage)) { Yii::app()->user->setFlash('error', Yii::t('menu', 'Name, Description cannot be blank.')); } if (($errorString = $this->convertErrorMessageToString($errorMessage)) !== FALSE) { Yii::app()->user->setFlash('error', $errorString); if (strpos($errorString, 'Vietnamese') == FALSE && strpos($errorString, 'English') != FALSE) { $langerror = 'en'; } } if ($model->validate() && empty($errorMessage) && !empty($postMenuLanguage)) { $transaction = Yii::app()->db->beginTransaction(); try { $parent = Menu::model()->findByPK($model->parent_id); if ($parent !== NULL && $parent->menu_type != 0) { $model->menu_type = $parent->menu_type; } if ($model->saveNode()) { Menu::model()->updateAll(array('menu_type' => $model->menu_type, 'status' => $model->status), 'lft BETWEEN ' . $model->lft . ' AND ' . $model->rgt); foreach ($postMenuLanguage as $index => $attribute) { $modelMenuLanguage = MenuLanguage::model()->find('menu_id=:id AND language_id=:language', array(':id' => $model->id, ':language' => $attribute['language_id'])); $modelMenuLanguage->name = $attribute['name']; $modelMenuLanguage->description = str_replace(PHP_EOL, '', $attribute['description']); if (!$modelMenuLanguage->save()) { Yii::app()->user->setFlash('error', Yii::t('menu', 'Update menu language failed. Please try it later.')); $transaction->rollback(); } } $this->resetTree(); $transaction->commit(); Yii::app()->user->setFlash('success', Yii::t('menu', 'Update menu successfully.')); $this->redirect(array('/' . backend . '/menu/admin')); } } catch (Exception $ex) { $transaction->rollback(); Yii::app()->user->setFlash('error', Yii::t('menu', 'Update menu failed. Please try it later.')); } } } if ($langerror == 'en') { $activetab = 1; } $this->render(strtolower($this->action->id), array('model' => $model, 'modelMenuLanguage' => $modelMenuLanguage, 'listMenutype' => $listMenutype, 'listLanguage' => $listLanguage, 'listMenuLanguage' => $listMenuLanguage, 'attributeInTab' => $attributeInTab, 'listParentMenutype' => json_encode($listMenuLanguage['menu_type']), 'activetab' => $activetab)); }
public static function PublishMenuJSON($site) { $types = MenuType::GetMenuTypes($site['SiteId']); // create types for primary, footer $primary = array('MenuTypeId' => -1, 'FriendlyId' => 'primary'); $footer = array('MenuTypeId' => -1, 'FriendlyId' => 'footer'); // push default types array_push($types, $primary); array_push($types, $footer); // walk through types foreach ($types as $type) { // get items for type $list = MenuItem::GetMenuItemsForType($site['SiteId'], $type['FriendlyId']); // encode to json $encoded = json_encode($list); $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/data/'; Utilities::SaveContent($dest, 'menu-' . $type['FriendlyId'] . '.json', $encoded); } }
public function getListMenu($lang = 'vi', $menu_type = NULL, $status = NULL, $level = NULL, $strtolower = NULL, $parent_id = NULL, $limit = NULL, $orderby = NULL) { $root = isset($parent_id) ? $this->getParent($parent_id) : $this->getRoot(); $allMenutypes = implode(",", $this->getAllMenutypes()); $menu_type = is_numeric($menu_type) ? MenuType::model()->findByPK($menu_type) : MenuType::model()->find('name_type="' . $menu_type . '"'); $command = Yii::app()->db->createCommand(); if (!empty($strtolower)) { $command->select('m.*, LOWER(m_l.name) AS "name", m_l.description'); } else { $command->select('m.*, m_l.name, m_l.description'); } $command->from('menu as m')->join('menu_language as m_l', 'm.id = m_l.menu_id')->join('language as lang', 'lang.id = m_l.language_id')->where('m.parent_id <> 0 AND lang.code =:code', array(':code' => $lang))->andWhere('m.lft BETWEEN :lft AND :rgt', array(':lft' => $root['lft'], ':rgt' => $root['rgt']))->andWhere('m.menu_type IN (' . (empty($menu_type) ? $allMenutypes : $menu_type->id) . ')')->andWhere('m.status IN (' . (empty($status) ? '1,0' : $status) . ')'); if (!empty($level)) { $command->andWhere('m.level IN (' . $level . ')'); } else { $command->andWhere('m.level <> 0'); } // if(!empty($parent_id)){ // $command->andWhere('m.parent_id=:parent_id',array(':parent_id'=>$parent_id)); // } if (!empty($limit)) { $command->limit($limit); } if (!empty($orderby)) { $command->order("m.{$orderby} asc"); } else { $command->order('m.lft asc'); } return $command->queryAll(); }
public static function PublishMenuJSON($siteId) { $site = Site::GetBySiteId($siteId); $types = MenuType::GetMenuTypes($site['SiteId']); // create types for primary, footer $primary = array('MenuTypeId' => -1, 'FriendlyId' => 'primary'); $footer = array('MenuTypeId' => -1, 'FriendlyId' => 'footer'); // push default types array_push($types, $primary); array_push($types, $footer); // walk through types foreach ($types as $type) { echo $type['FriendlyId']; // get items for type $list = MenuItem::GetMenuItemsForType($site['SiteId'], $type['FriendlyId']); // create array for menu $menu = array(); // walk through menu items foreach ($list as $row) { $isInternal = false; $state = ''; $url = ''; // push non nested items onto the array if ($row['IsNested'] == 0) { // create an array item $item = array('MenuItemId' => $row['MenuItemId'], 'Name' => $row['Name'], 'CssClass' => $row['CssClass'], 'Url' => $row['Url'], 'PageId' => $row['PageId'], 'HasChildren' => false, 'Children' => array()); // push item onto the array array_push($menu, $item); } else { // create an array item $item = array('MenuItemId' => $row['MenuItemId'], 'Name' => $row['Name'], 'CssClass' => $row['CssClass'], 'Url' => $row['Url'], 'PageId' => $row['PageId']); // get a reference to the parent $parent = array_pop($menu); // make sure the parent exists if ($parent != NULL) { // push item to the children array array_push($parent['Children'], $item); // set that it has children $parent['HasChildren'] = true; // push item onto the array array_push($menu, $parent); } } } // encode to json $encoded = json_encode($menu); $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/data/'; echo $dest . 'menu-' . $type['FriendlyId'] . '.json'; Utilities::SaveContent($dest, 'menu-' . $type['FriendlyId'] . '.json', $encoded); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionImport() { $model = new MenuType(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['MenuType'])) { if (!empty($_FILES)) { $tempFile = $_FILES['MenuType']['tmp_name']['fileImport']; $fileTypes = array('xls', 'xlsx'); // File extensions $fileParts = pathinfo($_FILES['MenuType']['name']['fileImport']); if (in_array(@$fileParts['extension'], $fileTypes)) { Yii::import('ext.heart.excel.EHeartExcel', true); EHeartExcel::init(); $inputFileType = PHPExcel_IOFactory::identify($tempFile); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($tempFile); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); $baseRow = 2; $inserted = 0; $read_status = false; while (!empty($sheetData[$baseRow]['A'])) { $read_status = true; //$menuType_id= $sheetData[$baseRow]['A']; $name = $sheetData[$baseRow]['B']; $model2 = new MenuType(); //$model2->menuType_id= $menuType_id; $model2->name = $name; try { if ($model2->save()) { $inserted++; } } catch (Exception $e) { Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } $baseRow++; } Yii::app()->user->setFlash('success', $inserted . ' row inserted'); } else { Yii::app()->user->setFlash('warning', 'Wrong file type (xlsx, xls, and ods only)'); } } $this->render('admin', array('model' => $model)); } else { $this->render('admin', array('model' => $model)); } }
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'menu-form', 'enableAjaxValidation' => false)); ?> <?php echo $form->errorSummary($model); echo Chtml::dropDownList('mType', '', CHtml::listData(MenuType::model()->findAll(), 'mType_id', 'name'), array('empty' => 'Выберите тип меню')); ?> <div id="listData"></div> <script> $(document).ready(function(){ $('#mType').change(function(){ var id = $(this).val(); $.ajax({ type: "POST", url: "<?php echo Yii::app()->createUrl('menu/menuList'); ?> ", data: "mType="+id, success: function(data){ $('#listData').html(data); } }); }); }); </script> <div class="form-actions"> <?php
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return MenuType the loaded model * @throws CHttpException */ public function loadModel($id) { $model = MenuType::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('menutype', 'The requested page does not exist.')); } return $model; }