BxGroupsModule.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /**
  64. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  65. */
  66. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  67. {
  68. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  69. }
  70. /**
  71. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  72. */
  73. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  74. {
  75. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  76. return CHECK_ACTION_RESULT_ALLOWED;
  77. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  78. }
  79. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  80. {
  81. $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
  82. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  83. }
  84. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  85. {
  86. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  87. return CHECK_ACTION_RESULT_ALLOWED;
  88. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  89. }
  90. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  91. {
  92. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  93. return CHECK_ACTION_RESULT_ALLOWED;
  94. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  95. }
  96. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  97. {
  98. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  99. return CHECK_ACTION_RESULT_ALLOWED;
  100. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  101. }
  102. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  103. {
  104. $sResult = $this->checkAllowedView($aDataEntry);
  105. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult)
  106. return $sResult;
  107. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  108. }
  109. }
  110. /** @} */