@@ -16,9 +16,10 @@ class Navigation {
16
16
* Contains the closing tag e.g. </ul>
17
17
* @var $_item_open:
18
18
* Contains the open tag for a nav item e.g. <li>
19
- * @var $_item_open_active:
20
- * Contains the open tag for an active item e.g.
21
- * <li class="active">
19
+ * @var $_item_open_active_class:
20
+ * Contains the class for an active item e.g. "active"
21
+ * @var $_item_open_dropdown_class:
22
+ * Contains the class for an item which has subitems e.g. "dropdown"
22
23
* @var $_item_close:
23
24
* Contains the close tag for an item e.g. </li>
24
25
* @var $_anchor:
@@ -27,6 +28,8 @@ class Navigation {
27
28
* where $url is the link to the item,
28
29
* $extra is any additional attributes e.g. class="main"
29
30
* and $text is the text to be held in the anchor.
31
+ * @var $_anchor_dropdown:
32
+ * Different template for dropdown parent links.
30
33
* @var $_dropdown_open:
31
34
* Contains the open tag for a dropdown e.g. <ul class="dropdown">
32
35
* @var $_dropdown_close:
@@ -37,9 +40,11 @@ class Navigation {
37
40
private $ _navigation_open ;
38
41
private $ _navigation_close ;
39
42
private $ _item_open ;
40
- private $ _item_open_active ;
43
+ private $ _item_open_active_class ;
44
+ private $ _item_open_dropdown_class ;
41
45
private $ _item_close ;
42
46
private $ _anchor ;
47
+ private $ _anchor_dropdown ;
43
48
private $ _dropdown_open ;
44
49
private $ _dropdown_close ;
45
50
@@ -73,9 +78,11 @@ public function __construct($params = array('config' => 'navigation'))
73
78
$ this ->_navigation_open = $ this ->CI ->config ->item ('navigation_open ' ,$ params ['config ' ]);
74
79
$ this ->_navigation_close = $ this ->CI ->config ->item ('navigation_close ' ,$ params ['config ' ]);
75
80
$ this ->_item_open = $ this ->CI ->config ->item ('item_open ' ,$ params ['config ' ]);
76
- $ this ->_item_open_active = $ this ->CI ->config ->item ('item_open_active ' ,$ params ['config ' ]);
81
+ $ this ->_item_open_active_class = $ this ->CI ->config ->item ('item_open_active_class ' ,$ params ['config ' ]);
82
+ $ this ->_item_open_dropdown_class = $ this ->CI ->config ->item ('item_open_dropdown_class ' ,$ params ['config ' ]);
77
83
$ this ->_item_close = $ this ->CI ->config ->item ('item_close ' ,$ params ['config ' ]);
78
84
$ this ->_anchor = $ this ->CI ->config ->item ('anchor ' ,$ params ['config ' ]);
85
+ $ this ->_anchor_dropdown = $ this ->CI ->config ->item ('anchor_dropdown ' ,$ params ['config ' ]);
79
86
$ this ->_dropdown_open = $ this ->CI ->config ->item ('dropdown_open ' ,$ params ['config ' ]);
80
87
$ this ->_dropdown_close = $ this ->CI ->config ->item ('dropdown_close ' ,$ params ['config ' ]);
81
88
@@ -97,25 +104,34 @@ function isCurrentPage($url) {
97
104
*/
98
105
99
106
// Remove site url
100
- $ page_url = str_replace ($ this ->_current_url ,$ this ->_base_url ,'' );
101
- return strcmp ($ url ,$ page_url );
107
+ $ page_url = str_replace (rtrim ($ this ->_base_url ,"/ " ),"" ,$ this ->_current_url );
108
+ if (empty ($ page_url )){
109
+ $ page_url = "/ " ;
110
+ }
111
+ return strcmp ("/ " . $ url ,$ page_url ) == 0 ;
102
112
}
103
113
104
- function bindAnchor ($ url , $ text , $ extra = '' ) {
114
+ function bindAnchor ($ url , $ text , $ extra = '' , $ isDropdown = false ) {
105
115
/**
106
116
* Takes parameters for an anchor and binds them to template.
107
117
* @param url : url to put in href
108
118
* @param text : text to put between anchor
109
119
* @param OPTIONAL extra : extra attributes and data
120
+ * @param OPTIONAL isDropdown : boolean indicating if dropdown or not,
121
+ * changes url template.
110
122
*/
111
123
112
124
$ vars = array (
113
- '{$url} ' => $ url ,
125
+ '{$url} ' => $ this -> _base_url . $ url ,
114
126
'{$text} ' => $ text ,
115
127
'{$extra} ' => $ extra
116
128
);
117
129
118
- return strtr ($ this ->_anchor , $ vars );
130
+ if ($ isDropdown ) {
131
+ return strtr ($ this ->_anchor_dropdown ,$ vars );
132
+ } else {
133
+ return strtr ($ this ->_anchor , $ vars );
134
+ }
119
135
}
120
136
121
137
function outputItem ($ item ) {
@@ -127,20 +143,38 @@ function outputItem($item) {
127
143
128
144
$ output = '' ;
129
145
130
- if ($ this ->isCurrentPage ($ item ->ItemLink )) {
131
- $ output .= $ this ->_item_open_active ;
132
- } else {
133
- $ output .= $ this ->_item_open ;
134
- }
146
+ $ classes = '' ;
135
147
136
- // Output link
137
- $ output .= $ this ->bindAnchor ($ item ->ItemLink , $ item ->ItemHumanName );
148
+ $ output .= $ this ->_item_open ;
138
149
139
150
// Check for sub items.
140
151
$ subItems = $ this ->CI ->nav ->getSubItems ($ item ->ItemID );
141
152
142
- if (count ($ subItems ->result_array ()) > 0 ) {
143
- $ this ->renderDropdown ($ subItems );
153
+ if ($ this ->isCurrentPage ($ item ->ItemLink )) {
154
+ $ classes .= $ this ->_item_open_active_class . ' ' ;
155
+ }
156
+
157
+ if (!is_null ($ subItems ) && count ($ subItems ->result ()) > 0 ){
158
+ // See if we have dropdown
159
+ $ classes .= $ this ->_item_open_dropdown_class . ' ' ;
160
+ }
161
+
162
+ if (!strcmp ($ classes ,'' ) == 0 ) {
163
+ // If classes to add them append to open tag
164
+ $ output = str_replace ('> ' ,' class=" ' . $ classes . '"> ' ,$ output );
165
+ }
166
+
167
+ // Output link
168
+ if (!is_null ($ subItems ) && count ($ subItems ->result ()) > 0 ) {
169
+ $ output .= $ this ->bindAnchor ($ item ->ItemLink , $ item ->ItemHumanName , '' , $ this ->_anchor_dropdown );
170
+ } else {
171
+ $ output .= $ this ->bindAnchor ($ item ->ItemLink , $ item ->ItemHumanName );
172
+ }
173
+
174
+ if (!is_null ($ subItems )){
175
+ if (count ($ subItems ->result ()) > 0 ) {
176
+ $ output .= $ this ->renderDropdown ($ subItems );
177
+ }
144
178
}
145
179
146
180
$ output .= $ this ->_item_close ;
@@ -157,7 +191,7 @@ function renderDropdown($subItems) {
157
191
158
192
$ output = $ this ->_dropdown_open ;
159
193
160
- foreach ($ subItems ->result_array () as $ item ) {
194
+ foreach ($ subItems ->result () as $ item ) {
161
195
162
196
// Check if current page and open item
163
197
if ($ this ->isCurrentPage ($ item ->ItemLink )) {
@@ -202,21 +236,50 @@ public function generateNav_fromID($menu_id) {
202
236
203
237
$ top_level = $ this ->CI ->nav ->getTopLevelNav_byID ($ menu_id );
204
238
205
- // if ($top_level->num_rows( ) > 0)
206
- // {
239
+ if (count ( $ top_level ->result () ) > 0 )
240
+ {
207
241
foreach ($ top_level ->result () as $ item )
208
242
{
209
243
// Output each nav item
210
244
$ this ->_output .= $ this ->outputItem ($ item );
211
245
}
212
- // }
246
+ }
213
247
214
248
$ this ->_output .= $ this ->_navigation_close ;
215
249
216
250
return $ this ->_output ;
217
251
}
218
252
253
+ public function generateRoleBasedNav () {
254
+ /**
255
+ * Outputs navigation selectively based on user authentication
256
+ * @returns HTML markup for navigation
257
+ */
258
+
259
+ if (!$ this ->CI ->ion_auth ->logged_in ()){
260
+ return $ this ->generateNav_fromName ('public ' );
261
+ } else {
262
+ // Customer Group
263
+ if ($ this ->CI ->ion_auth ->in_group ('customer ' )){
264
+ return $ this ->generateNav_fromName ('customer ' );
265
+ }
266
+
267
+ // Business Group
268
+ if ($ this ->CI ->ion_auth ->in_group ('business ' )){
269
+ return $ this ->generateNav_fromName ('business ' );
270
+ }
271
+
272
+ // Introducer Group
273
+ if ($ this ->CI ->ion_auth ->in_group ('introducer ' )){
274
+ return $ this ->generateNav_fromName ('introducer ' );
275
+ }
219
276
277
+ // Admins
278
+ if ($ this ->CI ->ion_auth ->is_admin ()){
279
+ return $ this ->generateNav_fromName ('admin ' );
280
+ }
281
+ }
282
+ }
220
283
221
284
222
285
}
0 commit comments