Exemplo n.º 1
0
 /**
  * Method to get the field option groups.
  *
  * @return  array  The field option objects as a nested array in groups.
  *
  * @since   1.6
  */
 protected function getGroups()
 {
     $this->filterAttribute = (string) $this->element['filter_attribute'];
     $this->filterValue = (string) $this->element['filter_value'];
     $groups = parent::getGroups();
     if ($this->filterAttribute && $this->filterValue) {
         $application = JApplication::getInstance('site');
         $menu = $application->getMenu();
         $items = $menu->getItems($this->filterAttribute, $this->filterValue);
         $enabled = array('', '0');
         foreach ($items as $item) {
             $enabled[] = $item->id;
         }
         foreach ($groups as $options) {
             foreach ($options as $option) {
                 if (!in_array($option->value, $enabled)) {
                     $option->disable = true;
                 }
             }
         }
     }
     return $groups;
 }
Exemplo n.º 2
0
 protected function getGroups()
 {
     static $comp_items = array();
     $menuType = $this->menuType;
     $component = empty($this->element['component']) ? false : (string) $this->element['component'];
     $link_filters = empty($this->element['link_filters']) ? false : explode('%%', (string) $this->element['link_filters']);
     // Get the menu items.
     if (!$menuType && $component && isset($comp_items[$component])) {
         $items =& $comp_items[$component];
     } else {
         //$items = MenusHelper::getMenuLinks($menuType, 0, 0, $this->published, $this->language);
         $items = $this->getMenuLinks($menuType, 0, 0, $this->published, $this->language);
         // Cache component menu items
         if (!$menuType && $component) {
             $filter_text = 'option=' . $component;
             $comp_items[$component] = array();
             foreach ($items as $menu) {
                 $_menu = new stdClass();
                 foreach ($menu as $prop_name => $prop_val) {
                     if (!is_object($prop_val) && !is_array($prop_val)) {
                         $_menu->{$prop_name} = $prop_val;
                     }
                 }
                 $_menu->links = array();
                 foreach ($menu->links as $link) {
                     if (strstr($link->url, $filter_text) === false) {
                         continue;
                     }
                     $_menu->links[] = clone $link;
                 }
                 $comp_items[$component][] = $_menu;
             }
             $items =& $comp_items[$component];
         }
     }
     // Build group for a specific menu type.
     $groups = array();
     if ($menuType) {
         // Initialize the group.
         $groups[$menuType] = array();
         // Build the options array.
         foreach ($items as $link) {
             $skip = 0;
             if ($link_filters && $this->value != $link->value) {
                 foreach ($link_filters as $filter_text) {
                     if ($filter_text[0] == '!') {
                         if (strstr($link->url, substr($filter_text, 1)) !== false) {
                             $skip = 1;
                             break;
                         }
                     } else {
                         if (strstr($link->url, $filter_text) === false) {
                             $skip = 1;
                             break;
                         }
                     }
                 }
             }
             if ($skip) {
                 continue;
             }
             $levelPrefix = str_repeat('- ', max(0, $link->level - 1));
             $groups[$menuType][] = JHtml::_('select.option', $link->value, $levelPrefix . $link->text, 'value', 'text', in_array($link->type, $this->disable));
         }
     } else {
         // Build the groups arrays.
         foreach ($items as $menu) {
             // Initialize the group.
             $groups[$menu->menutype] = array();
             // Build the options array.
             foreach ($menu->links as $link) {
                 $skip = 0;
                 if ($link_filters && $this->value != $link->value) {
                     foreach ($link_filters as $filter_text) {
                         if ($filter_text[0] == '!') {
                             if (strstr($link->url, substr($filter_text, 1)) !== false) {
                                 $skip = 1;
                                 break;
                             }
                         } else {
                             if (strstr($link->url, $filter_text) === false) {
                                 $skip = 1;
                                 break;
                             }
                         }
                     }
                 }
                 if ($skip) {
                     continue;
                 }
                 $levelPrefix = str_repeat('- ', $link->level - 1);
                 $groups[$menu->menutype][] = JHtml::_('select.option', $link->value, $levelPrefix . $link->text, 'value', 'text', in_array($link->type, $this->disable));
             }
         }
     }
     // Merge any additional groups in the XML definition.
     $groups = array_merge(parent::getGroups(), $groups);
     return $groups;
 }