BxBaseModGroupsFormsEntryHelper.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Group profile forms functions
  13. */
  14. class BxBaseModGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
  15. {
  16. public function __construct($oModule)
  17. {
  18. parent::__construct($oModule);
  19. }
  20. protected function _getProfileAndContentData ($iContentId)
  21. {
  22. $CNF = &$this->_oModule->_oConfig->CNF;
  23. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  24. if(!$aContentInfo)
  25. return array(false, false);
  26. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo[$CNF['FIELD_AUTHOR']]);
  27. return array($oProfile, $aContentInfo);
  28. }
  29. protected function _processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile)
  30. {
  31. $sMsg = parent::_processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile);
  32. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  33. if ($sMsg && $oPrivacy->isPartiallyVisible($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]))
  34. return '';
  35. return $sMsg;
  36. }
  37. public function onDataAddAfter ($iAccountId, $iContentId)
  38. {
  39. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  40. return $s;
  41. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName())))
  42. return '';
  43. $this->makeAuthorAdmin ($oGroupProfile, bx_get('initial_members'));
  44. $this->inviteMembers ($oGroupProfile, bx_get('initial_members'));
  45. return '';
  46. }
  47. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  48. {
  49. if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
  50. return $s;
  51. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName())))
  52. return '';
  53. $this->inviteMembers ($oGroupProfile, bx_get('initial_members'));
  54. if (bx_get('key')){
  55. $sKey = bx_get('key');
  56. $aData = $this->_oModule->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  57. if (isset($aData['invited_profile_id'])){
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  60. return '';
  61. $iInvitedProfileId = $aData['invited_profile_id'];
  62. if($oConnection && !$oConnection->isConnected($iInvitedProfileId, $oGroupProfile->id())){
  63. $oConnection->addConnection($iInvitedProfileId, $oGroupProfile->id());
  64. $oConnection->addConnection($oGroupProfile->id(), $iInvitedProfileId);
  65. $this->_oModule->_oDb->deleteInviteByKey($sKey, $oGroupProfile->id(), 'date_join', time());
  66. }
  67. }
  68. }
  69. return '';
  70. }
  71. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  72. {
  73. $CNF = &$this->_oModule->_oConfig->CNF;
  74. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
  75. if ($oGroupProfile && isset($CNF['TABLE_ADMINS']))
  76. $this->_oModule->_oDb->deleteAdminsByGroupId($oGroupProfile->id());
  77. if (isset($CNF['OBJECT_CONNECTIONS']) && $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  78. $oConnection->onDeleteInitiatorAndContent($oGroupProfile->id());
  79. if(($oPrivacyView = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  80. $oPrivacyView->deleteGroupCustomByContentId($iContentId);
  81. if(($oPrivacyPost = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST'])) !== false)
  82. $oPrivacyPost->deleteGroupCustomByContentId($iContentId);
  83. return '';
  84. }
  85. protected function inviteMembers ($oGroupProfile, $aInitialProfiles)
  86. {
  87. if (!$aInitialProfiles)
  88. return;
  89. // insert invited members, so they will join without confirmation
  90. foreach ($aInitialProfiles as $iProfileId) {
  91. if (!($oProfile = BxDolProfile::getInstance($iProfileId)))
  92. continue;
  93. $this->_oModule->serviceAddMutualConnection ($oGroupProfile->id(), $oProfile->id(), true);
  94. }
  95. }
  96. /**
  97. * Make author admin if their is in initial invitations list
  98. * @param $oGroupProfile group id
  99. * @param $aInitialProfiles array of initial profile ids
  100. * @return nothing
  101. */
  102. protected function makeAuthorAdmin ($oGroupProfile, $aInitialProfiles)
  103. {
  104. $CNF = &$this->_oModule->_oConfig->CNF;
  105. $iAdminProfileId = bx_get_logged_profile_id();
  106. if (!isset($CNF['OBJECT_CONNECTIONS']) || !$CNF['OBJECT_CONNECTIONS'] || !is_array($aInitialProfiles) || !in_array($iAdminProfileId, $aInitialProfiles))
  107. return;
  108. if (!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  109. return;
  110. if (!$oConnection->isConnected($oGroupProfile->id(), (int)$iAdminProfileId))
  111. $oConnection->addConnection($oGroupProfile->id(), (int)$iAdminProfileId);
  112. if (!$oConnection->isConnected((int)$iAdminProfileId, $oGroupProfile->id()))
  113. $oConnection->addConnection((int)$iAdminProfileId, $oGroupProfile->id());
  114. if (!$this->_oModule->_oDb->isAdmin ($oGroupProfile->id(), $iAdminProfileId))
  115. $this->_oModule->_oDb->toAdmins ($oGroupProfile->id(), $iAdminProfileId);
  116. }
  117. }
  118. /** @} */