BxGroupsModule.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. /**
  35. * Delete profile from fans and admins tables
  36. * @param $iProfileId profile id
  37. */
  38. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  39. {
  40. $CNF = &$this->_oConfig->CNF;
  41. $this->_oDb->deleteAdminsByProfileId($iProfileId);
  42. if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  43. $oConnection->onDeleteInitiatorAndContent($iProfileId);
  44. }
  45. /**
  46. * Reset group's author for particular group
  47. * @param $iContentId group id
  48. * @return false of error, or number of updated records on success
  49. */
  50. public function serviceReassignEntityAuthor ($iContentId)
  51. {
  52. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  53. if (!$aContentInfo)
  54. return false;
  55. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  56. return false;
  57. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  58. return $this->_oDb->updateAuthorById($iContentId, $aAdmins ? array_pop($aAdmins) : 0);
  59. }
  60. /**
  61. * Reset group's author when author profile is deleted
  62. * @param $iProfileId profile id
  63. * @return number of changed items
  64. */
  65. public function serviceReassignEntitiesByAuthor ($iProfileId)
  66. {
  67. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  68. if (!$a)
  69. return 0;
  70. $iCount = 0;
  71. foreach ($a as $aContentInfo)
  72. $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  73. return $iCount;
  74. }
  75. public function servicePrepareFields ($aFieldsProfile)
  76. {
  77. $aFieldsProfile['group_name'] = $aFieldsProfile['name'];
  78. $aFieldsProfile['group_desc'] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  79. unset($aFieldsProfile['name']);
  80. unset($aFieldsProfile['description']);
  81. return $aFieldsProfile;
  82. }
  83. public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $iIgnoreJoinConfirmation = false)
  84. {
  85. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  86. return false;
  87. $aContentInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  88. if (!$aContentInfo || (!$iIgnoreJoinConfirmation && $aContentInfo['join_confirmation']))
  89. return false;
  90. if (!($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])))
  91. return false;
  92. return $oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId);
  93. }
  94. public function serviceFansTable ()
  95. {
  96. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  97. if (!$oGrid)
  98. return false;
  99. return $oGrid->getCode();
  100. }
  101. public function serviceFans ($iContentId = 0)
  102. {
  103. if (!$iContentId)
  104. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  105. if (!$iContentId)
  106. return false;
  107. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  108. if (!$aContentInfo)
  109. return false;
  110. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  111. return false;
  112. bx_import('BxDolConnection');
  113. $s = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  114. if (!$s)
  115. return MsgBox(_t('_sys_txt_empty'));
  116. return $s;
  117. }
  118. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  119. {
  120. if (!$iProfileId)
  121. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  122. if (!$iProfileId)
  123. return '';
  124. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  125. }
  126. /**
  127. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  128. */
  129. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  130. {
  131. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  132. if ($oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected(bx_get_logged_profile_id(), $oGroupProfile->id(), true))
  133. return CHECK_ACTION_RESULT_ALLOWED;
  134. return parent::checkAllowedView ($aDataEntry, $isPerformAction);
  135. }
  136. /**
  137. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  138. */
  139. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  140. {
  141. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  142. }
  143. /**
  144. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  145. */
  146. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  147. {
  148. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  149. return CHECK_ACTION_RESULT_ALLOWED;
  150. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  151. }
  152. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  153. {
  154. $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
  155. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  156. }
  157. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  158. {
  159. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  160. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
  161. return CHECK_ACTION_RESULT_ALLOWED;
  162. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  163. }
  164. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  165. {
  166. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  167. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
  168. return CHECK_ACTION_RESULT_ALLOWED;
  169. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  170. }
  171. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  172. {
  173. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  174. if ($oGroupProfile && $this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
  175. return CHECK_ACTION_RESULT_ALLOWED;
  176. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  177. }
  178. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  179. {
  180. $sResult = $this->checkAllowedView($aDataEntry);
  181. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult)
  182. return $sResult;
  183. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  184. }
  185. }
  186. /** @} */