예제 #1
0
파일: NavHelper.php 프로젝트: UnionCMS/Core
 /**
  * Create and render navigation menu.
  *
  * @param array $items
  * @param string|int $key
  * @param array $options
  * @param int $level
  * @return string
  */
 public function render($key, array $items = [], array $options = [], $level = 1)
 {
     $_options = ['active' => 'active', 'type' => self::MENU_TYPE_COLLAPSE, 'menuAttr' => ['class' => 'menu', 'id' => 'level-' . $level]];
     $counter = 0;
     $out = '';
     $options = Hash::merge($_options, $options);
     $menuAttr = $options['menuAttr'];
     $type = $options['type'];
     $sorted = Hash::sort($items, '{s}.weight', 'ASC');
     foreach ($sorted as $link) {
         $child = '';
         $counter = $counter + 1;
         $title = h($link['title']);
         $liAttr = $this->_setLiAttr($counter, $link, $options);
         $linkAttr = $this->_setLinkAttr($counter, $link, $options);
         if (count($link['children']) > 0) {
             list($child, $link, $linkAttr, $title, $level) = $this->_createChild($key, $link, $level, $linkAttr, $type);
         }
         $title = $this->_createIcon($title, $link);
         $linkItem = $this->link($title, $link['url'], $linkAttr);
         $out .= $this->tag('li', $linkItem . $child, $liAttr);
         $counter++;
     }
     return $this->tag('ul', $out, $menuAttr);
 }
 public function render($data, $level = 0, $options = [])
 {
     if (empty($data)) {
         return '';
     }
     $html = '';
     $data = Hash::sort($data, '{s}.weight');
     foreach ($data as $class => $menu) {
         if (empty($menu)) {
             continue;
         }
         if (!isset($menu['options'])) {
             $menu['options'] = [];
         }
         $isDropdown = false;
         $liOptions = ['class' => ''];
         if ($level == 0 && isset($menu['options']['dropdown']) && !empty($menu['options']['dropdown'])) {
             $isDropdown = true;
             $liOptions['class'] .= 'dropdown';
         }
         if (!isset($menu['type'])) {
             $menu['type'] = 'link';
         }
         $block = $this->{$menu['type']}($menu, $level);
         $nextLevel = $level + 1;
         if ($menu['type'] == 'link') {
             if (isset($menu['children']) && !empty($menu['children']) && $nextLevel < 3) {
                 $childrenOptions = ['class' => 'nav nav-' . $this->_levels[$nextLevel] . '-level'];
                 if ($isDropdown) {
                     $childrenOptions = ['class' => 'dropdown-menu ' . $menu['options']['dropdown']];
                 }
                 $block .= $this->render($menu['children'], $nextLevel, $childrenOptions);
             }
         }
         $liOptions['class'] .= $class;
         if (isset($menu['url']) && $this->isLinkActive($menu['url']) || preg_match("/active/i", $block)) {
             $liOptions['class'] = ' active';
         }
         $html .= $this->Html->tag('li', $block, $liOptions);
     }
     return $this->Html->tag('ul', $html, $options);
 }
예제 #3
0
 public function adminMenus($items, $options = [], $depth = 0)
 {
     $options += ['type' => 'sidebar', 'children' => true, 'title' => ['class' => 'title'], 'arrow' => ['class' => 'arrow'], 'child_ul' => ['class' => 'sub-menu']];
     $output = '';
     $items = Hash::sort($items, '{s}.weight', 'ASC');
     foreach ($items as $item) {
         $liClass = [];
         if ($this->request->here == Router::url($item['url'])) {
             $liClass[] = 'active';
             if ($depth > 0) {
                 $this->_hasActiveMenuItem = true;
             }
         }
         $childrenBody = '';
         if (!empty($item['children'])) {
             $childrenBody .= $this->Html->tag('ul', null, $options['child_ul']);
             $childrenBody .= $this->adminMenus($item['children'], $options, $depth + 1);
             $childrenBody .= $this->tagend('ul');
         }
         //If first item and has current url is in sub child then active&open menu
         //Then reset activeMenu flag
         //            $listOptions = (isset($options['li-' . $depth]) ? $options['li-' . $depth] : (isset($options['li-*']) ? $options['li-*'] : []));
         //            debug($listOptions);die;
         if ($this->_hasActiveMenuItem && $depth == 0) {
             $liClass[] = 'active';
             $liClass[] = 'open';
             $this->_hasActiveMenuItem = false;
         }
         $output .= $this->Html->tag('li', null, ['class' => $liClass]);
         $linkOptions = isset($options['a-' . $depth]) ? $options['a-' . $depth] : (isset($options['a-*']) ? $options['a-*'] : []);
         $output .= $this->Html->link($this->__buildMenuLinkBody($item, $depth, $options), $item['url'], array_merge(['escape' => false], $linkOptions));
         $output .= $childrenBody;
         $output .= $this->tagend('li');
     }
     return $output;
 }
