BxGroupsModule.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. public function serviceActAsProfile ()
  21. {
  22. return false;
  23. }
  24. public function servicePrepareFields ($aFieldsProfile)
  25. {
  26. $aFieldsProfile['group_name'] = $aFieldsProfile['name'];
  27. $aFieldsProfile['group_desc'] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  28. unset($aFieldsProfile['name']);
  29. unset($aFieldsProfile['description']);
  30. return $aFieldsProfile;
  31. }
  32. public function serviceAddMutualConnection ($iContentId, $iInitiatorId)
  33. {
  34. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  35. if (!$aContentInfo || $aContentInfo['join_confirmation'])
  36. return false;
  37. if (!($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])))
  38. return false;
  39. return $oConnection->addConnection((int)$iContentId, (int)$iInitiatorId);
  40. }
  41. public function serviceFansTable ()
  42. {
  43. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  44. if (!$oGrid)
  45. return false;
  46. return $oGrid->getCode();
  47. }
  48. public function serviceFans ($iContentId = 0)
  49. {
  50. if (!$iContentId)
  51. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  52. if (!$iContentId)
  53. return false;
  54. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  55. if (!$aContentInfo)
  56. return false;
  57. bx_import('BxDolConnection');
  58. $s = $this->serviceBrowseConnectionsQuick ($iContentId, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  59. if (!$s)
  60. return MsgBox(_t('_sys_txt_empty'));
  61. return $s;
  62. }
  63. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  64. {
  65. if (!$iProfileId)
  66. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  67. if (!$iProfileId)
  68. return '';
  69. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  70. }
  71. /**
  72. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  73. */
  74. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  75. {
  76. if (($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected(bx_get_logged_profile_id(), $aDataEntry[$this->_oConfig->CNF['FIELD_ID']], true))
  77. return CHECK_ACTION_RESULT_ALLOWED;
  78. return parent::checkAllowedView ($aDataEntry, $isPerformAction);
  79. }
  80. /**
  81. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  82. */
  83. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  84. {
  85. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  86. }
  87. /**
  88. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  89. */
  90. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  91. {
  92. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  93. return CHECK_ACTION_RESULT_ALLOWED;
  94. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  95. }
  96. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  97. {
  98. $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
  99. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  100. }
  101. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  102. {
  103. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  104. return CHECK_ACTION_RESULT_ALLOWED;
  105. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  106. }
  107. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  108. {
  109. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  110. return CHECK_ACTION_RESULT_ALLOWED;
  111. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  112. }
  113. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  114. {
  115. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  116. return CHECK_ACTION_RESULT_ALLOWED;
  117. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  118. }
  119. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  120. {
  121. $sResult = $this->checkAllowedView($aDataEntry);
  122. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult)
  123. return $sResult;
  124. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  125. }
  126. }
  127. /** @} */