BxBaseModGroupsConnectionFans.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 Groups Groups
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsConnectionFans extends BxTemplConnection
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct($aObject)
  16. {
  17. parent::__construct($aObject);
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. }
  20. public function getActionTitle ($sAction, $iInitiatorId, $iContentId, $bFlip = false)
  21. {
  22. $aResult = [];
  23. if($this->isConnectedNotMutual($iInitiatorId, $iContentId))
  24. $aResult = [
  25. 'add' => '',
  26. 'remove' => _t('_sys_menu_item_title_sm_leave_cancel'),
  27. ];
  28. else if($this->isConnectedNotMutual($iContentId, $iInitiatorId))
  29. $aResult = [
  30. 'add' => _t('_sys_menu_item_title_sm_join_confirm'),
  31. 'remove' => _t('_sys_menu_item_title_sm_leave_reject'),
  32. ];
  33. else if($this->isConnected($iInitiatorId, $iContentId, true))
  34. $aResult = [
  35. 'add' => '',
  36. 'remove' => _t('_sys_menu_item_title_sm_leave'),
  37. ];
  38. else
  39. $aResult = [
  40. 'add' => _t('_sys_menu_item_title_sm_join'),
  41. 'remove' => '',
  42. ];
  43. $aFlip = ['add' => 'remove', 'remove' => 'add'];
  44. if($bFlip)
  45. $sAction = $aFlip[$sAction];
  46. return !empty($aResult[$sAction]) ? _t($aResult[$sAction]) : '';
  47. }
  48. protected function _checkAllowedConnectInitiator ($oInitiator, $isPerformAction = false)
  49. {
  50. if(!bx_srv($oInitiator->getModule(), 'act_as_profile'))
  51. return CHECK_ACTION_RESULT_ALLOWED;
  52. return parent::_checkAllowedConnectInitiator($oInitiator, $isPerformAction);
  53. }
  54. public function _checkAllowedConnectContent ($oContent)
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. if(bx_srv($oContent->getModule(), 'act_as_profile'))
  58. return CHECK_ACTION_RESULT_ALLOWED;
  59. if(!empty($CNF['OBJECT_PRIVACY_VIEW']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false) {
  60. $iContentId = $oContent->getContentId();
  61. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  62. if(in_array($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), ['s'])))
  63. return CHECK_ACTION_RESULT_ALLOWED;
  64. }
  65. return parent::_checkAllowedConnectContent($oContent);
  66. }
  67. }
  68. /** @} */