BxPersonsMenuViewPerson.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Persons Persons
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplMenu');
  12. /**
  13. * 'View person' menu.
  14. */
  15. class BxPersonsMenuViewPerson extends BxTemplMenu {
  16. protected $_aContentInfo;
  17. protected $_oModule;
  18. public function __construct($aObject, $oTemplate = false) {
  19. parent::__construct($aObject, $oTemplate);
  20. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  21. $this->_oModule = BxDolModule::getInstance('bx_persons');
  22. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  23. if ($this->_aContentInfo) {
  24. $oProfileAuthor = BxDolProfile::getInstance($this->_aContentInfo[BxPersonsConfig::$FIELD_AUTHOR]);
  25. $oProfile = $oProfileAuthor ? BxDolProfile::getInstanceByContentTypeAccount($iContentId, 'bx_persons', $oProfileAuthor->getAccountId()) : false;
  26. $this->addMarkers(array(
  27. 'content_id' => $this->_aContentInfo['id'],
  28. 'profile_id' => $oProfile ? $oProfile->id() : 0
  29. ));
  30. }
  31. }
  32. /**
  33. * Check if menu items is visible.
  34. * @param $a menu item array
  35. * @return boolean
  36. */
  37. protected function _isVisible ($a) {
  38. // default visible settings
  39. bx_import('BxDolAcl');
  40. if (!BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']))
  41. return false;
  42. // don't show current item, also this will solve problem when only one view note item is visible
  43. if ('bx_persons_view' == $this->_sObject && $this->_isSelected($a))
  44. return false;
  45. $sFuncCheckAccess = false;
  46. switch ($a['name']) {
  47. case 'view-persons-profile':
  48. $sFuncCheckAccess = 'isAllowedView';
  49. break;
  50. case 'edit-persons-profile':
  51. $sFuncCheckAccess = 'isAllowedEdit';
  52. break;
  53. case 'delete-persons-profile':
  54. $sFuncCheckAccess = 'isAllowedDelete';
  55. break;
  56. case 'profile-connect-add':
  57. $sFuncCheckAccess = 'isAllowedConnectAdd';
  58. break;
  59. case 'profile-connect-remove':
  60. $sFuncCheckAccess = 'isAllowedConnectRemove';
  61. break;
  62. case 'profile-subscribe-add':
  63. $sFuncCheckAccess = 'isAllowedSubscribeAdd';
  64. break;
  65. case 'profile-subscribe-remove':
  66. $sFuncCheckAccess = 'isAllowedSubscribeRemove';
  67. break;
  68. }
  69. return $sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFuncCheckAccess($this->_aContentInfo) ? true : false;
  70. }
  71. }
  72. /** @} */