BxGroupsModule.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 Groups Groups
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Groups profiles module.
  13. */
  14. class BxGroupsModule extends BxBaseModProfileModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. /**
  21. * Get possible recipients for start conversation form
  22. */
  23. public function actionAjaxGetInitialMembers ()
  24. {
  25. $sTerm = bx_get('term');
  26. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  27. header('Content-Type:text/javascript; charset=utf-8');
  28. echo(json_encode($a));
  29. }
  30. public function serviceActAsProfile ()
  31. {
  32. return false;
  33. }
  34. public function servicePrepareFields ($aFieldsProfile)
  35. {
  36. $aFieldsProfile['group_name'] = $aFieldsProfile['name'];
  37. $aFieldsProfile['group_desc'] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  38. unset($aFieldsProfile['name']);
  39. unset($aFieldsProfile['description']);
  40. return $aFieldsProfile;
  41. }
  42. public function serviceAddMutualConnection ($iContentId, $iInitiatorId, $iIgnoreJoinConfirmation = false)
  43. {
  44. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  45. if (!$aContentInfo || (!$iIgnoreJoinConfirmation && $aContentInfo['join_confirmation']))
  46. return false;
  47. if (!($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])))
  48. return false;
  49. return $oConnection->addConnection((int)$iContentId, (int)$iInitiatorId);
  50. }
  51. public function serviceFansTable ()
  52. {
  53. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  54. if (!$oGrid)
  55. return false;
  56. return $oGrid->getCode();
  57. }
  58. public function serviceFans ($iContentId = 0)
  59. {
  60. if (!$iContentId)
  61. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  62. if (!$iContentId)
  63. return false;
  64. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  65. if (!$aContentInfo)
  66. return false;
  67. bx_import('BxDolConnection');
  68. $s = $this->serviceBrowseConnectionsQuick ($iContentId, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  69. if (!$s)
  70. return MsgBox(_t('_sys_txt_empty'));
  71. return $s;
  72. }
  73. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  74. {
  75. if (!$iProfileId)
  76. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  77. if (!$iProfileId)
  78. return '';
  79. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  80. }
  81. /**
  82. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  83. */
  84. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  85. {
  86. if (($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected(bx_get_logged_profile_id(), $aDataEntry[$this->_oConfig->CNF['FIELD_ID']], true))
  87. return CHECK_ACTION_RESULT_ALLOWED;
  88. return parent::checkAllowedView ($aDataEntry, $isPerformAction);
  89. }
  90. /**
  91. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  92. */
  93. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  94. {
  95. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  96. }
  97. /**
  98. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  99. */
  100. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  101. {
  102. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  103. return CHECK_ACTION_RESULT_ALLOWED;
  104. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  105. }
  106. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  107. {
  108. $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
  109. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  110. }
  111. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  112. {
  113. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  114. return CHECK_ACTION_RESULT_ALLOWED;
  115. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  116. }
  117. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  118. {
  119. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  120. return CHECK_ACTION_RESULT_ALLOWED;
  121. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  122. }
  123. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  124. {
  125. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  126. return CHECK_ACTION_RESULT_ALLOWED;
  127. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  128. }
  129. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  130. {
  131. $sResult = $this->checkAllowedView($aDataEntry);
  132. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult)
  133. return $sResult;
  134. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  135. }
  136. }
  137. /** @} */