Esempio n. 1
0
 /**
  * Gets the menu items as html-string.
  * 
  * @param string $tpl
  * @param array $options
  * @return string
  */
 public function getItems($tpl = '', $options = array())
 {
     $html = '';
     $locale = '';
     $htmlMenuItems = '';
     $menuMapper = new \Modules\Admin\Mappers\Menu();
     $items = $menuMapper->getMenuItemsByParent($this->getId(), 0);
     $boxMapper = new \Modules\Admin\Mappers\Box();
     $config = \Ilch\Registry::get('config');
     if ((bool) $config->get('multilingual_acp')) {
         if ($this->layout->getTranslator()->getLocale() != $config->get('content_language')) {
             $locale = $this->layout->getTranslator()->getLocale();
         }
     }
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($item->getType() == 0 || $item->getType() == 4) {
                 $html = str_replace('%c', $htmlMenuItems, $html);
                 $htmlMenuItems = '';
                 $html .= str_replace('%s', $item->getTitle(), $tpl);
                 if ($item->getType() == 4) {
                     if ($item->getBoxId()) {
                         $box = $boxMapper->getBoxByIdLocale($item->getBoxId(), $locale);
                     } else {
                         $parts = explode('_', $item->getBoxKey());
                         $moduleKey = $parts[0];
                         $boxKey = $parts[1];
                         $class = '\\Modules\\' . ucfirst($moduleKey) . '\\Boxes\\' . ucfirst($boxKey);
                         $view = new \Ilch\View($this->layout->getRequest(), $this->layout->getTranslator(), $this->layout->getRouter());
                         $this->layout->getTranslator()->load(APPLICATION_PATH . '/modules/' . $moduleKey . '/translations');
                         $boxObj = new $class($this->layout, $view, $this->layout->getRequest(), $this->layout->getRouter(), $this->layout->getTranslator());
                         $boxObj->render();
                         $viewPath = APPLICATION_PATH . '/' . dirname($this->layout->getFile()) . '/override/' . $moduleKey . '/boxes/views/' . $boxKey . '.php';
                         if (!file_exists($viewPath)) {
                             $viewPath = APPLICATION_PATH . '/modules/' . $moduleKey . '/boxes/views/' . $boxKey . '.php';
                         }
                         $view->setLayoutKey($this->layout->getLayoutKey());
                         $output = $view->loadScript($viewPath);
                         $box = new \Modules\Admin\Models\Box();
                         $box->setContent($output);
                     }
                     $html = str_replace('%c', $box->getContent(), $html);
                 } else {
                     $htmlMenuItems .= $this->recGetItems($item, $locale, $options);
                 }
             }
         }
         $html = str_replace('%c', $htmlMenuItems, $html);
         $htmlMenuItems = '';
     }
     return $html;
 }
Esempio n. 2
0
 public function indexAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menu'), array('action' => 'index'));
     $menuId = 1;
     if ($this->getRequest()->getParam('menu')) {
         $menuId = (int) $this->getRequest()->getParam('menu');
     }
     $menuMapper = new MenuMapper();
     $pageMapper = new PageMapper();
     /*
      * Saves the item tree to database.
      */
     if ($this->getRequest()->isPost()) {
         if ($this->getRequest()->getPost('save')) {
             $sortItems = json_decode($this->getRequest()->getPost('hiddenMenu'));
             $items = $this->getRequest()->getPost('items');
             $oldItems = $menuMapper->getMenuItems($menuId);
             /*
              * Deletes old entries from database.
              */
             if (!empty($oldItems)) {
                 foreach ($oldItems as $oldItem) {
                     if (!isset($items[$oldItem->getId()])) {
                         $menuMapper->deleteItem($oldItem);
                     }
                 }
             }
             if ($items) {
                 $sortArray = array();
                 foreach ($sortItems as $sortItem) {
                     if ($sortItem->item_id !== null) {
                         $sortArray[$sortItem->item_id] = (int) $sortItem->parent_id;
                     }
                 }
                 foreach ($items as $item) {
                     $menuItem = new MenuItem();
                     if (strpos($item['id'], 'tmp_') !== false) {
                         $tmpId = str_replace('tmp_', '', $item['id']);
                     } else {
                         $menuItem->setId($item['id']);
                     }
                     $menuItem->setMenuId($menuId);
                     $menuItem->setType($item['type']);
                     $menuItem->setSiteId($item['siteid']);
                     $menuItem->setHref($item['href']);
                     $menuItem->setTitle($item['title']);
                     if ((int) $item['boxkey'] > 0) {
                         $menuItem->setBoxId($item['boxkey']);
                     } else {
                         $menuItem->setBoxKey($item['boxkey']);
                     }
                     $menuItem->setModuleKey($item['modulekey']);
                     $newId = $menuMapper->saveItem($menuItem);
                     if (isset($tmpId)) {
                         foreach ($sortArray as $id => $parentId) {
                             if ($id == $tmpId) {
                                 unset($sortArray[$id]);
                                 $sortArray[$newId] = $parentId;
                             }
                             if ($parentId == $tmpId) {
                                 $sortArray[$id] = $newId;
                             }
                         }
                     }
                 }
                 $sort = 0;
                 foreach ($sortArray as $id => $parent) {
                     $menuItem = new MenuItem();
                     $menuItem->setId($id);
                     $menuItem->setSort($sort);
                     $menuItem->setParentId($parent);
                     $menuMapper->saveItem($menuItem);
                     $sort += 10;
                 }
             }
             $menu = new MenuModel();
             $menu->setId($menuId);
             $menuMapper->save($menu);
         }
         if ($this->getRequest()->getPost('delete')) {
             $id = (int) $this->getRequest()->getParam('menu');
             $menuMapper->delete($id);
             $this->redirect(array('action' => 'index'));
         }
         $this->addMessage('saveSuccess');
     }
     $menuItems = $menuMapper->getMenuItemsByParent($menuId, 0);
     $menu = $menuMapper->getMenu($menuId);
     $menus = $menuMapper->getMenus();
     $moduleMapper = new \Modules\Admin\Mappers\Module();
     $boxMapper = new \Modules\Admin\Mappers\Box();
     $locale = '';
     if ((bool) $this->getConfig()->get('multilingual_acp')) {
         if ($this->getTranslator()->getLocale() != $this->getConfig()->get('content_language')) {
             $locale = $this->getTranslator()->getLocale();
         }
     }
     $this->getView()->set('menu', $menu);
     $this->getView()->set('menus', $menus);
     $this->getView()->set('menuItems', $menuItems);
     $this->getView()->set('menuMapper', $menuMapper);
     $this->getView()->set('pages', $pageMapper->getPageList($locale));
     $this->getView()->set('boxes', (array) $boxMapper->getBoxList($locale));
     $this->getView()->set('modules', $moduleMapper->getModules());
 }