예제 #4
0
 /**
  * Test sorting on a nested key that is sometimes undefined.
  *
  * @return void
  */
 public function testSortSparse()
 {
     $data = [['id' => 1, 'title' => 'element 1', 'extra' => 1], ['id' => 2, 'title' => 'element 2', 'extra' => 2], ['id' => 3, 'title' => 'element 3'], ['id' => 4, 'title' => 'element 4', 'extra' => 4]];
     $result = Hash::sort($data, '{n}.extra', 'desc', 'natural');
     $expected = [['id' => 4, 'title' => 'element 4', 'extra' => 4], ['id' => 2, 'title' => 'element 2', 'extra' => 2], ['id' => 1, 'title' => 'element 1', 'extra' => 1], ['id' => 3, 'title' => 'element 3']];
     $this->assertSame($expected, $result);
 }
예제 #5
0
 /**
  * Chooser action.
  *
  * @return void
  */
 public function chooser()
 {
     Event::dispatch('Controller.Admin.Link.Chooser', $this);
     $types = Configure::read('Link.choosers');
     $types = Hash::sort($types, '{n}.order', 'desc');
     $this->set('types', $types);
 }
예제 #6
0
 /**
  * test sorting with string keys.
  *
  * @return void
  */
 public function testSortString()
 {
     $toSort = ['four' => ['number' => 4, 'some' => 'foursome'], 'six' => ['number' => 6, 'some' => 'sixsome'], 'five' => ['number' => 5, 'some' => 'fivesome'], 'two' => ['number' => 2, 'some' => 'twosome'], 'three' => ['number' => 3, 'some' => 'threesome']];
     $sorted = Hash::sort($toSort, '{s}.number', 'asc');
     $expected = ['two' => ['number' => 2, 'some' => 'twosome'], 'three' => ['number' => 3, 'some' => 'threesome'], 'four' => ['number' => 4, 'some' => 'foursome'], 'five' => ['number' => 5, 'some' => 'fivesome'], 'six' => ['number' => 6, 'some' => 'sixsome']];
     $this->assertEquals($expected, $sorted);
     $menus = ['blogs' => ['title' => 'Blogs', 'weight' => 3], 'comments' => ['title' => 'Comments', 'weight' => 2], 'users' => ['title' => 'Users', 'weight' => 1]];
     $expected = ['users' => ['title' => 'Users', 'weight' => 1], 'comments' => ['title' => 'Comments', 'weight' => 2], 'blogs' => ['title' => 'Blogs', 'weight' => 3]];
     $result = Hash::sort($menus, '{s}.weight', 'ASC');
     $this->assertEquals($expected, $result);
 }
