1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12
13 require_once realpath(JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php');
14
15 JFormHelper::loadFieldClass('GroupedList');
16
17 18 19 20 21
22 class extends JFormFieldGroupedList
23 {
24 25 26 27 28 29
30 public $type = 'Menu';
31
32 33 34 35 36 37 38 39
40 protected function getGroups()
41 {
42 $clientId = (string) $this->element['clientid'];
43 $accessType = (string) $this->element['accesstype'];
44 $showAll = (string) $this->element['showAll'] == 'true';
45
46 $db = JFactory::getDbo();
47 $query = $db->getQuery(true)
48 ->select($db->qn(array('id', 'menutype', 'title', 'client_id'), array('id', 'value', 'text', 'client_id')))
49 ->from($db->quoteName('#__menu_types'))
50 ->order('client_id, title');
51
52 if (strlen($clientId))
53 {
54 $query->where('client_id = ' . (int) $clientId);
55 }
56
57 $menus = $db->setQuery($query)->loadObjectList();
58
59 if ($accessType)
60 {
61 $user = JFactory::getUser();
62
63 foreach ($menus as $key => $menu)
64 {
65 switch ($accessType)
66 {
67 case 'create':
68 case 'manage':
69 if (!$user->authorise('core.' . $accessType, 'com_menus.menu.' . (int) $menu->id))
70 {
71 unset($menus[$key]);
72 }
73 break;
74
75
76 case 'edit':
77 $check = $this->value == $menu->value ? 'edit' : 'create';
78
79 if (!$user->authorise('core.' . $check, 'com_menus.menu.' . (int) $menu->id))
80 {
81 unset($menus[$key]);
82 }
83 break;
84 }
85 }
86 }
87
88 $opts = array();
89
90
91 if ($clientId == 1 && $showAll)
92 {
93 $opts[] = (object) array(
94 'value' => 'main',
95 'text' => JText::_('COM_MENUS_MENU_TYPE_PROTECTED_MAIN_LABEL'),
96 'client_id' => 1,
97 );
98 }
99
100 $options = array_merge($opts, $menus);
101 $groups = array();
102
103 if (strlen($clientId))
104 {
105 $groups[0] = $options;
106 }
107 else
108 {
109 foreach ($options as $option)
110 {
111
112 $label = ($option->client_id == 1 ? JText::_('JADMINISTRATOR') : JText::_('JSITE'));
113
114 $groups[$label][] = $option;
115 }
116 }
117
118
119 return array_merge(parent::getGroups(), $groups);
120 }
121 }
122