BxBaseModGeneralMenuView.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // default visible settings
  34. if (!BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']))
  35. return false;
  36. $CNF = $this->_oModule->_oConfig->CNF;
  37. // get custom function name to check menu item visibility
  38. $sFuncCheckAccess = false;
  39. if (isset($CNF['MENU_ITEM_TO_METHOD'][$this->_sObject][$a['name']]))
  40. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$this->_sObject][$a['name']];
  41. // check custom visibility settings defined in module config class
  42. if ($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this->_oModule, $sFuncCheckAccess), isset($this->_aContentInfo) ? array(&$this->_aContentInfo) : array()))
  43. return false;
  44. return true;
  45. }
  46. protected function _getMenuItemsCombined ()
  47. {
  48. // combile values from ACTIONS_VIEW_ENTRY and ACTIONS_VIEW_ENTRY_MORE menus
  49. $CNF = $this->_oModule->_oConfig->CNF;
  50. if (empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  51. return array();
  52. $aItems = $this->_oQuery->getMenuItemsFromSet($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  53. if (empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  54. return $aItems;
  55. $aItemsMore = $this->_oQuery->getMenuItemsFromSet($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  56. // remove "more" item from ACTIONS_VIEW_ENTRY
  57. $aItems = array_filter ($aItems, function ($aItem) {
  58. return $aItem['order'] != BX_MENU_LAST_ITEM_ORDER;
  59. });
  60. // return combined array
  61. return array_merge($aItems, $aItemsMore);
  62. }
  63. }
  64. /** @} */