public function actionUpdate($id)
 {
     if (Yii::app()->request->isAjaxRequest) {
         $this->layout = '//layouts/empty';
     } else {
         $this->layout = '//layouts/main';
     }
     Yii::app()->clientScript->registerCSSFile(Yii::app()->request->getBaseUrl(false) . '/js/plugins/bootstrap-switch/static/stylesheets/bootstrap-switch-metro.css');
     Yii::app()->clientScript->registerScriptFile(Yii::app()->request->getBaseUrl(false) . '/js/plugins/bootstrap-switch/static/js/bootstrap-switch.min.js', CClientScript::POS_BEGIN);
     Yii::app()->clientScript->registerScriptFile(Yii::app()->request->getBaseUrl(false) . '/js/plugins/bootstrap-touchspin/bootstrap.touchspin.js', CClientScript::POS_END);
     Yii::app()->clientScript->registerScript('initTouchSpin', "FormComponents.initTouchSpin();", CClientScript::POS_END);
     $sections = $this->getMainSections();
     $parents[0] = 'Нет родителя';
     foreach ($sections as $section) {
         if ($section['id'] != $id) {
             $parents[$section['id']] = $section['title'];
         }
     }
     $childs = MenuLink::model()->findAll(array('conditions' => array('menu_id' => array('equals' => 7)), 'sort' => array('parent_id' => 1, 'order' => 1)));
     foreach ($childs as $child) {
         $show = false;
         $allowed_modules = explode(',', $child->is_visible);
         foreach ($allowed_modules as $am) {
             if (trim($am) == 1) {
                 $show = true;
             } else {
                 if (Yii::app()->params[trim($am)]) {
                     $show = true;
                 }
             }
         }
         if ($show) {
             $temp = array();
             $temp['id'] = $child->id;
             $temp['title'] = $child->title;
             if ($child->parent_id > 0) {
                 $filtered_childs[$child->parent_id][] = $temp;
             }
         }
     }
     $model = $this->loadModel($id);
     if (isset($_POST['MenuLinks'])) {
         $model->attributes = $_POST['MenuLinks'];
         // TODO поправить баг
         $model->controller = $_POST['MenuLinks']['controller'];
         $model->url = $_POST['MenuLinks']['url'];
         $model->icon = $_POST['MenuLinks']['icon'];
         if ($_POST['MenuLinks']['is_visible'] == "Да") {
             $model->is_visible = true;
         } else {
             if ($_POST['MenuLinks']['is_visible'] == "Нет") {
                 $model->is_visible = false;
             } else {
                 $model->is_visible = $_POST['MenuLinks']['is_visible'];
             }
         }
         if ($model->save()) {
             $this->redirect(array('index'));
         }
     }
     $updateSection = null;
     foreach ($sections as $section) {
         if ($section->id == $id) {
             $updateSection = $section;
         }
     }
     $this->render('update', array('model' => $model, 'sections' => $parents, 'section' => $updateSection, 'subsections' => $filtered_childs[$id]));
 }
 public function getHiddenSections()
 {
     return MenuLink::model()->findAll(array('conditions' => array('menu_id' => array('equals' => 7), 'is_visible' => array('equals' => false)), 'sort' => array('order' => 1)));
 }