menunode.class.inc.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Construction and display of the application's main menu
  20. *
  21. * @copyright Copyright (C) 2010-2016 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once(APPROOT.'/application/utils.inc.php');
  25. require_once(APPROOT.'/application/template.class.inc.php');
  26. require_once(APPROOT."/application/user.dashboard.class.inc.php");
  27. /**
  28. * This class manipulates, stores and displays the navigation menu used in the application
  29. * In order to improve the modularity of the data model and to ease the update/migration
  30. * between evolving data models, the menus are no longer stored in the database, but are instead
  31. * built on the fly each time a page is loaded.
  32. * The application's menu is organized into top-level groups with, inside each group, a tree of menu items.
  33. * Top level groups do not display any content, they just expand/collapse.
  34. * Sub-items drive the actual content of the page, they are based either on templates, OQL queries or full (external?) web pages.
  35. *
  36. * Example:
  37. * Here is how to insert the following items in the application's menu:
  38. * +----------------------------------------+
  39. * | Configuration Management Group | >> Top level group
  40. * +----------------------------------------+
  41. * + Configuration Management Overview >> Template based menu item
  42. * + Contacts >> Template based menu item
  43. * + Persons >> Plain list (OQL based)
  44. * + Teams >> Plain list (OQL based)
  45. *
  46. * // Create the top-level group. fRank = 1, means it will be inserted after the group '0', which is usually 'Welcome'
  47. * $oConfigMgmtMenu = new MenuGroup('ConfigurationManagementMenu', 1);
  48. * // Create an entry, based on a custom template, for the Configuration management overview, under the top-level group
  49. * new TemplateMenuNode('ConfigurationManagementMenu', '../somedirectory/configuration_management_menu.html', $oConfigMgmtMenu->GetIndex(), 0);
  50. * // Create an entry (template based) for the overview of contacts
  51. * $oContactsMenu = new TemplateMenuNode('ContactsMenu', '../somedirectory/configuration_management_menu.html',$oConfigMgmtMenu->GetIndex(), 1);
  52. * // Plain list of persons
  53. * new OQLMenuNode('PersonsMenu', 'SELECT bizPerson', $oContactsMenu->GetIndex(), 0);
  54. *
  55. */
  56. class ApplicationMenu
  57. {
  58. static $bAdditionalMenusLoaded = false;
  59. static $aRootMenus = array();
  60. static $aMenusIndex = array();
  61. static $sFavoriteSiloQuery = 'SELECT Organization';
  62. static public function LoadAdditionalMenus()
  63. {
  64. if (!self::$bAdditionalMenusLoaded)
  65. {
  66. // Build menus from module handlers
  67. //
  68. foreach(get_declared_classes() as $sPHPClass)
  69. {
  70. if (is_subclass_of($sPHPClass, 'ModuleHandlerAPI'))
  71. {
  72. $aCallSpec = array($sPHPClass, 'OnMenuCreation');
  73. call_user_func($aCallSpec);
  74. }
  75. }
  76. // Build menus from the menus themselves (e.g. the ShortcutContainerMenuNode will do that)
  77. //
  78. foreach(self::$aRootMenus as $aMenu)
  79. {
  80. $oMenuNode = self::GetMenuNode($aMenu['index']);
  81. $oMenuNode->PopulateChildMenus();
  82. }
  83. self::$bAdditionalMenusLoaded = true;
  84. }
  85. }
  86. /**
  87. * Set the query used to limit the list of displayed organizations in the drop-down menu
  88. * @param $sOQL string The OQL query returning a list of Organization objects
  89. * @return none
  90. */
  91. static public function SetFavoriteSiloQuery($sOQL)
  92. {
  93. self::$sFavoriteSiloQuery = $sOQL;
  94. }
  95. /**
  96. * Get the query used to limit the list of displayed organizations in the drop-down menu
  97. * @return string The OQL query returning a list of Organization objects
  98. */
  99. static public function GetFavoriteSiloQuery()
  100. {
  101. return self::$sFavoriteSiloQuery;
  102. }
  103. /**
  104. * Main function to add a menu entry into the application, can be called during the definition
  105. * of the data model objects
  106. */
  107. static public function InsertMenu(MenuNode $oMenuNode, $iParentIndex, $fRank)
  108. {
  109. $index = self::GetMenuIndexById($oMenuNode->GetMenuId());
  110. if ($index == -1)
  111. {
  112. // The menu does not already exist, insert it
  113. $index = count(self::$aMenusIndex);
  114. if ($iParentIndex == -1)
  115. {
  116. $sParentId = '';
  117. self::$aRootMenus[] = array ('rank' => $fRank, 'index' => $index);
  118. }
  119. else
  120. {
  121. $sParentId = self::$aMenusIndex[$iParentIndex]['node']->GetMenuId();
  122. self::$aMenusIndex[$iParentIndex]['children'][] = array ('rank' => $fRank, 'index' => $index);
  123. }
  124. // Note: At the time when 'parent', 'rank' and 'source_file' have been added for the reflection API,
  125. // they were not used to display the menus (redundant or unused)
  126. //
  127. $aBacktrace = debug_backtrace();
  128. $sFile = isset($aBacktrace[2]["file"]) ? $aBacktrace[2]["file"] : $aBacktrace[1]["file"];
  129. self::$aMenusIndex[$index] = array('node' => $oMenuNode, 'children' => array(), 'parent' => $sParentId, 'rank' => $fRank, 'source_file' => $sFile);
  130. }
  131. else
  132. {
  133. // the menu already exists, let's combine the conditions that make it visible
  134. self::$aMenusIndex[$index]['node']->AddCondition($oMenuNode);
  135. }
  136. return $index;
  137. }
  138. /**
  139. * Reflection API - Get menu entries
  140. */
  141. static public function ReflectionMenuNodes()
  142. {
  143. self::LoadAdditionalMenus();
  144. return self::$aMenusIndex;
  145. }
  146. /**
  147. * Entry point to display the whole menu into the web page, used by iTopWebPage
  148. */
  149. static public function DisplayMenu($oPage, $aExtraParams)
  150. {
  151. self::LoadAdditionalMenus();
  152. // Sort the root menu based on the rank
  153. usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
  154. $iAccordion = 0;
  155. $iActiveMenu = self::GetMenuIndexById(self::GetActiveNodeId());
  156. foreach(self::$aRootMenus as $aMenu)
  157. {
  158. $oMenuNode = self::GetMenuNode($aMenu['index']);
  159. if (!$oMenuNode->IsEnabled()) continue; // Don't display a non-enabled menu
  160. $oPage->AddToMenu('<h3>'.$oMenuNode->GetTitle().'</h3>');
  161. $oPage->AddToMenu('<div>');
  162. $aChildren = self::GetChildren($aMenu['index']);
  163. if (count($aChildren) > 0)
  164. {
  165. $oPage->AddToMenu('<ul>');
  166. $bActive = self::DisplaySubMenu($oPage, $aChildren, $aExtraParams, $iActiveMenu);
  167. $oPage->AddToMenu('</ul>');
  168. if ($bActive)
  169. {
  170. $oPage->add_ready_script(
  171. <<<EOF
  172. // Accordion Menu
  173. $("#accordion").css({display:'block'}).accordion({ header: "h3", navigation: true, heightStyle: "content", collapsible: true, active: $iAccordion, icons: false, animate:true }); // collapsible will be enabled once the item will be selected
  174. EOF
  175. );
  176. }
  177. }
  178. $oPage->AddToMenu('</div>');
  179. $iAccordion++;
  180. }
  181. }
  182. /**
  183. * Handles the display of the sub-menus (called recursively if necessary)
  184. * @return true if the currently selected menu is one of the submenus
  185. */
  186. static protected function DisplaySubMenu($oPage, $aMenus, $aExtraParams, $iActiveMenu = -1)
  187. {
  188. // Sort the menu based on the rank
  189. $bActive = false;
  190. usort($aMenus, array('ApplicationMenu', 'CompareOnRank'));
  191. foreach($aMenus as $aMenu)
  192. {
  193. $index = $aMenu['index'];
  194. $oMenu = self::GetMenuNode($index);
  195. if ($oMenu->IsEnabled())
  196. {
  197. $aChildren = self::GetChildren($index);
  198. $sCSSClass = (count($aChildren) > 0) ? ' class="submenu"' : '';
  199. $sHyperlink = $oMenu->GetHyperlink($aExtraParams);
  200. if ($sHyperlink != '')
  201. {
  202. $oPage->AddToMenu('<li'.$sCSSClass.'><a href="'.$oMenu->GetHyperlink($aExtraParams).'">'.$oMenu->GetTitle().'</a></li>');
  203. }
  204. else
  205. {
  206. $oPage->AddToMenu('<li'.$sCSSClass.'>'.$oMenu->GetTitle().'</li>');
  207. }
  208. $aCurrentMenu = self::$aMenusIndex[$index];
  209. if ($iActiveMenu == $index)
  210. {
  211. $bActive = true;
  212. }
  213. if (count($aChildren) > 0)
  214. {
  215. $oPage->AddToMenu('<ul>');
  216. $bActive |= self::DisplaySubMenu($oPage, $aChildren, $aExtraParams, $iActiveMenu);
  217. $oPage->AddToMenu('</ul>');
  218. }
  219. }
  220. }
  221. return $bActive;
  222. }
  223. /**
  224. * Helper function to sort the menus based on their rank
  225. */
  226. static public function CompareOnRank($a, $b)
  227. {
  228. $result = 1;
  229. if ($a['rank'] == $b['rank'])
  230. {
  231. $result = 0;
  232. }
  233. if ($a['rank'] < $b['rank'])
  234. {
  235. $result = -1;
  236. }
  237. return $result;
  238. }
  239. /**
  240. * Helper function to retrieve the MenuNodeObject based on its ID
  241. */
  242. static public function GetMenuNode($index)
  243. {
  244. return isset(self::$aMenusIndex[$index]) ? self::$aMenusIndex[$index]['node'] : null;
  245. }
  246. /**
  247. * Helper function to get the list of child(ren) of a menu
  248. */
  249. static public function GetChildren($index)
  250. {
  251. return self::$aMenusIndex[$index]['children'];
  252. }
  253. /**
  254. * Helper function to get the ID of a menu based on its name
  255. * @param string $sTitle Title of the menu (as passed when creating the menu)
  256. * @return integer ID of the menu, or -1 if not found
  257. */
  258. static public function GetMenuIndexById($sTitle)
  259. {
  260. $index = -1;
  261. foreach(self::$aMenusIndex as $aMenu)
  262. {
  263. if ($aMenu['node']->GetMenuId() == $sTitle)
  264. {
  265. $index = $aMenu['node']->GetIndex();
  266. break;
  267. }
  268. }
  269. return $index;
  270. }
  271. /**
  272. * Retrieves the currently active menu (if any, otherwise the first menu is the default)
  273. * @return string The Id of the currently active menu
  274. */
  275. static public function GetActiveNodeId()
  276. {
  277. $oAppContext = new ApplicationContext();
  278. $sMenuId = $oAppContext->GetCurrentValue('menu', null);
  279. if ($sMenuId === null)
  280. {
  281. $sMenuId = self::GetDefaultMenuId();
  282. }
  283. return $sMenuId;
  284. }
  285. static public function GetDefaultMenuId()
  286. {
  287. static $sDefaultMenuId = null;
  288. if (is_null($sDefaultMenuId))
  289. {
  290. // Make sure the root menu is sorted on 'rank'
  291. usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
  292. $oFirstGroup = self::GetMenuNode(self::$aRootMenus[0]['index']);
  293. $aChildren = self::$aMenusIndex[$oFirstGroup->GetIndex()]['children'];
  294. usort($aChildren, array('ApplicationMenu', 'CompareOnRank'));
  295. $oMenuNode = self::GetMenuNode($aChildren[0]['index']);
  296. $sDefaultMenuId = $oMenuNode->GetMenuId();
  297. }
  298. return $sDefaultMenuId;
  299. }
  300. }
  301. /**
  302. * Root class for all the kind of node in the menu tree, data model providers are responsible for instantiating
  303. * MenuNodes (i.e instances from derived classes) in order to populate the application's menu. Creating an objet
  304. * derived from MenuNode is enough to have it inserted in the application's main menu.
  305. * The class iTopWebPage, takes care of 3 items:
  306. * +--------------------+
  307. * | Welcome |
  308. * +--------------------+
  309. * Welcome To iTop
  310. * +--------------------+
  311. * | Tools |
  312. * +--------------------+
  313. * CSV Import
  314. * +--------------------+
  315. * | Admin Tools |
  316. * +--------------------+
  317. * User Accounts
  318. * Profiles
  319. * Notifications
  320. * Run Queries
  321. * Export
  322. * Data Model
  323. * Universal Search
  324. *
  325. * All the other menu items must constructed along with the various data model modules
  326. */
  327. abstract class MenuNode
  328. {
  329. protected $sMenuId;
  330. protected $index;
  331. protected $iParentIndex;
  332. /**
  333. * Properties reflecting how the node has been declared
  334. */
  335. protected $aReflectionProperties;
  336. /**
  337. * Class of objects to check if the menu is enabled, null if none
  338. */
  339. protected $m_aEnableClasses;
  340. /**
  341. * User Rights Action code to check if the menu is enabled, null if none
  342. */
  343. protected $m_aEnableActions;
  344. /**
  345. * User Rights allowed results (actually a bitmask) to check if the menu is enabled, null if none
  346. */
  347. protected $m_aEnableActionResults;
  348. /**
  349. * Stimulus to check: if the user can 'apply' this stimulus, then she/he can see this menu
  350. */
  351. protected $m_aEnableStimuli;
  352. /**
  353. * Create a menu item, sets the condition to have it displayed and inserts it into the application's main menu
  354. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  355. * @param integer $iParentIndex ID of the parent menu, pass -1 for top level (group) items
  356. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  357. * @param string $sEnableClass Name of class of object
  358. * @param mixed $iActionCode UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  359. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  360. * @param string $sEnableStimulus The user can see this menu if she/he has enough rights to apply this stimulus
  361. * @return MenuNode
  362. */
  363. public function __construct($sMenuId, $iParentIndex = -1, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  364. {
  365. $this->sMenuId = $sMenuId;
  366. $this->iParentIndex = $iParentIndex;
  367. $this->aReflectionProperties = array();
  368. if (strlen($sEnableClass) > 0)
  369. {
  370. $this->aReflectionProperties['enable_class'] = $sEnableClass;
  371. $this->aReflectionProperties['enable_action'] = $iActionCode;
  372. $this->aReflectionProperties['enable_permission'] = $iAllowedResults;
  373. $this->aReflectionProperties['enable_stimulus'] = $sEnableStimulus;
  374. }
  375. $this->m_aEnableClasses = array($sEnableClass);
  376. $this->m_aEnableActions = array($iActionCode);
  377. $this->m_aEnableActionResults = array($iAllowedResults);
  378. $this->m_aEnableStimuli = array($sEnableStimulus);
  379. $this->index = ApplicationMenu::InsertMenu($this, $iParentIndex, $fRank);
  380. }
  381. public function ReflectionProperties()
  382. {
  383. return $this->aReflectionProperties;
  384. }
  385. public function GetMenuId()
  386. {
  387. return $this->sMenuId;
  388. }
  389. public function GetTitle()
  390. {
  391. return Dict::S("Menu:$this->sMenuId", str_replace('_', ' ', $this->sMenuId));
  392. }
  393. public function GetLabel()
  394. {
  395. $sRet = Dict::S("Menu:$this->sMenuId+", "");
  396. if ($sRet === '')
  397. {
  398. if ($this->iParentIndex != -1)
  399. {
  400. $oParentMenu = ApplicationMenu::GetMenuNode($this->iParentIndex);
  401. $sRet = $oParentMenu->GetTitle().' / '.$this->GetTitle();
  402. }
  403. else
  404. {
  405. $sRet = $this->GetTitle();
  406. }
  407. //$sRet = $this->GetTitle();
  408. }
  409. return $sRet;
  410. }
  411. public function GetIndex()
  412. {
  413. return $this->index;
  414. }
  415. public function PopulateChildMenus()
  416. {
  417. foreach (ApplicationMenu::GetChildren($this->GetIndex()) as $aMenu)
  418. {
  419. $index = $aMenu['index'];
  420. $oMenu = ApplicationMenu::GetMenuNode($index);
  421. $oMenu->PopulateChildMenus();
  422. }
  423. }
  424. public function GetHyperlink($aExtraParams)
  425. {
  426. $aExtraParams['c[menu]'] = $this->GetMenuId();
  427. return $this->AddParams(utils::GetAbsoluteUrlAppRoot().'pages/UI.php', $aExtraParams);
  428. }
  429. /**
  430. * Add a limiting display condition for the same menu node. The conditions will be combined with a AND
  431. * @param $oMenuNode MenuNode Another definition of the same menu node, with potentially different access restriction
  432. * @return void
  433. */
  434. public function AddCondition(MenuNode $oMenuNode)
  435. {
  436. foreach($oMenuNode->m_aEnableClasses as $index => $sClass )
  437. {
  438. $this->m_aEnableClasses[] = $sClass;
  439. $this->m_aEnableActions[] = $oMenuNode->m_aEnableActions[$index];
  440. $this->m_aEnableActionResults[] = $oMenuNode->m_aEnableActionResults[$index];
  441. $this->m_aEnableStimuli[] = $oMenuNode->m_aEnableStimuli[$index];
  442. }
  443. }
  444. /**
  445. * Tells whether the menu is enabled (i.e. displayed) for the current user
  446. * @return bool True if enabled, false otherwise
  447. */
  448. public function IsEnabled()
  449. {
  450. foreach($this->m_aEnableClasses as $index => $sClass)
  451. {
  452. if ($sClass != null)
  453. {
  454. if (MetaModel::IsValidClass($sClass))
  455. {
  456. if ($this->m_aEnableStimuli[$index] != null)
  457. {
  458. if (!UserRights::IsStimulusAllowed($sClass, $this->m_aEnableStimuli[$index]))
  459. {
  460. return false;
  461. }
  462. }
  463. if ($this->m_aEnableActions[$index] != null)
  464. {
  465. $iResult = UserRights::IsActionAllowed($sClass, $this->m_aEnableActions[$index]);
  466. if (!($iResult & $this->m_aEnableActionResults[$index]))
  467. {
  468. return false;
  469. }
  470. }
  471. }
  472. else
  473. {
  474. return false;
  475. }
  476. }
  477. }
  478. return true;
  479. }
  480. public abstract function RenderContent(WebPage $oPage, $aExtraParams = array());
  481. protected function AddParams($sHyperlink, $aExtraParams)
  482. {
  483. if (count($aExtraParams) > 0)
  484. {
  485. $aQuery = array();
  486. $sSeparator = '?';
  487. if (strpos($sHyperlink, '?') !== false)
  488. {
  489. $sSeparator = '&';
  490. }
  491. foreach($aExtraParams as $sName => $sValue)
  492. {
  493. $aQuery[] = urlencode($sName).'='.urlencode($sValue);
  494. }
  495. $sHyperlink .= $sSeparator.implode('&', $aQuery);
  496. }
  497. return $sHyperlink;
  498. }
  499. }
  500. /**
  501. * This class implements a top-level menu group. A group is just a container for sub-items
  502. * it does not display a page by itself
  503. */
  504. class MenuGroup extends MenuNode
  505. {
  506. /**
  507. * Create a top-level menu group and inserts it into the application's main menu
  508. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  509. * @param float $fRank Number used to order the list, the groups are sorted based on this value
  510. * @param string $sEnableClass Name of class of object
  511. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  512. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  513. * @return MenuGroup
  514. */
  515. public function __construct($sMenuId, $fRank, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  516. {
  517. parent::__construct($sMenuId, -1 /* no parent, groups are at root level */, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  518. }
  519. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  520. {
  521. assert(false); // Shall never be called, groups do not display any content
  522. }
  523. }
  524. /**
  525. * This class defines a menu item which content is based on a custom template.
  526. * Note the template can be either a local file or an URL !
  527. */
  528. class TemplateMenuNode extends MenuNode
  529. {
  530. protected $sTemplateFile;
  531. /**
  532. * Create a menu item based on a custom template and inserts it into the application's main menu
  533. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  534. * @param string $sTemplateFile Path (or URL) to the file that will be used as a template for displaying the page's content
  535. * @param integer $iParentIndex ID of the parent menu
  536. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  537. * @param string $sEnableClass Name of class of object
  538. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  539. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  540. * @return MenuNode
  541. */
  542. public function __construct($sMenuId, $sTemplateFile, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  543. {
  544. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  545. $this->sTemplateFile = $sTemplateFile;
  546. $this->aReflectionProperties['template_file'] = $sTemplateFile;
  547. }
  548. public function GetHyperlink($aExtraParams)
  549. {
  550. if ($this->sTemplateFile == '') return '';
  551. return parent::GetHyperlink($aExtraParams);
  552. }
  553. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  554. {
  555. $sTemplate = @file_get_contents($this->sTemplateFile);
  556. if ($sTemplate !== false)
  557. {
  558. $aExtraParams['table_id'] = 'Menu_'.$this->GetMenuId();
  559. $oTemplate = new DisplayTemplate($sTemplate);
  560. $oTemplate->Render($oPage, $aExtraParams);
  561. }
  562. else
  563. {
  564. $oPage->p("Error: failed to load template file: '{$this->sTemplateFile}'"); // No need to translate ?
  565. }
  566. }
  567. }
  568. /**
  569. * This class defines a menu item that uses a standard template to display a list of items therefore it allows
  570. * only two parameters: the page's title and the OQL expression defining the list of items to be displayed
  571. */
  572. class OQLMenuNode extends MenuNode
  573. {
  574. protected $sPageTitle;
  575. protected $sOQL;
  576. protected $bSearch;
  577. protected $bSearchFormOpen;
  578. /**
  579. * Extra parameters to be passed to the display block to fine tune its appearence
  580. */
  581. protected $m_aParams;
  582. /**
  583. * Create a menu item based on an OQL query and inserts it into the application's main menu
  584. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  585. * @param string $sOQL OQL query defining the set of objects to be displayed
  586. * @param integer $iParentIndex ID of the parent menu
  587. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  588. * @param bool $bSearch Whether or not to display a (collapsed) search frame at the top of the page
  589. * @param string $sEnableClass Name of class of object
  590. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  591. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  592. * @return MenuNode
  593. */
  594. public function __construct($sMenuId, $sOQL, $iParentIndex, $fRank = 0, $bSearch = false, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null, $bSearchFormOpen = true)
  595. {
  596. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  597. $this->sPageTitle = "Menu:$sMenuId+";
  598. $this->sOQL = $sOQL;
  599. $this->bSearch = $bSearch;
  600. $this->bSearchFormOpen = $bSearchFormOpen;
  601. $this->m_aParams = array();
  602. $this->aReflectionProperties['oql'] = $sOQL;
  603. $this->aReflectionProperties['do_search'] = $bSearch;
  604. // Enhancement: we could set as the "enable" condition that the user has enough rights to "read" the objects
  605. // of the class specified by the OQL...
  606. }
  607. /**
  608. * Set some extra parameters to be passed to the display block to fine tune its appearence
  609. * @param Hash $aParams paramCode => value. See DisplayBlock::GetDisplay for the meaning of the parameters
  610. */
  611. public function SetParameters($aParams)
  612. {
  613. $this->m_aParams = $aParams;
  614. foreach($aParams as $sKey => $value)
  615. {
  616. $this->aReflectionProperties[$sKey] = $value;
  617. }
  618. }
  619. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  620. {
  621. OQLMenuNode::RenderOQLSearch
  622. (
  623. $this->sOQL,
  624. Dict::S($this->sPageTitle),
  625. 'Menu_'.$this->GetMenuId(),
  626. $this->bSearch, // Search pane
  627. $this->bSearchFormOpen, // Search open
  628. $oPage,
  629. array_merge($this->m_aParams, $aExtraParams),
  630. true
  631. );
  632. }
  633. public static function RenderOQLSearch($sOql, $sTitle, $sUsageId, $bSearchPane, $bSearchOpen, WebPage $oPage, $aExtraParams = array(), $bEnableBreadcrumb = false)
  634. {
  635. $sUsageId = utils::GetSafeId($sUsageId);
  636. $oSearch = DBObjectSearch::FromOQL($sOql);
  637. $sIcon = MetaModel::GetClassIcon($oSearch->GetClass());
  638. if ($bSearchPane)
  639. {
  640. $aParams = array_merge(array('open' => $bSearchOpen, 'table_id' => $sUsageId), $aExtraParams);
  641. $oBlock = new DisplayBlock($oSearch, 'search', false /* Asynchronous */, $aParams);
  642. $oBlock->Display($oPage, 0);
  643. }
  644. $oPage->add("<p class=\"page-header\">$sIcon ".Dict::S($sTitle)."</p>");
  645. $aParams = array_merge(array('table_id' => $sUsageId), $aExtraParams);
  646. $oBlock = new DisplayBlock($oSearch, 'list', false /* Asynchronous */, $aParams);
  647. $oBlock->Display($oPage, $sUsageId);
  648. if ($bEnableBreadcrumb && ($oPage instanceof iTopWebPage))
  649. {
  650. // Breadcrumb
  651. //$iCount = $oBlock->GetDisplayedCount();
  652. $sPageId = "ui-search-".$oSearch->GetClass();
  653. $sLabel = MetaModel::GetName($oSearch->GetClass());
  654. $oPage->SetBreadCrumbEntry($sPageId, $sLabel, $sTitle, '', '../images/breadcrumb-search.png');
  655. }
  656. }
  657. }
  658. /**
  659. * This class defines a menu item that displays a search form for the given class of objects
  660. */
  661. class SearchMenuNode extends MenuNode
  662. {
  663. protected $sPageTitle;
  664. protected $sClass;
  665. /**
  666. * Create a menu item based on an OQL query and inserts it into the application's main menu
  667. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  668. * @param string $sClass The class of objects to search for
  669. * @param string $sPageTitle Title displayed into the page's content (will be looked-up in the dictionnary for translation)
  670. * @param integer $iParentIndex ID of the parent menu
  671. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  672. * @param string $sEnableClass Name of class of object
  673. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  674. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  675. * @return MenuNode
  676. */
  677. public function __construct($sMenuId, $sClass, $iParentIndex, $fRank = 0, $bSearch = false, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  678. {
  679. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  680. $this->sPageTitle = "Menu:$sMenuId+";
  681. $this->sClass = $sClass;
  682. $this->aReflectionProperties['class'] = $sClass;
  683. }
  684. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  685. {
  686. $oPage->SetBreadCrumbEntry("menu-".$this->sMenuId, $this->GetTitle(), '', '', utils::GetAbsoluteUrlAppRoot().'images/search.png');
  687. $oSearch = new DBObjectSearch($this->sClass);
  688. $aParams = array_merge(array('open' => true, 'table_id' => 'Menu_'.utils::GetSafeId($this->GetMenuId())), $aExtraParams);
  689. $oBlock = new DisplayBlock($oSearch, 'search', false /* Asynchronous */, $aParams);
  690. $oBlock->Display($oPage, 0);
  691. }
  692. }
  693. /**
  694. * This class defines a menu that points to any web page. It takes only two parameters:
  695. * - The hyperlink to point to
  696. * - The name of the menu
  697. * Note: the parameter menu=xxx (where xxx is the id of the menu itself) will be added to the hyperlink
  698. * in order to make it the active one, if the target page is based on iTopWebPage and therefore displays the menu
  699. */
  700. class WebPageMenuNode extends MenuNode
  701. {
  702. protected $sHyperlink;
  703. /**
  704. * Create a menu item that points to any web page (not only UI.php)
  705. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  706. * @param string $sHyperlink URL to the page to load. Use relative URL if you want to keep the application portable !
  707. * @param integer $iParentIndex ID of the parent menu
  708. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  709. * @param string $sEnableClass Name of class of object
  710. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  711. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  712. * @return MenuNode
  713. */
  714. public function __construct($sMenuId, $sHyperlink, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  715. {
  716. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  717. $this->sHyperlink = $sHyperlink;
  718. $this->aReflectionProperties['url'] = $sHyperlink;
  719. }
  720. public function GetHyperlink($aExtraParams)
  721. {
  722. $aExtraParams['c[menu]'] = $this->GetMenuId();
  723. return $this->AddParams( $this->sHyperlink, $aExtraParams);
  724. }
  725. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  726. {
  727. assert(false); // Shall never be called, the external web page will handle the display by itself
  728. }
  729. }
  730. /**
  731. * This class defines a menu that points to the page for creating a new object of the specified class.
  732. * It take only one parameter: the name of the class
  733. * Note: the parameter menu=xxx (where xxx is the id of the menu itself) will be added to the hyperlink
  734. * in order to make it the active one
  735. */
  736. class NewObjectMenuNode extends MenuNode
  737. {
  738. protected $sClass;
  739. /**
  740. * Create a menu item that points to the URL for creating a new object, the menu will be added only if the current user has enough
  741. * rights to create such an object (or an object of a child class)
  742. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  743. * @param string $sClass URL to the page to load. Use relative URL if you want to keep the application portable !
  744. * @param integer $iParentIndex ID of the parent menu
  745. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  746. * @return MenuNode
  747. */
  748. public function __construct($sMenuId, $sClass, $iParentIndex, $fRank = 0)
  749. {
  750. parent::__construct($sMenuId, $iParentIndex, $fRank);
  751. $this->sClass = $sClass;
  752. $this->aReflectionProperties['class'] = $sClass;
  753. }
  754. public function GetHyperlink($aExtraParams)
  755. {
  756. $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$this->sClass;
  757. $aExtraParams['c[menu]'] = $this->GetMenuId();
  758. return $this->AddParams($sHyperlink, $aExtraParams);
  759. }
  760. /**
  761. * Overload the check of the "enable" state of this menu to take into account
  762. * derived classes of objects
  763. */
  764. public function IsEnabled()
  765. {
  766. // Enable this menu, only if the current user has enough rights to create such an object, or an object of
  767. // any child class
  768. $aSubClasses = MetaModel::EnumChildClasses($this->sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
  769. $bActionIsAllowed = false;
  770. foreach($aSubClasses as $sCandidateClass)
  771. {
  772. if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES))
  773. {
  774. $bActionIsAllowed = true;
  775. break; // Enough for now
  776. }
  777. }
  778. return $bActionIsAllowed;
  779. }
  780. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  781. {
  782. assert(false); // Shall never be called, the external web page will handle the display by itself
  783. }
  784. }
  785. require_once(APPROOT.'application/dashboard.class.inc.php');
  786. /**
  787. * This class defines a menu item which content is based on XML dashboard.
  788. */
  789. class DashboardMenuNode extends MenuNode
  790. {
  791. protected $sDashboardFile;
  792. /**
  793. * Create a menu item based on a custom template and inserts it into the application's main menu
  794. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  795. * @param string $sTemplateFile Path (or URL) to the file that will be used as a template for displaying the page's content
  796. * @param integer $iParentIndex ID of the parent menu
  797. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  798. * @param string $sEnableClass Name of class of object
  799. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  800. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  801. * @return MenuNode
  802. */
  803. public function __construct($sMenuId, $sDashboardFile, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  804. {
  805. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  806. $this->sDashboardFile = $sDashboardFile;
  807. $this->aReflectionProperties['definition_file'] = $sDashboardFile;
  808. }
  809. public function GetHyperlink($aExtraParams)
  810. {
  811. if ($this->sDashboardFile == '') return '';
  812. return parent::GetHyperlink($aExtraParams);
  813. }
  814. public function GetDashboard()
  815. {
  816. $sDashboardDefinition = @file_get_contents($this->sDashboardFile);
  817. if ($sDashboardDefinition !== false)
  818. {
  819. $bCustomized = false;
  820. // Search for an eventual user defined dashboard, overloading the existing one
  821. $oUDSearch = new DBObjectSearch('UserDashboard');
  822. $oUDSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
  823. $oUDSearch->AddCondition('menu_code', $this->sMenuId, '=');
  824. $oUDSet = new DBObjectSet($oUDSearch);
  825. if ($oUDSet->Count() > 0)
  826. {
  827. // Assuming there is at most one couple {user, menu}!
  828. $oUserDashboard = $oUDSet->Fetch();
  829. $sDashboardDefinition = $oUserDashboard->Get('contents');
  830. $bCustomized = true;
  831. }
  832. $oDashboard = new RuntimeDashboard($this->sMenuId);
  833. $oDashboard->FromXml($sDashboardDefinition);
  834. $oDashboard->SetCustomFlag($bCustomized);
  835. }
  836. else
  837. {
  838. $oDashboard = null;
  839. }
  840. return $oDashboard;
  841. }
  842. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  843. {
  844. $oDashboard = $this->GetDashboard();
  845. if ($oDashboard != null)
  846. {
  847. $sDivId = preg_replace('/[^a-zA-Z0-9_]/', '', $this->sMenuId);
  848. $oPage->add('<div class="dashboard_contents" id="'.$sDivId.'">');
  849. $oDashboard->Render($oPage, false, $aExtraParams);
  850. $oPage->add('</div>');
  851. $oDashboard->RenderEditionTools($oPage);
  852. if ($oDashboard->GetAutoReload())
  853. {
  854. $sId = $this->sMenuId;
  855. $sExtraParams = json_encode($aExtraParams);
  856. $iReloadInterval = 1000 * $oDashboard->GetAutoReloadInterval();
  857. $oPage->add_script(
  858. <<<EOF
  859. setInterval("ReloadDashboard('$sDivId');", $iReloadInterval);
  860. function ReloadDashboard(sDivId)
  861. {
  862. var oExtraParams = $sExtraParams;
  863. // Do not reload when a dialog box is active
  864. if (!($('.ui-dialog:visible').length > 0))
  865. {
  866. $('.dashboard_contents#'+sDivId).block();
  867. $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php',
  868. { operation: 'reload_dashboard', dashboard_id: '$sId', extra_params: oExtraParams},
  869. function(data){
  870. $('.dashboard_contents#'+sDivId).html(data);
  871. $('.dashboard_contents#'+sDivId).unblock();
  872. }
  873. );
  874. }
  875. }
  876. EOF
  877. );
  878. }
  879. $bEdit = utils::ReadParam('edit', false);
  880. if ($bEdit)
  881. {
  882. $sId = addslashes($this->sMenuId);
  883. $oPage->add_ready_script("EditDashboard('$sId');");
  884. }
  885. else
  886. {
  887. $oParentMenu = ApplicationMenu::GetMenuNode($this->iParentIndex);
  888. $sParentTitle = $oParentMenu->GetTitle();
  889. $sThisTitle = $this->GetTitle();
  890. if ($sParentTitle != $sThisTitle)
  891. {
  892. $sDescription = $sParentTitle.' / '.$sThisTitle;
  893. }
  894. else
  895. {
  896. $sDescription = $sThisTitle;
  897. }
  898. if ($this->sMenuId == ApplicationMenu::GetDefaultMenuId())
  899. {
  900. $sIcon = '../images/breadcrumb_home.png';
  901. }
  902. else
  903. {
  904. $sIcon = '../images/breadcrumb-dashboard.png';
  905. }
  906. $oPage->SetBreadCrumbEntry("ui-dashboard-".$this->sMenuId, $this->GetTitle(), $sDescription, '', $sIcon);
  907. }
  908. }
  909. else
  910. {
  911. $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  912. }
  913. }
  914. public function RenderEditor(WebPage $oPage)
  915. {
  916. $oDashboard = $this->GetDashboard();
  917. if ($oDashboard != null)
  918. {
  919. $oDashboard->RenderEditor($oPage);
  920. }
  921. else
  922. {
  923. $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  924. }
  925. }
  926. public function AddDashlet($oDashlet)
  927. {
  928. $oDashboard = $this->GetDashboard();
  929. if ($oDashboard != null)
  930. {
  931. $oDashboard->AddDashlet($oDashlet);
  932. $oDashboard->Save();
  933. }
  934. else
  935. {
  936. throw new Exception("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  937. }
  938. }
  939. }
  940. /**
  941. * A shortcut container is the preferred destination of newly created shortcuts
  942. */
  943. class ShortcutContainerMenuNode extends MenuNode
  944. {
  945. public function GetHyperlink($aExtraParams)
  946. {
  947. return '';
  948. }
  949. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  950. {
  951. }
  952. public function PopulateChildMenus()
  953. {
  954. // Load user shortcuts in DB
  955. //
  956. $oBMSearch = new DBObjectSearch('Shortcut');
  957. $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
  958. $oBMSet = new DBObjectSet($oBMSearch, array('friendlyname' => true)); // ascending on friendlyname
  959. $fRank = 1;
  960. while ($oShortcut = $oBMSet->Fetch())
  961. {
  962. $sName = $this->GetMenuId().'_'.$oShortcut->GetKey();
  963. $oShortcutMenu = new ShortcutMenuNode($sName, $oShortcut, $this->GetIndex(), $fRank++);
  964. }
  965. // Complete the tree
  966. //
  967. parent::PopulateChildMenus();
  968. }
  969. }
  970. require_once(APPROOT.'application/shortcut.class.inc.php');
  971. /**
  972. * This class defines a menu item which content is a shortcut.
  973. */
  974. class ShortcutMenuNode extends MenuNode
  975. {
  976. protected $oShortcut;
  977. /**
  978. * Create a menu item based on a custom template and inserts it into the application's main menu
  979. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  980. * @param object $oShortcut Shortcut object
  981. * @param integer $iParentIndex ID of the parent menu
  982. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  983. * @param string $sEnableClass Name of class of object
  984. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  985. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  986. * @return MenuNode
  987. */
  988. public function __construct($sMenuId, $oShortcut, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  989. {
  990. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  991. $this->oShortcut = $oShortcut;
  992. $this->aReflectionProperties['shortcut'] = $oShortcut->GetKey();
  993. }
  994. public function GetHyperlink($aExtraParams)
  995. {
  996. $sContext = $this->oShortcut->Get('context');
  997. $aContext = unserialize($sContext);
  998. if (isset($aContext['menu']))
  999. {
  1000. unset($aContext['menu']);
  1001. }
  1002. foreach ($aContext as $sArgName => $sArgValue)
  1003. {
  1004. $aExtraParams[$sArgName] = $sArgValue;
  1005. }
  1006. return parent::GetHyperlink($aExtraParams);
  1007. }
  1008. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  1009. {
  1010. $this->oShortcut->RenderContent($oPage, $aExtraParams);
  1011. }
  1012. public function GetTitle()
  1013. {
  1014. return $this->oShortcut->Get('name');
  1015. }
  1016. public function GetLabel()
  1017. {
  1018. return $this->oShortcut->Get('name');
  1019. }
  1020. }