예제 #7
0
 /**
  * add
  *
  * Adds a new menu-item.
  *
  * ### OPTIONS
  * - id
  * - parent
  * - url
  * - title
  * - icon
  * - area
  * - weight
  *
  * @param string $title The title or id of the item.
  * @param array $item Options for the item.
  * @return void
  */
 public function add($title, $item = [])
 {
     $list = self::$data;
     $_item = ['id' => $title, 'parent' => false, 'url' => '#', 'title' => $title, 'icon' => '', 'area' => $this->area(), 'active' => false, 'weight' => 10, 'children' => []];
     $item = array_merge($_item, $item);
     $url = Router::url($item['url']);
     $actives = $this->config('active');
     if ($url === Router::url("/" . $this->Controller->request->url)) {
         $item['active'] = true;
     }
     $this->area = $item['area'];
     $data = self::$data;
     if (array_key_exists($this->area, $data)) {
         $menu = $data[$this->area];
     } else {
         $menu = [];
     }
     if ($item['parent']) {
         if (array_key_exists($item['parent'], $menu)) {
             $menu[$item['parent']]['children'][$item['id']] = $item;
         }
     } else {
         $menu[$item['id']] = $item;
     }
     $menu = Hash::sort($menu, '{s}.weight', 'asc');
     $data[$this->area] = $menu;
     self::$data = $data;
 }
예제 #8
0
 /**
  * add
  *
  * Adds a new menu-item.
  *
  * ### OPTIONS
  * - id
  * - parent
  * - url
  * - title
  * - icon
  * - area
  * - weight
  *
  * @param string $title The title or id of the item.
  * @param array $item Options for the item.
  * @return void
  */
 public function add($title, $item = [])
 {
     $list = self::$data;
     $_item = ['id' => $title, 'parent' => false, 'url' => '#', 'title' => $title, 'icon' => '', 'area' => $this->area(), 'active' => false, 'weight' => 10, ''];
     $item = array_merge($_item, $item);
     $url = Router::url($item['url']);
     $actives = $this->config('active');
     if ($url === "/" . $this->Controller->request->url) {
         $item['active'] = true;
     }
     $this->area = $item['area'];
     $data = self::$data;
     $data[$this->area][$item['id']] = $item;
     $data[$this->area] = Hash::sort($data[$this->area], '{s}.weight', 'asc');
     self::$data = $data;
 }
예제 #9
0
 /**
  * Created admin nested menu.
  *
  * @param $menus
  * @param array $options
  * @param int $depth
  * @return string
  */
 public function menu($menus, array $options = [], $depth = 0)
 {
     $_options = ['children' => true, 'htmlAttr' => ['class' => 'nav nav-list', 'dropDown' => false, 'downClasses' => ['dropdown-menu', 'dropdown-caret', 'dropdown-close', 'dropdown-yellow', 'dropdown-menu-right']]];
     $out = null;
     $options = Hash::merge($_options, $options);
     $isDropDown = $options['htmlAttr']['dropDown'];
     $downClasses = $options['htmlAttr']['downClasses'];
     $htmlAttributes = $options['htmlAttr'];
     unset($options['htmlAttr']);
     unset($htmlAttributes['dropDown']);
     unset($htmlAttributes['downClasses']);
     $menus = Hash::sort($menus, '{s}.weight', 'ASC');
     $i = 0;
     foreach ($menus as $menu) {
         $itemId = $i + 1;
         $liOptions = ['class' => 'li-link link-' . $itemId];
         if (isset($menu['divider'])) {
             $liOptions = $this->addClass($liOptions, 'divider');
             $out .= $this->Html->tag('li', null, $liOptions);
             continue;
         }
         $menu['htmlAttr']['title'] = h($menu['title']);
         $title = $this->Html->tag('span', $menu['title'], ['class' => 'un-link-label']);
         unset($menu['title']);
         if (empty($menu['htmlAttr']['class'])) {
             $menu['htmlAttr'] = Hash::merge(['class' => 'admin-link-menu'], $menu['htmlAttr']);
         }
         if (!empty($menu['icon'])) {
             $menu['htmlAttr'] = ['icon' => $menu['icon'], 'iconClass' => 'menu-icon'];
         }
         if (isset($menu['before'])) {
             $title = $menu['before'] . $title;
         }
         if (isset($menu['after'])) {
             $title .= $menu['after'];
         }
         $children = null;
         if (!empty($menu['children'])) {
             $level = $depth + 1;
             $childClass = 'submenu hasChild level-' . $level;
             $liOptions = $this->addClass($liOptions, 'un-parent');
             $title .= PHP_EOL . $this->Html->icon('angle-down', ['class' => 'arrow']);
             if ($isDropDown) {
                 $childClass = implode(' ', $downClasses);
             }
             $children = $this->menu($menu['children'], ['children' => true, 'htmlAttr' => ['class' => $childClass, 'dropDown' => $isDropDown]], $level);
         }
         if ($this->Url->build($menu['url']) == env('REQUEST_URI')) {
             $liOptions = $this->addClass($liOptions, 'active');
         }
         if (!empty($children)) {
             $menu['htmlAttr'] = $this->addClass($menu['htmlAttr'], 'dropdown-toggle');
             if ($isDropDown) {
                 $menu['htmlAttr']['data-toggle'] = 'dropdown';
             }
             if (preg_match("#active#i", $children)) {
                 $liOptions = $this->addClass($liOptions, 'active open');
             }
         }
         if (($depth > 0 || !empty($children)) && !$isDropDown) {
             $menu['htmlAttr']['isClear'] = true;
             $title = $this->Html->icon('caret-right', ['class' => 'menu-icon']) . $title;
         }
         $link = $this->Html->link($title, $menu['url'], $menu['htmlAttr']);
         if (isset($menu['divider'])) {
             $link = null;
         }
         if (isset($menu['liClass'])) {
             $liOptions = $this->addClass($liOptions, $menu['liClass']);
         }
         $out .= $this->Html->tag('li', $link . $children, $liOptions);
         $i++;
     }
     return $this->Html->tag('ul', $out, $htmlAttributes);
 }
