modmenu.class.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. require_once (dirname(__DIR__) . '/modmenu.class.php');
  11. /**
  12. * @package modx
  13. * @subpackage sqlsrv
  14. */
  15. class modMenu_sqlsrv extends modMenu {
  16. /**
  17. * Gets all submenus from a start menu.
  18. *
  19. * @param string $start The top menu to load from.
  20. * @return array An array of modMenu objects, in tree form.
  21. */
  22. public function getSubMenus($start = '') {
  23. if (!$this->xpdo->lexicon) {
  24. $this->xpdo->getService('lexicon','modLexicon');
  25. }
  26. $this->xpdo->lexicon->load('menu','topmenu');
  27. $c = $this->xpdo->newQuery('modMenu');
  28. $c->select($this->xpdo->getSelectColumns('modMenu', 'modMenu'));
  29. /* 2.2 and earlier support */
  30. $c->leftJoin('modAction','Action', 'CAST(Action.id AS nvarchar) = modMenu.action');
  31. $c->select(array(
  32. 'action_controller' => 'Action.controller',
  33. 'action_namespace' => 'Action.namespace',
  34. ));
  35. $c->where(array(
  36. 'modMenu.parent' => $start,
  37. ));
  38. $c->sortby($this->xpdo->getSelectColumns('modMenu','modMenu','',array('menuindex')),'ASC');
  39. $menus = $this->xpdo->getCollection('modMenu',$c);
  40. if (count($menus) < 1) return array();
  41. $list = array();
  42. /** @var modMenu $menu */
  43. foreach ($menus as $menu) {
  44. $ma = $menu->toArray();
  45. $ma['id'] = $menu->get('text');
  46. $action = $menu->get('action');
  47. $namespace = $menu->get('namespace');
  48. // allow 2.2 and earlier actions
  49. $deprecatedNamespace = $menu->get('action_namespace');
  50. if (!empty($deprecatedNamespace)) {
  51. $namespace = $deprecatedNamespace;
  52. }
  53. if ($namespace != 'core') {
  54. $this->xpdo->lexicon->load($namespace.':default');
  55. }
  56. /* if 3rd party menu item, load proper text */
  57. if (!empty($action)) {
  58. if (!empty($namespace) && $namespace != 'core') {
  59. $ma['text'] = $menu->get('text') === 'user'
  60. ? $this->xpdo->lexicon($menu->get('text'), array('username' => $this->xpdo->getLoginUserName()))
  61. : $this->xpdo->lexicon($menu->get('text'));
  62. } else {
  63. $ma['text'] = $menu->get('text') === 'user'
  64. ? $this->xpdo->lexicon($menu->get('text'), array('username' => $this->xpdo->getLoginUserName()))
  65. : $this->xpdo->lexicon($menu->get('text'));
  66. }
  67. } else {
  68. $ma['text'] = $menu->get('text') === 'user'
  69. ? $this->xpdo->lexicon($menu->get('text'), array('username' => $this->xpdo->getLoginUserName()))
  70. : $this->xpdo->lexicon($menu->get('text'));
  71. }
  72. $desc = $menu->get('description');
  73. $ma['description'] = !empty($desc) ? $this->xpdo->lexicon($desc) : '';
  74. $ma['children'] = $menu->get('text') != '' ? $this->getSubMenus($menu->get('text')) : array();
  75. if ($menu->get('controller')) {
  76. $ma['controller'] = $menu->get('controller');
  77. } else {
  78. $ma['controller'] = '';
  79. }
  80. $list[] = $ma;
  81. }
  82. unset($menu,$desc,$namespace,$ma);
  83. return $list;
  84. }
  85. }