BxGroupsModule.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 ($iGroupProfileId, $iInitiatorId, $iIgnoreJoinConfirmation = false)
  43. {
  44. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  45. return false;
  46. $aContentInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  47. if (!$aContentInfo || (!$iIgnoreJoinConfirmation && $aContentInfo['join_confirmation']))
  48. return false;
  49. if (!($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])))
  50. return false;
  51. return $oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId);
  52. }
  53. public function serviceFansTable ()
  54. {
  55. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  56. if (!$oGrid)
  57. return false;
  58. return $oGrid->getCode();
  59. }
  60. public function serviceFans ($iContentId = 0)
  61. {
  62. if (!$iContentId)
  63. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  64. if (!$iContentId)
  65. return false;
  66. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  67. if (!$aContentInfo)
  68. return false;
  69. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  70. return false;
  71. bx_import('BxDolConnection');
  72. $s = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  73. if (!$s)
  74. return MsgBox(_t('_sys_txt_empty'));
  75. return $s;
  76. }
  77. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  78. {
  79. if (!$iProfileId)
  80. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  81. if (!$iProfileId)
  82. return '';
  83. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  84. }
  85. /**
  86. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  87. */
  88. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  89. {
  90. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  91. if ($oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected(bx_get_logged_profile_id(), $oGroupProfile->id(), true))
  92. return CHECK_ACTION_RESULT_ALLOWED;
  93. return parent::checkAllowedView ($aDataEntry, $isPerformAction);
  94. }
  95. /**
  96. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  97. */
  98. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  99. {
  100. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  101. }
  102. /**
  103. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  104. */
  105. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  106. {
  107. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  108. return CHECK_ACTION_RESULT_ALLOWED;
  109. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  110. }
  111. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  112. {
  113. $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
  114. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  115. }
  116. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  117. {
  118. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  119. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
  120. return CHECK_ACTION_RESULT_ALLOWED;
  121. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  122. }
  123. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  124. {
  125. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  126. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
  127. return CHECK_ACTION_RESULT_ALLOWED;
  128. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  129. }
  130. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  131. {
  132. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  133. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
  134. return CHECK_ACTION_RESULT_ALLOWED;
  135. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  136. }
  137. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  138. {
  139. $sResult = $this->checkAllowedView($aDataEntry);
  140. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult)
  141. return $sResult;
  142. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  143. }
  144. }
  145. /** @} */