예제 #10
0
 public function edit($id = null)
 {
     $broch = $this->request->data;
     if (!$id && empty($this->request->data)) {
         $this->Flash->set(__('Invalid brochure'));
         $this->redirect(array('action' => 'index'));
     }
     if (!empty($this->request->data)) {
         $this->Brochures->BrochureOrderAmts->deleteAll(['brochure_id' => $id]);
         $brochureOrderAmts = [];
         foreach ($this->request->data['brochure_order_amts'] as $brochurOrderAmt) {
             if ($brochurOrderAmt['quantity'] != null) {
                 array_push($brochureOrderAmts, $this->Brochures->BrochureOrderAmts->newEntity($brochurOrderAmt));
             }
         }
         $this->request->data['brochure_order_amts'] = array(null);
         $brochure = $this->Brochures->newEntity($this->request->data);
         $brochure->brochure_order_amts = $brochureOrderAmts;
         if ($this->Brochures->save($brochure)) {
             $this->Flash->set(__('The brochure has been saved'));
             //     $this->_notifyWarehouse($broch);
             $this->redirect($this->referer());
         } else {
             $this->Flash->set(__('The brochure could not be saved. Please, try again.'));
             $this->redirect($this->referer());
         }
     }
     if (empty($this->request->data)) {
         $this->request->data = $this->Brochures->findById($id)->contain(['BrochureOrderAmts', 'Racks'])->first()->toArray();
         $broch1 = $this->request->data;
         $sortedracks = Hash::sort($broch1['racks'], '{n}.rack_number', 'asc');
         $this->set(compact('sortedracks'));
     }
     $images = $this->Brochures->Images->find('list', array('fields' => array('id', 'caption'), 'order' => ['Images.caption']));
     $suppliers = $this->Brochures->Suppliers->find('list', array('fields' => array('id', 'company'), 'order' => ['Suppliers.company']));
     $this->set(compact('images', 'suppliers'));
     $brochurelinks = $this->request->data['ebrochure'];
     $this->set(compact('brochurelinks'));
 }
예제 #11
0
파일: Menu.php 프로젝트: wasabi-cms/core
 /**
  * Create and return an array clone of menu items ordered by their priority.
  *
  * @param array $items The menu items to order.
  * @return array
  */
 public function getOrderedArray($items = [])
 {
     $ordered = [];
     if (empty($items)) {
         $items = $this->_menuItems;
     }
     foreach ($items as $item) {
         $ordered[] = $item;
     }
     $ordered = Hash::sort($ordered, '{n}.priority', 'ASC');
     foreach ($ordered as &$item) {
         if (isset($item['children']) && !empty($item['children'])) {
             $item['children'] = $this->getOrderedArray($item['children']);
         }
     }
     return $ordered;
 }
