1
0

BxBaseModGeneralMenuView.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. public function __construct($aObject, $oTemplate = false)
  19. {
  20. parent::__construct($aObject, $oTemplate);
  21. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  22. }
  23. /**
  24. * Check if menu items is visible with extended checking linked to "allow*" method of particular module
  25. * Associated "allow*" method with particular menu item is stored in module config in MENU_ITEM_TO_METHOD array.
  26. * @param $a menu item array
  27. * @return boolean
  28. */
  29. protected function _isVisible ($a)
  30. {
  31. // default visible settings
  32. if (!BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']))
  33. return false;
  34. $CNF = $this->_oModule->_oConfig->CNF;
  35. // get custom function name to check menu item visibility
  36. $sFuncCheckAccess = false;
  37. if (isset($CNF['MENU_ITEM_TO_METHOD'][$this->_sObject][$a['name']]))
  38. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$this->_sObject][$a['name']];
  39. // check custom visibility settings defined in module config class
  40. if ($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this->_oModule, $sFuncCheckAccess), isset($this->_aContentInfo) ? array(&$this->_aContentInfo) : array()))
  41. return false;
  42. return true;
  43. }
  44. protected function _getMenuItemsCombined ()
  45. {
  46. // combile values from ACTIONS_VIEW_ENTRY and ACTIONS_VIEW_ENTRY_MORE menus
  47. $CNF = $this->_oModule->_oConfig->CNF;
  48. if (empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  49. return array();
  50. $aItems = $this->_oQuery->getMenuItemsFromSet($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  51. if (empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  52. return $aItems;
  53. $aItemsMore = $this->_oQuery->getMenuItemsFromSet($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  54. // remove "more" item from ACTIONS_VIEW_ENTRY
  55. $aItems = array_filter ($aItems, function ($aItem) {
  56. return $aItem['order'] != BX_MENU_LAST_ITEM_ORDER;
  57. });
  58. // return combined array
  59. return array_merge($aItems, $aItemsMore);
  60. }
  61. }
  62. /** @} */