BxBaseModProfileMenuManageTools.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Manage tools submenu
  13. */
  14. class BxBaseModProfileMenuManageTools extends BxBaseModGeneralMenuManageTools
  15. {
  16. public function __construct($aObject, $oTemplate = false)
  17. {
  18. parent::__construct($aObject, $oTemplate);
  19. }
  20. /**
  21. * Check if menu items is visible.
  22. * @param $a menu item array
  23. * @return boolean
  24. */
  25. protected function _isVisible ($a)
  26. {
  27. if(!parent::_isVisible($a))
  28. return false;
  29. if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
  30. return false;
  31. $sCheckFuncName = '';
  32. $aCheckFuncParams = [];
  33. switch ($a['name']) {
  34. case 'clear-reports':
  35. case 'manage-cf':
  36. $sCheckFuncName = 'checkAllowedEditAnyEntry';
  37. break;
  38. case 'delete':
  39. case 'delete-with-content':
  40. if($this->_oModule->checkMyself($this->_iContentId))
  41. return false;
  42. $oProfile = $this->_oModule->getProfileObject(($this->_iContentId));
  43. if (!$this->_oModule->isAllowDeleteOrDisable(bx_get_logged_profile_id(), $oProfile->id()))
  44. return false;
  45. $sCheckFuncName = 'checkAllowedDelete';
  46. $aCheckFuncParams = [&$this->_aContentInfo];
  47. break;
  48. }
  49. if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))
  50. return true;
  51. return call_user_func_array([$this->_oModule, $sCheckFuncName], $aCheckFuncParams) === CHECK_ACTION_RESULT_ALLOWED;
  52. }
  53. }
  54. /** @} */