BxBaseModGeneralMenuView.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * View entry menu
  13. */
  14. class BxBaseModGeneralMenuView extends BxTemplMenu
  15. {
  16. protected $MODULE;
  17. protected $_oModule;
  18. protected $_iContentId;
  19. protected $_aContentInfo;
  20. public function __construct($aObject, $oTemplate = false)
  21. {
  22. parent::__construct($aObject, $oTemplate);
  23. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  24. }
  25. /**
  26. * Check if menu items is visible with extended checking linked to "allow*" method of particular module
  27. * Associated "allow*" method with particular menu item is stored in module config in MENU_ITEM_TO_METHOD array.
  28. * @param $a menu item array
  29. * @return boolean
  30. */
  31. protected function _isVisible ($a)
  32. {
  33. if(!parent::_isVisible($a))
  34. return false;
  35. return $this->_oModule->isMenuItemVisible($this->_sObject, $a, $this->_aContentInfo);
  36. }
  37. protected function _getMenuItemsCombined ()
  38. {
  39. // combile values from ACTIONS_VIEW_ENTRY and ACTIONS_VIEW_ENTRY_MORE menus
  40. $CNF = $this->_oModule->_oConfig->CNF;
  41. if (empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  42. return array();
  43. $aItems = $this->_oQuery->getMenuItemsFromSet($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  44. if (empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  45. return $aItems;
  46. $aItemsMore = $this->_oQuery->getMenuItemsFromSet($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  47. // remove "more" item from ACTIONS_VIEW_ENTRY
  48. $aItems = array_filter ($aItems, function ($aItem) {
  49. return $aItem['order'] != BX_MENU_LAST_ITEM_ORDER;
  50. });
  51. // return combined array
  52. return array_merge($aItems, $aItemsMore);
  53. }
  54. }
  55. /** @} */