BxGroupsModule.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. $oConnection = BxDolConnection::getObjectInstance('bx_groups_fans');
  38. return $oConnection->addConnection((int)$iContentId, (int)$iInitiatorId);
  39. }
  40. public function serviceFansTable ()
  41. {
  42. $oGrid = BxDolGrid::getObjectInstance('bx_groups_fans');
  43. if (!$oGrid)
  44. return false;
  45. return $oGrid->getCode();
  46. }
  47. public function serviceFans ($iContentId = 0)
  48. {
  49. if (!$iContentId)
  50. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  51. if (!$iContentId)
  52. return false;
  53. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  54. if (!$aContentInfo)
  55. return false;
  56. bx_import('BxDolConnection');
  57. $s = $this->serviceBrowseConnectionsQuick ($iContentId, 'bx_groups_fans', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  58. if (!$s)
  59. return MsgBox(_t('_sys_txt_empty'));
  60. return $s;
  61. }
  62. /**
  63. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  64. */
  65. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  66. {
  67. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, 'bx_groups_fans', true, false);
  68. }
  69. /**
  70. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  71. */
  72. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  73. {
  74. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  75. return CHECK_ACTION_RESULT_ALLOWED;
  76. return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, 'bx_groups_fans', false, true, false);
  77. }
  78. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  79. {
  80. $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
  81. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  82. }
  83. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  84. {
  85. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  86. return CHECK_ACTION_RESULT_ALLOWED;
  87. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  88. }
  89. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  90. {
  91. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  92. return CHECK_ACTION_RESULT_ALLOWED;
  93. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  94. }
  95. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  96. {
  97. if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
  98. return CHECK_ACTION_RESULT_ALLOWED;
  99. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  100. }
  101. }
  102. /** @} */