BxOrgsModule.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 Organizations Organizations
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_ORGANIZATIONS_ACTION_SWITCH_TO_PROFILE', 'switch_to_profile');
  12. /**
  13. * Organizations profiles module.
  14. */
  15. class BxOrgsModule extends BxBaseModGroupsModule
  16. {
  17. function __construct(&$aModule)
  18. {
  19. parent::__construct($aModule);
  20. $CNF = &$this->_oConfig->CNF;
  21. $this->_aSearchableNamesExcept[] = $CNF['FIELD_AUTHOR'];
  22. $this->_aSearchableNamesExcept[] = $CNF['FIELD_JOIN_CONFIRMATION'];
  23. }
  24. /**
  25. * Check if this module entry can be used as profile
  26. */
  27. public function serviceActAsProfile ()
  28. {
  29. return true;
  30. }
  31. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  32. {
  33. if(empty($sUnitTemplate))
  34. $sUnitTemplate = 'unit_with_cover.html';
  35. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  36. }
  37. /**
  38. * @see BxBaseModProfileModule::serviceGetSpaceTitle
  39. */
  40. public function serviceGetSpaceTitle()
  41. {
  42. $aExcludeModules = explode(',', getParam('sys_hide_post_to_context_for_privacy'));
  43. if (in_array($this->_aModule['name'], $aExcludeModules))
  44. return BxBaseModProfileModule::serviceGetSpaceTitle();
  45. else
  46. return _t($this->_oConfig->CNF['T']['txt_sample_single']);
  47. }
  48. /**
  49. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  50. */
  51. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  52. {
  53. $aExcludeModules = explode(',', getParam('sys_hide_post_to_context_for_privacy'));
  54. if (false === $aConnectionObjects){
  55. if (in_array($this->_aModule['name'], $aExcludeModules)){
  56. $aConnectionObjects = array('sys_profiles_friends');
  57. }
  58. else{
  59. $aConnectionObjects = array('sys_profiles_subscriptions');
  60. if (isset($this->_oConfig->CNF['OBJECT_CONNECTIONS'])){
  61. $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
  62. }
  63. }
  64. }
  65. return BxBaseModProfileModule::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
  66. }
  67. public function servicePrepareFields ($aFieldsProfile)
  68. {
  69. $a = parent::_servicePrepareFields($aFieldsProfile, array('org_cat' => 35), array(
  70. 'org_desc' => 'description',
  71. ));
  72. if (!empty($a['fullname'])) {
  73. $a['org_name'] = $a['fullname'];
  74. unset($a['fullname']);
  75. }
  76. return $a;
  77. }
  78. public function serviceBrowseAlphabetical ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  79. {
  80. return $this->_serviceBrowse ('alphabetical', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  81. }
  82. public function serviceGetTimelineData()
  83. {
  84. return BxBaseModProfileModule::serviceGetTimelineData();
  85. }
  86. public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
  87. {
  88. if($oAlert->sAction != 'join_request' || empty($aDataItems) || !is_array($aDataItems))
  89. return $aDataItems;
  90. $aDataItem = reset($aDataItems);
  91. $aDataItem['owner_id'] = $oAlert->aExtras['performer_id'];
  92. $aDataItems[] = $aDataItem;
  93. return $aDataItems;
  94. }
  95. public function serviceGetNotificationsJoinRequest($aEvent)
  96. {
  97. $CNF = &$this->_oConfig->CNF;
  98. $sAction = 'join';
  99. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  100. if($oConnection !== false && $oConnection->isConnected($aEvent['object_owner_id'], $aEvent['owner_id'], true))
  101. $sAction = 'accept';
  102. if($aEvent['owner_id'] == $aEvent['object_owner_id'])
  103. return $this->_serviceGetNotification($aEvent, 'join_request', $CNF['T']['txt_ntfs_' . $sAction . '_request']);
  104. return $this->_serviceGetNotification($aEvent, 'join_request', $CNF['T']['txt_ntfs_' . $sAction . '_request_for_owner']);
  105. }
  106. public function onFanRemovedFromAdmins($iGroupProfileId, $iProfileId)
  107. {
  108. if (!($oProfile = BxDolProfile::getInstance($iProfileId)))
  109. return false;
  110. $oAccount = $oProfile->getAccountObject();
  111. $oAccount->updateProfileContextAuto();
  112. }
  113. public function isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId)
  114. {
  115. $bResult = parent::isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId);
  116. if(!$bResult)
  117. return $bResult;
  118. $iProfileRole = $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  119. switch($sAction) {
  120. case BX_ORGANIZATIONS_ACTION_SWITCH_TO_PROFILE:
  121. $bResult = $this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR) || $this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_MODERATOR);
  122. break;
  123. }
  124. return $bResult;
  125. }
  126. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  127. {
  128. return BxBaseModProfileModule::checkAllowedCompose ($aDataEntry, $isPerformAction);
  129. }
  130. public function checkAllowedContact($aDataEntry, $isPerformAction = false)
  131. {
  132. return BxBaseModProfileModule::checkAllowedContact($aDataEntry, $isPerformAction);
  133. }
  134. }
  135. /** @} */