예제 #12
0
 /**
  * test regular sorting ignoring case.
  *
  * @return void
  */
 public function testSortRegularIgnoreCase()
 {
     $toSort = [['Item' => ['name' => 'bar']], ['Item' => ['name' => 'Baby']], ['Item' => ['name' => 'Baz']], ['Item' => ['name' => 'bat']]];
     $sorted = Hash::sort($toSort, '{n}.Item.name', 'asc', ['type' => 'regular', 'ignoreCase' => true]);
     $expected = [['Item' => ['name' => 'Baby']], ['Item' => ['name' => 'bar']], ['Item' => ['name' => 'bat']], ['Item' => ['name' => 'Baz']]];
     $this->assertEquals($expected, $sorted);
 }
예제 #13
0
 public function processCount($oneEnd, $query)
 {
     $countTotalOnDay = [];
     foreach ($query as $key => $row) {
         $dateFormat = $row->date_result->i18nFormat('yyyy-MM-dd');
         if ($row->one_end == $oneEnd) {
             $countTotalOnDay[$dateFormat] = Hash::check($countTotalOnDay, $dateFormat) ? $countTotalOnDay[$dateFormat] + 1 : 1;
         }
     }
     $arrDurationPresent = [];
     $space = 0;
     foreach ($countTotalOnDay as $key => $value) {
         if ($value > 3) {
         } else {
             $space++;
             continue;
         }
         $arrDurationPresent[$space]['count'] = Hash::check($arrDurationPresent, "{$space}.count") ? $arrDurationPresent[$space]['count'] + 1 : 1;
         //$arrDurationPresent[$space]['date'][] = $key;
         $arrDurationPresent[$space]['index'] = $space;
         $space = 0;
     }
     $arrDurationPresent = Hash::sort($arrDurationPresent, '{n}.index', 'asc');
     return $arrDurationPresent;
 }
예제 #14
0
 /**
  * add item to the tabs
  *
  * @param string $title title
  * @param array $item item
  * @return void
  */
 public function add($title, array $item = [])
 {
     $list = self::$tabs;
     $_item = ['id' => $title, 'url' => '#', 'title' => $title, 'active' => false, 'weight' => 10];
     $item = array_merge($_item, $item);
     $url = Router::url($item['url']);
     $active = $this->config('active');
     if ($url === Router::url('/' . $this->Controller->request->url)) {
         $item['active'] = true;
     }
     $tabs = self::$tabs;
     $tabs[$item['id']] = $item;
     $tabs = Hash::sort($tabs, '{s}.weight', 'asc');
     self::$tabs = $tabs;
 }
 /**
  * Get translated fields
  *
  * @return array
  */
 public function getTranslatedFields()
 {
     return Hash::apply($this->config('fields'), '{n}[searchable=true]', function ($array) {
         $formatted = [];
         foreach ($array as $data) {
             $formatted[$data['name']] = $data['translation'];
         }
         return Hash::sort($formatted, '{s}', 'asc');
     });
 }
예제 #16
0
 /**
  * Getting all permission related to given aro entity
  * @param Entity $aro
  * @return array|mixed
  */
 public function getPermissions($aro)
 {
     if (empty($aro)) {
         return [];
     }
     if (!is_array($aro)) {
         $aro = [$aro];
     }
     $permissions = $this->Aros->find()->contain(['Acos'])->where(['id IN' => Hash::extract($aro, '{n}.id')])->toArray();
     $permissions = Hash::extract($permissions, '{n}.acos');
     $permissions = Hash::combine($permissions, '{n}.{n}.name', '{n}.{n}');
     $permissions = Hash::sort($permissions, '{s}.name');
     //        $permissions = Hash::expand($permissions, '/');
     return $permissions;
 }