Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation { | |
34 | ||
73538697 CW |
35 | // Number of characters in the menu js cache key |
36 | const CACHE_KEY_STRLEN = 8; | |
37 | ||
6a488035 | 38 | /** |
fe482240 | 39 | * Class constructor. |
6a488035 | 40 | */ |
00be9182 | 41 | public function __construct() { |
6a488035 TO |
42 | parent::__construct(); |
43 | } | |
44 | ||
45 | /** | |
fe482240 | 46 | * Update the is_active flag in the db. |
6a488035 | 47 | * |
6a0b768e TO |
48 | * @param int $id |
49 | * Id of the database record. | |
50 | * @param bool $is_active | |
51 | * Value we want to set the is_active field. | |
6a488035 | 52 | * |
8a4fede3 | 53 | * @return bool |
54 | * true if we found and updated the object, else false | |
6a488035 | 55 | */ |
00be9182 | 56 | public static function setIsActive($id, $is_active) { |
6a488035 TO |
57 | return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_Navigation', $id, 'is_active', $is_active); |
58 | } | |
59 | ||
6a488035 | 60 | /** |
ffbff132 | 61 | * Add/update navigation record. |
6a488035 | 62 | * |
ffbff132 | 63 | * @param array $params Submitted values |
6a488035 | 64 | * |
ffbff132 | 65 | * @return CRM_Core_DAO_Navigation |
a6c01b45 | 66 | * navigation object |
6a488035 | 67 | */ |
00be9182 | 68 | public static function add(&$params) { |
6a488035 | 69 | $navigation = new CRM_Core_DAO_Navigation(); |
3523b615 | 70 | if (empty($params['id'])) { |
71 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); | |
72 | $params['has_separator'] = CRM_Utils_Array::value('has_separator', $params, FALSE); | |
7a487c63 | 73 | $params['domain_id'] = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID()); |
3523b615 | 74 | } |
6a488035 TO |
75 | |
76 | if (!isset($params['id']) || | |
481a74f4 | 77 | (CRM_Utils_Array::value('parent_id', $params) != CRM_Utils_Array::value('current_parent_id', $params)) |
6a488035 TO |
78 | ) { |
79 | /* re/calculate the weight, if the Parent ID changed OR create new menu */ | |
80 | ||
81 | if ($navName = CRM_Utils_Array::value('name', $params)) { | |
82 | $params['name'] = $navName; | |
83 | } | |
c5e077b2 PJ |
84 | elseif ($navLabel = CRM_Utils_Array::value('label', $params)) { |
85 | $params['name'] = $navLabel; | |
6a488035 TO |
86 | } |
87 | ||
88 | $params['weight'] = self::calculateWeight(CRM_Utils_Array::value('parent_id', $params)); | |
89 | } | |
90 | ||
c5e077b2 | 91 | if (array_key_exists('permission', $params) && is_array($params['permission'])) { |
6a488035 TO |
92 | $params['permission'] = implode(',', $params['permission']); |
93 | } | |
94 | ||
95 | $navigation->copyValues($params); | |
96 | ||
6a488035 TO |
97 | $navigation->save(); |
98 | return $navigation; | |
99 | } | |
100 | ||
101 | /** | |
fe482240 | 102 | * Fetch object based on array of properties. |
6a488035 | 103 | * |
6a0b768e TO |
104 | * @param array $params |
105 | * (reference ) an assoc array of name/value pairs. | |
106 | * @param array $defaults | |
107 | * (reference ) an assoc array to hold the flattened values. | |
6a488035 | 108 | * |
16b10e64 CW |
109 | * @return CRM_Core_BAO_Navigation|null |
110 | * object on success, NULL otherwise | |
6a488035 | 111 | */ |
00be9182 | 112 | public static function retrieve(&$params, &$defaults) { |
6a488035 TO |
113 | $navigation = new CRM_Core_DAO_Navigation(); |
114 | $navigation->copyValues($params); | |
115 | ||
116 | $navigation->domain_id = CRM_Core_Config::domainID(); | |
117 | ||
118 | if ($navigation->find(TRUE)) { | |
119 | CRM_Core_DAO::storeValues($navigation, $defaults); | |
120 | return $navigation; | |
121 | } | |
122 | return NULL; | |
123 | } | |
124 | ||
125 | /** | |
fe482240 | 126 | * Calculate navigation weight. |
6a488035 | 127 | * |
5a4f6742 | 128 | * @param int $parentID |
6a0b768e | 129 | * Parent_id of a menu. |
5a4f6742 | 130 | * @param int $menuID |
6a0b768e | 131 | * Menu id. |
6a488035 | 132 | * |
a6c01b45 CW |
133 | * @return int |
134 | * $weight string | |
6a488035 | 135 | */ |
00be9182 | 136 | public static function calculateWeight($parentID = NULL, $menuID = NULL) { |
6a488035 TO |
137 | $domainID = CRM_Core_Config::domainID(); |
138 | ||
139 | $weight = 1; | |
140 | // we reset weight for each parent, i.e we start from 1 to n | |
141 | // calculate max weight for top level menus, if parent id is absent | |
142 | if (!$parentID) { | |
143 | $query = "SELECT max(weight) as weight FROM civicrm_navigation WHERE parent_id IS NULL AND domain_id = $domainID"; | |
144 | } | |
145 | else { | |
146 | // if parent is passed, we need to get max weight for that particular parent | |
147 | $query = "SELECT max(weight) as weight FROM civicrm_navigation WHERE parent_id = {$parentID} AND domain_id = $domainID"; | |
148 | } | |
149 | ||
150 | $dao = CRM_Core_DAO::executeQuery($query); | |
151 | $dao->fetch(); | |
152 | return $weight = $weight + $dao->weight; | |
153 | } | |
154 | ||
155 | /** | |
fe482240 | 156 | * Get formatted menu list. |
6a488035 | 157 | * |
a6c01b45 CW |
158 | * @return array |
159 | * returns associated array | |
6a488035 | 160 | */ |
00be9182 | 161 | public static function getNavigationList() { |
6a488035 TO |
162 | $cacheKeyString = "navigationList"; |
163 | $whereClause = ''; | |
164 | ||
165 | $config = CRM_Core_Config::singleton(); | |
166 | ||
167 | // check if we can retrieve from database cache | |
168 | $navigations = CRM_Core_BAO_Cache::getItem('navigation', $cacheKeyString); | |
169 | ||
170 | if (!$navigations) { | |
171 | $domainID = CRM_Core_Config::domainID(); | |
172 | $query = " | |
173 | SELECT id, label, parent_id, weight, is_active, name | |
a8911fe3 | 174 | FROM civicrm_navigation WHERE domain_id = $domainID"; |
6a488035 TO |
175 | $result = CRM_Core_DAO::executeQuery($query); |
176 | ||
177 | $pidGroups = array(); | |
178 | while ($result->fetch()) { | |
179 | $pidGroups[$result->parent_id][$result->label] = $result->id; | |
180 | } | |
181 | ||
182 | foreach ($pidGroups[''] as $label => $val) { | |
183 | $pidGroups[''][$label] = self::_getNavigationValue($val, $pidGroups); | |
184 | } | |
185 | ||
186 | $navigations = array(); | |
187 | self::_getNavigationLabel($pidGroups[''], $navigations); | |
188 | ||
189 | CRM_Core_BAO_Cache::setItem($navigations, 'navigation', $cacheKeyString); | |
190 | } | |
191 | return $navigations; | |
192 | } | |
193 | ||
194 | /** | |
ffbff132 | 195 | * Helper function for getNavigationList(). |
6a488035 | 196 | * |
6a0b768e TO |
197 | * @param array $list |
198 | * Menu info. | |
199 | * @param array $navigations | |
200 | * Navigation menus. | |
201 | * @param string $separator | |
202 | * Menu separator. | |
6a488035 | 203 | */ |
00be9182 | 204 | public static function _getNavigationLabel($list, &$navigations, $separator = '') { |
6a488035 TO |
205 | $i18n = CRM_Core_I18n::singleton(); |
206 | foreach ($list as $label => $val) { | |
207 | if ($label == 'navigation_id') { | |
208 | continue; | |
209 | } | |
210 | $translatedLabel = $i18n->crm_translate($label, array('context' => 'menu')); | |
211 | $navigations[is_array($val) ? $val['navigation_id'] : $val] = "{$separator}{$translatedLabel}"; | |
212 | if (is_array($val)) { | |
213 | self::_getNavigationLabel($val, $navigations, $separator . ' '); | |
214 | } | |
215 | } | |
216 | } | |
217 | ||
218 | /** | |
ffbff132 | 219 | * Helper function for getNavigationList(). |
6a488035 | 220 | * |
6a0b768e TO |
221 | * @param string $val |
222 | * Menu name. | |
223 | * @param array $pidGroups | |
224 | * Parent menus. | |
ffbff132 | 225 | * |
6a488035 TO |
226 | * @return array |
227 | */ | |
00be9182 | 228 | public static function _getNavigationValue($val, &$pidGroups) { |
6a488035 TO |
229 | if (array_key_exists($val, $pidGroups)) { |
230 | $list = array('navigation_id' => $val); | |
231 | foreach ($pidGroups[$val] as $label => $id) { | |
232 | $list[$label] = self::_getNavigationValue($id, $pidGroups); | |
233 | } | |
234 | unset($pidGroups[$val]); | |
235 | return $list; | |
236 | } | |
237 | else { | |
238 | return $val; | |
239 | } | |
240 | } | |
241 | ||
242 | /** | |
fe482240 | 243 | * Build navigation tree. |
6a488035 | 244 | * |
a6c01b45 CW |
245 | * @return array |
246 | * nested array of menus | |
6a488035 | 247 | */ |
656e5c5b | 248 | public static function buildNavigationTree() { |
6a488035 | 249 | $domainID = CRM_Core_Config::domainID(); |
656e5c5b | 250 | $navigationTree = array(); |
6a488035 | 251 | |
c88f9a4d O |
252 | $navigationMenu = new self(); |
253 | $navigationMenu->domain_id = $domainID; | |
254 | $navigationMenu->orderBy('parent_id, weight'); | |
255 | $navigationMenu->find(); | |
256 | ||
257 | while ($navigationMenu->fetch()) { | |
258 | $navigationTree[$navigationMenu->id] = array( | |
6ea503d4 | 259 | 'attributes' => array( |
c88f9a4d O |
260 | 'label' => $navigationMenu->label, |
261 | 'name' => $navigationMenu->name, | |
262 | 'url' => $navigationMenu->url, | |
263 | 'icon' => $navigationMenu->icon, | |
9f51bd16 | 264 | 'weight' => $navigationMenu->weight, |
c88f9a4d O |
265 | 'permission' => $navigationMenu->permission, |
266 | 'operator' => $navigationMenu->permission_operator, | |
267 | 'separator' => $navigationMenu->has_separator, | |
268 | 'parentID' => $navigationMenu->parent_id, | |
269 | 'navID' => $navigationMenu->id, | |
270 | 'active' => $navigationMenu->is_active, | |
acb1052e | 271 | ), |
353ffa53 | 272 | ); |
6a488035 TO |
273 | } |
274 | ||
656e5c5b | 275 | return self::buildTree($navigationTree); |
6a488035 TO |
276 | } |
277 | ||
278 | /** | |
656e5c5b | 279 | * Convert flat array to nested. |
6a488035 | 280 | * |
656e5c5b CW |
281 | * @param array $elements |
282 | * @param int|null $parentId | |
283 | * | |
284 | * @return array | |
285 | */ | |
286 | private static function buildTree($elements, $parentId = NULL) { | |
287 | $branch = array(); | |
288 | ||
289 | foreach ($elements as $id => $element) { | |
290 | if ($element['attributes']['parentID'] == $parentId) { | |
291 | $children = self::buildTree($elements, $id); | |
292 | if ($children) { | |
293 | $element['child'] = $children; | |
294 | } | |
295 | $branch[$id] = $element; | |
296 | } | |
297 | } | |
298 | ||
299 | return $branch; | |
300 | } | |
301 | ||
302 | /** | |
303 | * Build menu. | |
6a488035 | 304 | * |
72b3a70c | 305 | * @return string |
6a488035 | 306 | */ |
656e5c5b CW |
307 | public static function buildNavigation() { |
308 | $navigations = self::buildNavigationTree(); | |
309 | $navigationString = ''; | |
6a488035 TO |
310 | |
311 | // run the Navigation through a hook so users can modify it | |
312 | CRM_Utils_Hook::navigationMenu($navigations); | |
b774b065 | 313 | self::fixNavigationMenu($navigations); |
6a488035 | 314 | |
9f51bd16 MM |
315 | // Hooks have added menu items in an arbitrary order. We need to order by |
316 | // weight again. I would put this function directly after | |
317 | // CRM_Utils_Hook::navigationMenu but for some reason, fixNavigationMenu is | |
318 | // moving items added by hooks on the end of the menu. Hence I do it | |
319 | // afterwards | |
320 | self::orderByWeight($navigations); | |
321 | ||
6a488035 TO |
322 | //skip children menu item if user don't have access to parent menu item |
323 | $skipMenuItems = array(); | |
324 | foreach ($navigations as $key => $value) { | |
656e5c5b CW |
325 | // Home is a special case |
326 | if ($value['attributes']['name'] != 'Home') { | |
327 | $name = self::getMenuName($value, $skipMenuItems); | |
328 | if ($name) { | |
329 | //separator before | |
330 | if (isset($value['attributes']['separator']) && $value['attributes']['separator'] == 2) { | |
331 | $navigationString .= '<li class="menu-separator"></li>'; | |
6a488035 | 332 | } |
656e5c5b CW |
333 | $removeCharacters = array('/', '!', '&', '*', ' ', '(', ')', '.'); |
334 | $navigationString .= '<li class="menumain crm-' . str_replace($removeCharacters, '_', $value['attributes']['label']) . '">' . $name; | |
6a488035 TO |
335 | } |
336 | } | |
656e5c5b | 337 | self::recurseNavigation($value, $navigationString, $skipMenuItems); |
6a488035 TO |
338 | } |
339 | ||
656e5c5b CW |
340 | // clean up - Need to remove empty <ul>'s, this happens when user don't have |
341 | // permission to access parent | |
342 | $navigationString = str_replace('<ul></ul></li>', '', $navigationString); | |
6a488035 TO |
343 | |
344 | return $navigationString; | |
345 | } | |
346 | ||
9f51bd16 MM |
347 | /** |
348 | * buildNavigationTree retreives items in order. We call this function to | |
349 | * ensure that any items added by the hook are also in the correct order. | |
350 | */ | |
c7e39a79 | 351 | public static function orderByWeight(&$navigations) { |
9f51bd16 MM |
352 | // sort each item in navigations by weight |
353 | usort($navigations, function($a, $b) { | |
354 | ||
355 | // If no weight have been defined for an item put it at the end of the list | |
356 | if (!isset($a['attributes']['weight'])) { | |
357 | $a['attributes']['weight'] = 1000; | |
358 | } | |
359 | if (!isset($b['attributes']['weight'])) { | |
360 | $b['attributes']['weight'] = 1000; | |
361 | } | |
362 | return $a['attributes']['weight'] - $b['attributes']['weight']; | |
363 | }); | |
364 | ||
365 | // If any of the $navigations have children, recurse | |
366 | foreach ($navigations as $navigation) { | |
367 | if (isset($navigation['child'])) { | |
368 | self::orderByWeight($navigation['child']); | |
369 | } | |
370 | } | |
371 | } | |
372 | ||
6a488035 | 373 | /** |
fe482240 | 374 | * Recursively check child menus. |
6a488035 TO |
375 | * |
376 | * @param array $value | |
377 | * @param string $navigationString | |
656e5c5b | 378 | * @param array $skipMenuItems |
ffbff132 | 379 | * |
6a488035 TO |
380 | * @return string |
381 | */ | |
656e5c5b CW |
382 | public static function recurseNavigation(&$value, &$navigationString, $skipMenuItems) { |
383 | if (!empty($value['child'])) { | |
384 | $navigationString .= '<ul>'; | |
6a488035 TO |
385 | } |
386 | else { | |
656e5c5b CW |
387 | $navigationString .= '</li>'; |
388 | //locate separator after | |
389 | if (isset($value['attributes']['separator']) && $value['attributes']['separator'] == 1) { | |
390 | $navigationString .= '<li class="menu-separator"></li>'; | |
6a488035 | 391 | } |
656e5c5b | 392 | } |
6a488035 | 393 | |
656e5c5b CW |
394 | if (!empty($value['child'])) { |
395 | foreach ($value['child'] as $val) { | |
396 | $name = self::getMenuName($val, $skipMenuItems); | |
397 | if ($name) { | |
398 | //locate separator before | |
399 | if (isset($val['attributes']['separator']) && $val['attributes']['separator'] == 2) { | |
400 | $navigationString .= '<li class="menu-separator"></li>'; | |
6a488035 | 401 | } |
656e5c5b CW |
402 | $removeCharacters = array('/', '!', '&', '*', ' ', '(', ')', '.'); |
403 | $navigationString .= '<li class="crm-' . str_replace($removeCharacters, '_', $val['attributes']['label']) . '">' . $name; | |
404 | self::recurseNavigation($val, $navigationString, $skipMenuItems); | |
6a488035 TO |
405 | } |
406 | } | |
656e5c5b CW |
407 | } |
408 | if (!empty($value['child'])) { | |
409 | $navigationString .= '</ul></li>'; | |
410 | if (isset($value['attributes']['separator']) && $value['attributes']['separator'] == 1) { | |
411 | $navigationString .= '<li class="menu-separator"></li>'; | |
6a488035 TO |
412 | } |
413 | } | |
414 | return $navigationString; | |
415 | } | |
416 | ||
b774b065 TO |
417 | /** |
418 | * Given a navigation menu, generate navIDs for any items which are | |
419 | * missing them. | |
420 | * | |
421 | * @param array $nodes | |
422 | * Each key is a numeral; each value is a node in | |
423 | * the menu tree (with keys "child" and "attributes"). | |
424 | */ | |
425 | public static function fixNavigationMenu(&$nodes) { | |
426 | $maxNavID = 1; | |
427 | array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) { | |
428 | if ($key === 'navID') { | |
429 | $maxNavID = max($maxNavID, $item); | |
430 | } | |
431 | }); | |
432 | self::_fixNavigationMenu($nodes, $maxNavID, NULL); | |
433 | } | |
434 | ||
435 | /** | |
436 | * @param array $nodes | |
437 | * Each key is a numeral; each value is a node in | |
438 | * the menu tree (with keys "child" and "attributes"). | |
ea3ddccf | 439 | * @param int $maxNavID |
440 | * @param int $parentID | |
b774b065 TO |
441 | */ |
442 | private static function _fixNavigationMenu(&$nodes, &$maxNavID, $parentID) { | |
443 | $origKeys = array_keys($nodes); | |
444 | foreach ($origKeys as $origKey) { | |
445 | if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) { | |
446 | $nodes[$origKey]['attributes']['parentID'] = $parentID; | |
447 | } | |
448 | // If no navID, then assign navID and fix key. | |
449 | if (!isset($nodes[$origKey]['attributes']['navID'])) { | |
450 | $newKey = ++$maxNavID; | |
451 | $nodes[$origKey]['attributes']['navID'] = $newKey; | |
f5d3c41c JM |
452 | if ($origKey != $newKey) { |
453 | // If the keys are different, reset the array index to match. | |
454 | $nodes[$newKey] = $nodes[$origKey]; | |
455 | unset($nodes[$origKey]); | |
456 | $origKey = $newKey; | |
457 | } | |
b774b065 TO |
458 | } |
459 | if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) { | |
460 | self::_fixNavigationMenu($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']); | |
461 | } | |
462 | } | |
463 | } | |
464 | ||
6a488035 | 465 | /** |
c7e39a79 | 466 | * Check permissions and format menu item as html. |
6a488035 TO |
467 | * |
468 | * @param $value | |
100fef9d | 469 | * @param array $skipMenuItems |
ffbff132 | 470 | * |
6a488035 TO |
471 | * @return bool|string |
472 | */ | |
00be9182 | 473 | public static function getMenuName(&$value, &$skipMenuItems) { |
6a488035 TO |
474 | // we need to localise the menu labels (CRM-5456) and don’t |
475 | // want to use ts() as it would throw the ts-extractor off | |
476 | $i18n = CRM_Core_I18n::singleton(); | |
477 | ||
353ffa53 | 478 | $name = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu')); |
29c4b4bf | 479 | $url = CRM_Utils_Array::value('url', $value['attributes']); |
29c4b4bf WA |
480 | $parentID = CRM_Utils_Array::value('parentID', $value['attributes']); |
481 | $navID = CRM_Utils_Array::value('navID', $value['attributes']); | |
482 | $active = CRM_Utils_Array::value('active', $value['attributes']); | |
353ffa53 | 483 | $target = CRM_Utils_Array::value('target', $value['attributes']); |
6a488035 | 484 | |
c7e39a79 | 485 | if (in_array($parentID, $skipMenuItems) || !$active || !self::checkPermission($value['attributes'])) { |
6a488035 TO |
486 | $skipMenuItems[] = $navID; |
487 | return FALSE; | |
488 | } | |
489 | ||
6a488035 | 490 | $makeLink = FALSE; |
45d70ef5 | 491 | if (!empty($url)) { |
0f1c7462 | 492 | $url = self::makeFullyFormedUrl($url); |
6a488035 TO |
493 | $makeLink = TRUE; |
494 | } | |
495 | ||
c7e39a79 CW |
496 | if (!empty($value['attributes']['icon'])) { |
497 | $menuIcon = sprintf('<i class="%s"></i>', $value['attributes']['icon']); | |
498 | $name = $menuIcon . $name; | |
6a488035 TO |
499 | } |
500 | ||
c7e39a79 CW |
501 | if ($makeLink) { |
502 | $url = CRM_Utils_System::evalUrl($url); | |
503 | if ($target) { | |
504 | $name = "<a href=\"{$url}\" target=\"{$target}\">{$name}</a>"; | |
505 | } | |
506 | else { | |
507 | $name = "<a href=\"{$url}\">{$name}</a>"; | |
508 | } | |
509 | } | |
6a488035 | 510 | |
c7e39a79 CW |
511 | return $name; |
512 | } | |
513 | ||
514 | /** | |
515 | * Check if a menu item should be visible based on permissions and component. | |
516 | * | |
517 | * @param $item | |
518 | * @return bool | |
519 | */ | |
520 | public static function checkPermission($item) { | |
521 | if (!empty($item['permission'])) { | |
522 | $permissions = explode(',', $item['permission']); | |
523 | $operator = CRM_Utils_Array::value('operator', $item); | |
6a488035 TO |
524 | $hasPermission = FALSE; |
525 | foreach ($permissions as $key) { | |
526 | $key = trim($key); | |
527 | $showItem = TRUE; | |
528 | ||
529 | //get the component name from permission. | |
530 | $componentName = CRM_Core_Permission::getComponentName($key); | |
531 | ||
532 | if ($componentName) { | |
c7e39a79 | 533 | if (!in_array($componentName, CRM_Core_Config::singleton()->enableComponents) || |
6a488035 TO |
534 | !CRM_Core_Permission::check($key) |
535 | ) { | |
536 | $showItem = FALSE; | |
537 | if ($operator == 'AND') { | |
c7e39a79 | 538 | return FALSE; |
6a488035 TO |
539 | } |
540 | } | |
541 | else { | |
542 | $hasPermission = TRUE; | |
543 | } | |
544 | } | |
545 | elseif (!CRM_Core_Permission::check($key)) { | |
546 | $showItem = FALSE; | |
547 | if ($operator == 'AND') { | |
c7e39a79 | 548 | return FALSE; |
6a488035 TO |
549 | } |
550 | } | |
551 | else { | |
552 | $hasPermission = TRUE; | |
553 | } | |
554 | } | |
555 | ||
c7e39a79 | 556 | if (empty($showItem) && !$hasPermission) { |
6a488035 TO |
557 | return FALSE; |
558 | } | |
559 | } | |
c7e39a79 | 560 | return TRUE; |
6a488035 TO |
561 | } |
562 | ||
563 | /** | |
fe482240 | 564 | * Create navigation for CiviCRM Admin Menu. |
6a488035 | 565 | * |
a6c01b45 CW |
566 | * @return string |
567 | * returns navigation html | |
6a488035 | 568 | */ |
2e42cb18 | 569 | public static function createNavigation() { |
73538697 | 570 | $navigation = self::buildNavigation(); |
6a488035 | 571 | |
73538697 | 572 | if ($navigation) { |
6a488035 TO |
573 | |
574 | //add additional navigation items | |
575 | $logoutURL = CRM_Utils_System::url('civicrm/logout', 'reset=1'); | |
6a488035 TO |
576 | |
577 | // get home menu from db | |
578 | $homeParams = array('name' => 'Home'); | |
579 | $homeNav = array(); | |
a2e1885c | 580 | $homeIcon = '<span class="crm-logo-sm" ></span>'; |
6a488035 TO |
581 | self::retrieve($homeParams, $homeNav); |
582 | if ($homeNav) { | |
0f1c7462 | 583 | $homeURL = self::makeFullyFormedUrl($homeNav['url']); |
6a488035 TO |
584 | $homeLabel = $homeNav['label']; |
585 | // CRM-6804 (we need to special-case this as we don’t ts()-tag variables) | |
586 | if ($homeLabel == 'Home') { | |
a65693e5 | 587 | $homeLabel = ts('CiviCRM Home'); |
6a488035 TO |
588 | } |
589 | } | |
590 | else { | |
591 | $homeURL = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
a65693e5 | 592 | $homeLabel = ts('CiviCRM Home'); |
6a488035 | 593 | } |
8960d9b9 | 594 | // Link to hide the menubar |
8b571e4c | 595 | $hideLabel = ts('Hide Menu'); |
6a488035 | 596 | |
8960d9b9 CW |
597 | $prepandString = " |
598 | <li class='menumain crm-link-home'>$homeIcon | |
599 | <ul id='civicrm-home'> | |
600 | <li><a href='$homeURL'>$homeLabel</a></li> | |
601 | <li><a href='#' class='crm-hidemenu'>$hideLabel</a></li> | |
86bfa4f6 | 602 | <li><a href='$logoutURL' class='crm-logout-link'>" . ts('Log out') . "</a></li> |
8960d9b9 CW |
603 | </ul>"; |
604 | // <li> tag doesn't need to be closed | |
73538697 | 605 | } |
8960d9b9 | 606 | return $prepandString . $navigation; |
73538697 | 607 | } |
6a488035 | 608 | |
0f1c7462 DA |
609 | /** |
610 | * Turns relative URLs (like civicrm/foo/bar) into fully-formed | |
611 | * ones (i.e. example.com/wp-admin?q=civicrm/dashboard). | |
612 | * | |
613 | * If the URL is already fully-formed, nothing will be done. | |
614 | * | |
615 | * @param string $url | |
616 | * | |
617 | * @return string | |
618 | */ | |
c7e39a79 | 619 | public static function makeFullyFormedUrl($url) { |
0f1c7462 DA |
620 | if (self::isNotFullyFormedUrl($url)) { |
621 | //CRM-7656 --make sure to separate out url path from url params, | |
622 | //as we'r going to validate url path across cross-site scripting. | |
623 | $path = parse_url($url, PHP_URL_PATH); | |
624 | $q = parse_url($url, PHP_URL_QUERY); | |
625 | $fragment = parse_url($url, PHP_URL_FRAGMENT); | |
626 | return CRM_Utils_System::url($path, $q, FALSE, $fragment); | |
627 | } | |
628 | ||
629 | if (strpos($url, '&') === FALSE) { | |
630 | return htmlspecialchars($url); | |
631 | } | |
632 | ||
633 | return $url; | |
634 | } | |
635 | ||
636 | /** | |
637 | * Checks if the given URL is not fully-formed | |
638 | * | |
639 | * @param string $url | |
640 | * | |
641 | * @return bool | |
642 | */ | |
643 | private static function isNotFullyFormedUrl($url) { | |
644 | return substr($url, 0, 4) !== 'http' && $url[0] !== '/' && $url[0] !== '#'; | |
645 | } | |
646 | ||
73538697 | 647 | /** |
fe482240 | 648 | * Reset navigation for all contacts or a specified contact. |
73538697 | 649 | * |
6a0b768e TO |
650 | * @param int $contactID |
651 | * Reset only entries belonging to that contact ID. | |
ffbff132 | 652 | * |
73538697 CW |
653 | * @return string |
654 | */ | |
00be9182 | 655 | public static function resetNavigation($contactID = NULL) { |
73538697 CW |
656 | $newKey = CRM_Utils_String::createRandom(self::CACHE_KEY_STRLEN, CRM_Utils_String::ALPHANUMERIC); |
657 | if (!$contactID) { | |
290110ef TO |
658 | $ser = serialize($newKey); |
659 | $query = "UPDATE civicrm_setting SET value = '$ser' WHERE name='navigation' AND contact_id IS NOT NULL"; | |
73538697 CW |
660 | CRM_Core_DAO::executeQuery($query); |
661 | CRM_Core_BAO_Cache::deleteGroup('navigation'); | |
662 | } | |
663 | else { | |
6a488035 | 664 | // before inserting check if contact id exists in db |
73538697 | 665 | // this is to handle weird case when contact id is in session but not in db |
6a488035 TO |
666 | $contact = new CRM_Contact_DAO_Contact(); |
667 | $contact->id = $contactID; | |
668 | if ($contact->find(TRUE)) { | |
669 | CRM_Core_BAO_Setting::setItem( | |
73538697 | 670 | $newKey, |
6a488035 TO |
671 | CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, |
672 | 'navigation', | |
673 | NULL, | |
674 | $contactID, | |
675 | $contactID | |
676 | ); | |
677 | } | |
678 | } | |
73538697 CW |
679 | |
680 | return $newKey; | |
6a488035 TO |
681 | } |
682 | ||
683 | /** | |
fe482240 | 684 | * Process navigation. |
6a488035 | 685 | * |
6a0b768e TO |
686 | * @param array $params |
687 | * Associated array, $_GET. | |
6a488035 | 688 | */ |
00be9182 | 689 | public static function processNavigation(&$params) { |
353ffa53 TO |
690 | $nodeID = (int) str_replace("node_", "", $params['id']); |
691 | $referenceID = (int) str_replace("node_", "", $params['ref_id']); | |
692 | $position = $params['ps']; | |
693 | $type = $params['type']; | |
694 | $label = CRM_Utils_Array::value('data', $params); | |
6a488035 TO |
695 | |
696 | switch ($type) { | |
697 | case "move": | |
698 | self::processMove($nodeID, $referenceID, $position); | |
699 | break; | |
700 | ||
701 | case "rename": | |
702 | self::processRename($nodeID, $label); | |
703 | break; | |
704 | ||
705 | case "delete": | |
706 | self::processDelete($nodeID); | |
707 | break; | |
708 | } | |
709 | ||
710 | //reset navigation menus | |
711 | self::resetNavigation(); | |
712 | CRM_Utils_System::civiExit(); | |
713 | } | |
714 | ||
715 | /** | |
fe482240 | 716 | * Process move action. |
6a488035 | 717 | * |
6a0b768e TO |
718 | * @param $nodeID |
719 | * Node that is being moved. | |
720 | * @param $referenceID | |
721 | * Parent id where node is moved. 0 mean no parent. | |
722 | * @param $position | |
723 | * New position of the nod, it starts with 0 - n. | |
6a488035 | 724 | */ |
00be9182 | 725 | public static function processMove($nodeID, $referenceID, $position) { |
6a488035 TO |
726 | // based on the new position we need to get the weight of the node after moved node |
727 | // 1. update the weight of $position + 1 nodes to weight + 1 | |
728 | // 2. weight of the ( $position -1 ) node - 1 is the new weight of the node being moved | |
729 | ||
730 | // check if there is parent id, which means node is moved inside existing parent container, so use parent id | |
731 | // to find the correct position else use NULL to get the weights of parent ( $position - 1 ) | |
732 | // accordingly set the new parent_id | |
733 | if ($referenceID) { | |
734 | $newParentID = $referenceID; | |
735 | $parentClause = "parent_id = {$referenceID} "; | |
736 | } | |
737 | else { | |
738 | $newParentID = 'NULL'; | |
739 | $parentClause = 'parent_id IS NULL'; | |
740 | } | |
741 | ||
4eeb9a5b | 742 | $incrementOtherNodes = TRUE; |
353ffa53 | 743 | $sql = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1"; |
481a74f4 | 744 | $params = array(1 => array($position, 'Positive')); |
6a488035 TO |
745 | $newWeight = CRM_Core_DAO::singleValueQuery($sql, $params); |
746 | ||
747 | // this means node is moved to last position, so you need to get the weight of last element + 1 | |
748 | if (!$newWeight) { | |
7cc5305f CW |
749 | // If this is not the first item being added to a parent |
750 | if ($position) { | |
751 | $lastPosition = $position - 1; | |
752 | $sql = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1"; | |
753 | $params = array(1 => array($lastPosition, 'Positive')); | |
754 | $newWeight = CRM_Core_DAO::singleValueQuery($sql, $params); | |
755 | ||
756 | // since last node increment + 1 | |
757 | $newWeight = $newWeight + 1; | |
758 | } | |
759 | else { | |
760 | $newWeight = '0'; | |
761 | } | |
6a488035 TO |
762 | |
763 | // since this is a last node we don't need to increment other nodes | |
ab8a593e | 764 | $incrementOtherNodes = FALSE; |
6a488035 TO |
765 | } |
766 | ||
767 | $transaction = new CRM_Core_Transaction(); | |
768 | ||
769 | // now update the existing nodes to weight + 1, if required. | |
481a74f4 | 770 | if ($incrementOtherNodes) { |
6a488035 TO |
771 | $query = "UPDATE civicrm_navigation SET weight = weight + 1 |
772 | WHERE {$parentClause} AND weight >= {$newWeight}"; | |
773 | ||
774 | CRM_Core_DAO::executeQuery($query); | |
775 | } | |
776 | ||
777 | // finally set the weight of current node | |
778 | $query = "UPDATE civicrm_navigation SET weight = {$newWeight}, parent_id = {$newParentID} WHERE id = {$nodeID}"; | |
779 | CRM_Core_DAO::executeQuery($query); | |
780 | ||
781 | $transaction->commit(); | |
782 | } | |
783 | ||
784 | /** | |
ffbff132 | 785 | * Function to process rename action for tree. |
6a488035 | 786 | * |
100fef9d | 787 | * @param int $nodeID |
6a488035 TO |
788 | * @param $label |
789 | */ | |
00be9182 | 790 | public static function processRename($nodeID, $label) { |
6a488035 TO |
791 | CRM_Core_DAO::setFieldValue('CRM_Core_DAO_Navigation', $nodeID, 'label', $label); |
792 | } | |
793 | ||
794 | /** | |
fe482240 | 795 | * Process delete action for tree. |
6a488035 | 796 | * |
100fef9d | 797 | * @param int $nodeID |
6a488035 | 798 | */ |
00be9182 | 799 | public static function processDelete($nodeID) { |
6a488035 TO |
800 | $query = "DELETE FROM civicrm_navigation WHERE id = {$nodeID}"; |
801 | CRM_Core_DAO::executeQuery($query); | |
802 | } | |
803 | ||
6a488035 | 804 | /** |
fe482240 | 805 | * Update menu. |
6a488035 | 806 | * |
6a0b768e TO |
807 | * @param array $params |
808 | * @param array $newParams | |
809 | * New value of params. | |
6a488035 | 810 | */ |
00be9182 | 811 | public static function processUpdate($params, $newParams) { |
6a488035 TO |
812 | $dao = new CRM_Core_DAO_Navigation(); |
813 | $dao->copyValues($params); | |
814 | if ($dao->find(TRUE)) { | |
815 | $dao->copyValues($newParams); | |
816 | $dao->save(); | |
817 | } | |
818 | } | |
73538697 | 819 | |
31cb1898 AN |
820 | /** |
821 | * Rebuild reports menu. | |
822 | * | |
823 | * All Contact reports will become sub-items of 'Contact Reports' and so on. | |
824 | * | |
825 | * @param int $domain_id | |
826 | */ | |
827 | public static function rebuildReportsNavigation($domain_id) { | |
828 | $component_to_nav_name = array( | |
829 | 'CiviContact' => 'Contact Reports', | |
830 | 'CiviContribute' => 'Contribution Reports', | |
831 | 'CiviMember' => 'Membership Reports', | |
832 | 'CiviEvent' => 'Event Reports', | |
833 | 'CiviPledge' => 'Pledge Reports', | |
834 | 'CiviGrant' => 'Grant Reports', | |
835 | 'CiviMail' => 'Mailing Reports', | |
836 | 'CiviCampaign' => 'Campaign Reports', | |
837 | ); | |
838 | ||
839 | // Create or update the top level Reports link. | |
840 | $reports_nav = self::createOrUpdateTopLevelReportsNavItem($domain_id); | |
841 | ||
842 | // Get all active report instances grouped by component. | |
843 | $components = self::getAllActiveReportsByComponent($domain_id); | |
844 | foreach ($components as $component_id => $component) { | |
845 | // Create or update the per component reports links. | |
846 | $component_nav_name = $component['name']; | |
847 | if (isset($component_to_nav_name[$component_nav_name])) { | |
848 | $component_nav_name = $component_to_nav_name[$component_nav_name]; | |
849 | } | |
850 | $permission = "access {$component['name']}"; | |
851 | if ($component['name'] === 'CiviContact') { | |
852 | $permission = "administer CiviCRM"; | |
853 | } | |
854 | elseif ($component['name'] === 'CiviCampaign') { | |
855 | $permission = "access CiviReport"; | |
856 | } | |
0087242f | 857 | $component_nav = self::createOrUpdateReportNavItem($component_nav_name, 'civicrm/report/list', |
858 | "compid={$component_id}&reset=1", $reports_nav->id, $permission, $domain_id, TRUE); | |
31cb1898 AN |
859 | foreach ($component['reports'] as $report_id => $report) { |
860 | // Create or update the report instance links. | |
51704c4d | 861 | $report_nav = self::createOrUpdateReportNavItem($report['title'], $report['url'], 'reset=1', $component_nav->id, $report['permission'], $domain_id, FALSE, TRUE); |
31cb1898 AN |
862 | // Update the report instance to include the navigation id. |
863 | $query = "UPDATE civicrm_report_instance SET navigation_id = %1 WHERE id = %2"; | |
864 | $params = array( | |
865 | 1 => array($report_nav->id, 'Integer'), | |
866 | 2 => array($report_id, 'Integer'), | |
867 | ); | |
868 | CRM_Core_DAO::executeQuery($query, $params); | |
869 | } | |
870 | } | |
871 | ||
872 | // Create or update the All Reports link. | |
dfbeefd8 | 873 | self::createOrUpdateReportNavItem('All Reports', 'civicrm/report/list', 'reset=1', $reports_nav->id, 'access CiviReport', $domain_id, TRUE); |
e24131b6 | 874 | // Create or update the My Reports link. |
875 | self::createOrUpdateReportNavItem('My Reports', 'civicrm/report/list', 'myreports=1&reset=1', $reports_nav->id, 'access CiviReport', $domain_id, TRUE); | |
876 | ||
31cb1898 AN |
877 | } |
878 | ||
879 | /** | |
880 | * Create the top level 'Reports' item in the navigation tree. | |
881 | * | |
882 | * @param int $domain_id | |
883 | * | |
884 | * @return bool|\CRM_Core_DAO | |
885 | */ | |
886 | static public function createOrUpdateTopLevelReportsNavItem($domain_id) { | |
887 | $id = NULL; | |
888 | ||
889 | $dao = new CRM_Core_BAO_Navigation(); | |
890 | $dao->name = 'Reports'; | |
891 | $dao->domain_id = $domain_id; | |
892 | // The first selectAdd clears it - so that we only retrieve the one field. | |
893 | $dao->selectAdd(); | |
894 | $dao->selectAdd('id'); | |
895 | if ($dao->find(TRUE)) { | |
896 | $id = $dao->id; | |
897 | } | |
898 | ||
899 | $nav = self::createReportNavItem('Reports', NULL, NULL, NULL, 'access CiviReport', $id, $domain_id); | |
900 | return $nav; | |
901 | } | |
902 | ||
903 | /** | |
904 | * Retrieve a navigation item using it's url. | |
905 | * | |
51704c4d | 906 | * Note that we use LIKE to permit a wildcard as the calling code likely doesn't |
907 | * care about output params appended. | |
908 | * | |
31cb1898 AN |
909 | * @param string $url |
910 | * @param array $url_params | |
911 | * | |
0087242f | 912 | * @param int|null $parent_id |
913 | * Optionally restrict to one parent. | |
914 | * | |
915 | * @return bool|\CRM_Core_BAO_Navigation | |
31cb1898 | 916 | */ |
0087242f | 917 | public static function getNavItemByUrl($url, $url_params, $parent_id = NULL) { |
918 | $nav = new CRM_Core_BAO_Navigation(); | |
0087242f | 919 | $nav->parent_id = $parent_id; |
51704c4d | 920 | $nav->whereAdd("url LIKE '{$url}?{$url_params}'"); |
921 | ||
0087242f | 922 | if ($nav->find(TRUE)) { |
923 | return $nav; | |
31cb1898 AN |
924 | } |
925 | return FALSE; | |
926 | } | |
927 | ||
928 | /** | |
929 | * Get all active reports, organised by component. | |
930 | * | |
931 | * @param int $domain_id | |
932 | * | |
933 | * @return array | |
934 | */ | |
935 | public static function getAllActiveReportsByComponent($domain_id) { | |
936 | $sql = " | |
937 | SELECT | |
938 | civicrm_report_instance.id, civicrm_report_instance.title, civicrm_report_instance.permission, civicrm_component.name, civicrm_component.id AS component_id | |
939 | FROM | |
940 | civicrm_option_group | |
941 | LEFT JOIN | |
942 | civicrm_option_value ON civicrm_option_value.option_group_id = civicrm_option_group.id AND civicrm_option_group.name = 'report_template' | |
943 | LEFT JOIN | |
944 | civicrm_report_instance ON civicrm_option_value.value = civicrm_report_instance.report_id | |
945 | LEFT JOIN | |
946 | civicrm_component ON civicrm_option_value.component_id = civicrm_component.id | |
947 | WHERE | |
948 | civicrm_option_value.is_active = 1 | |
949 | AND | |
950 | civicrm_report_instance.domain_id = %1 | |
951 | ORDER BY civicrm_option_value.weight"; | |
952 | ||
953 | $dao = CRM_Core_DAO::executeQuery($sql, array( | |
954 | 1 => array($domain_id, 'Integer'), | |
955 | )); | |
956 | $rows = array(); | |
957 | while ($dao->fetch()) { | |
958 | $component_name = is_null($dao->name) ? 'CiviContact' : $dao->name; | |
959 | $component_id = is_null($dao->component_id) ? 99 : $dao->component_id; | |
960 | $rows[$component_id]['name'] = $component_name; | |
961 | $rows[$component_id]['reports'][$dao->id] = array( | |
962 | 'title' => $dao->title, | |
963 | 'url' => "civicrm/report/instance/{$dao->id}", | |
964 | 'permission' => $dao->permission, | |
965 | ); | |
966 | } | |
967 | return $rows; | |
968 | } | |
969 | ||
970 | /** | |
971 | * Create or update a navigation item for a report instance. | |
972 | * | |
973 | * The function will check whether create or update is required. | |
974 | * | |
975 | * @param string $name | |
976 | * @param string $url | |
977 | * @param string $url_params | |
978 | * @param int $parent_id | |
979 | * @param string $permission | |
980 | * @param int $domain_id | |
981 | * | |
0087242f | 982 | * @param bool $onlyMatchParentID |
983 | * If True then do not match with a url that has a different parent | |
984 | * (This is because for top level items there is a risk of 'stealing' rows that normally | |
985 | * live under 'Contact' and intentionally duplicate the report examples.) | |
986 | * | |
31cb1898 AN |
987 | * @return \CRM_Core_DAO_Navigation |
988 | */ | |
0087242f | 989 | protected static function createOrUpdateReportNavItem($name, $url, $url_params, $parent_id, $permission, |
51704c4d | 990 | $domain_id, $onlyMatchParentID = FALSE, $useWildcard = TRUE) { |
31cb1898 | 991 | $id = NULL; |
51704c4d | 992 | $existing_url_params = $useWildcard ? $url_params . '%' : $url_params; |
993 | $existing_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, $existing_url_params, ($onlyMatchParentID ? $parent_id : NULL)); | |
31cb1898 AN |
994 | if ($existing_nav) { |
995 | $id = $existing_nav->id; | |
996 | } | |
0087242f | 997 | |
31cb1898 AN |
998 | $nav = self::createReportNavItem($name, $url, $url_params, $parent_id, $permission, $id, $domain_id); |
999 | return $nav; | |
1000 | } | |
1001 | ||
1002 | /** | |
1003 | * Create a navigation item for a report instance. | |
1004 | * | |
1005 | * @param string $name | |
1006 | * @param string $url | |
1007 | * @param string $url_params | |
1008 | * @param int $parent_id | |
1009 | * @param string $permission | |
1010 | * @param int $id | |
1011 | * @param int $domain_id | |
1012 | * ID of domain to create item in. | |
1013 | * | |
1014 | * @return \CRM_Core_DAO_Navigation | |
1015 | */ | |
1016 | public static function createReportNavItem($name, $url, $url_params, $parent_id, $permission, $id, $domain_id) { | |
1017 | if ($url !== NULL) { | |
1018 | $url = "{$url}?{$url_params}"; | |
1019 | } | |
1020 | $params = array( | |
1021 | 'name' => $name, | |
1022 | 'label' => ts($name), | |
1023 | 'url' => $url, | |
1024 | 'parent_id' => $parent_id, | |
1025 | 'is_active' => TRUE, | |
1026 | 'permission' => array( | |
1027 | $permission, | |
1028 | ), | |
1029 | 'domain_id' => $domain_id, | |
1030 | ); | |
0087242f | 1031 | if ($id) { |
31cb1898 AN |
1032 | $params['id'] = $id; |
1033 | } | |
0087242f | 1034 | return CRM_Core_BAO_Navigation::add($params); |
31cb1898 AN |
1035 | } |
1036 | ||
b5c2afd0 | 1037 | /** |
ffbff132 EM |
1038 | * Get cache key. |
1039 | * | |
100fef9d | 1040 | * @param int $cid |
b5c2afd0 EM |
1041 | * |
1042 | * @return object|string | |
1043 | */ | |
00be9182 | 1044 | public static function getCacheKey($cid) { |
aaffa79f | 1045 | $key = Civi::service('settings_manager') |
1046 | ->getBagByContact(NULL, $cid) | |
1047 | ->get('navigation'); | |
73538697 CW |
1048 | if (strlen($key) !== self::CACHE_KEY_STRLEN) { |
1049 | $key = self::resetNavigation($cid); | |
1050 | } | |
1051 | return $key; | |
1052 | } | |
96025800 | 1053 | |
6a488035 | 1054 | } |