예제 #1
0
 protected function saveMenuItem($row, $menuCode)
 {
     $module = $this->modules[$this->data[$row]['Module']];
     $titles = explode("\n", $this->data[$row]['Name']);
     $item = new Cms_Model_MenuItem();
     $item->set_application_id(1)->set_menu($this->menuCode)->set_route($module['route'])->set_menu($menuCode);
     //set page id
     if (isset($this->data[$row]['page_id'])) {
         $item->set_page_id_new($this->data[$row]['page_id']);
     }
     //set path / params
     $item->set_path($module['path']);
     if (isset($module['params'])) {
         $item->set_params($module['params']);
     } else {
         $item->set_params("");
     }
     $item->set_params_old("");
     //uri
     if ($this->data[$row]['Module'] == 'external' && isset($this->data[$row]['External url'])) {
         $item->set_uri($this->data[$row]['External url']);
     }
     //set order
     $item->set_ord_num($row);
     foreach ($this->languages as $langIndex => $lang) {
         $title = $this->getLangText($titles, $langIndex);
         $item->set_name($title)->set_level($this->data[$row]['level'])->set_parent_id(0);
         //set parent
         if (isset($this->data[$row]['parent'])) {
             $parentRow = $this->data[$this->data[$row]['parent']];
             if (isset($parentRow['menu_item_id'])) {
                 $item->set_parent_id($parentRow['menu_item_id']);
             }
         }
         Cms_Model_MenuItemMapper::getInstance()->save($item, $lang, true);
     }
     $this->data[$row]['menu_item_id'] = $item->get_id();
 }
예제 #2
0
 public function menuEditAction()
 {
     $data = $this->getRequest()->getPost('data');
     $submit = $this->getRequest()->getPost('submit');
     $id = $this->_getParam('id');
     $langFilter = $this->_getParam('langFilter');
     $menuFilter = $this->_getParam('menuFilter');
     /* get routes from application.ini */
     $bootstrap = $this->getInvokeArg('bootstrap');
     $routes = array_keys($bootstrap->getResource('router')->getRoutes());
     /* get all modules */
     $criteria['application_id'] = $this->_applicationId;
     $modules = Application_Model_ModuleMapper::getInstance()->fetchAll($criteria);
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'menu')), $this->translate('Action canceled'));
     }
     if (isset($data['path']) && $data['path'] != '') {
         foreach ($modules as $module) {
             $moduleData = $module->get_data();
             if (isset($moduleData['menus'])) {
                 foreach ($moduleData['menus'] as $path => $menu) {
                     if ($module->get_code() . "/" . $path == $data['path']) {
                         $data['dialog_url'] = $menu['dialog_url'];
                     }
                 }
             }
         }
     }
     //create form object
     $form = new Cms_Form_MenuItem($data);
     $route = new Cms_Model_Route();
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             //create entity object from submitted values, and save
             $item = new Cms_Model_MenuItem($values);
             if ($data['route'] == '') {
                 $item->set_path('');
                 $item->set_page_id('');
                 $item->set_page_id_new('');
                 $item->set_params('');
             } else {
                 $item->set_uri('');
             }
             //new entity
             if (!isset($data['id']) || $data['id'] <= 0) {
                 $item->set_application_id($this->_applicationId);
             } else {
                 $existingMenu = new Cms_Model_MenuItem();
                 if (!Cms_Model_MenuItemMapper::getInstance()->find($data['id'], $existingMenu)) {
                     throw new Exception("Menu not found");
                 }
                 if ((int) $existingMenu->get_application_id() != $this->_applicationId) {
                     throw new Exception("Cannot edit this Menu Item.");
                 }
             }
             $item->set_application_id($this->_applicationId);
             Cms_Model_MenuItemMapper::getInstance()->save($item, $langFilter);
             //save done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'menu')), $this->translate('Menu Item saved.'));
         } else {
             //we have errors - return json or continue
             $this->_formHelper->returnError($form->getMessages());
         }
     } elseif (!$this->_formHelper->getRequest()->isPost()) {
         //edit action
         if (isset($id) && $id > 0) {
             $item = new Cms_Model_MenuItem();
             if (!Cms_Model_MenuItemMapper::getInstance()->find($id, $item, $langFilter)) {
                 throw new Exception("Menu not found");
             }
             Cms_Model_RouteMapper::getInstance()->findByPath($item->get_path(), $this->_applicationId, $route, $item->get_params(), $langFilter != '' ? $langFilter : null);
             $item->set_route_uri($route->get_uri());
             $params = $item->get_params();
             $item->set_params(Cms_Model_MenuItemMapper::getInstance()->unsetParamsPageId($params));
             //fetch data
             $data = $item->toArray();
             //populate form with data
             $form->setData($data);
         }
     }
     $this->view->menus = Cms_Model_MenuMapper::getInstance()->getMenus();
     $this->view->menuFilter = $menuFilter;
     $this->view->langFilter = $langFilter;
     $this->view->routes = $routes;
     $this->view->modules = $modules;
     $page = new Cms_Model_Page();
     if (isset($data['page_id'])) {
         Cms_Model_PageMapper::getInstance()->find($data['page_id'], $page);
     }
     $this->view->page_title = $page->get_title();
     $this->view->data = $data;
 }