示例#1
0
 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));
 }
 /**
  * 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, 'The requested page does not exist.');
     }
     return $model;
 }
示例#3
0
 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();
 }
示例#4
0
<?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