BxBaseModGroupsFormsEntryHelper.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. return '';
  55. }
  56. protected function redirectAfterEdit($aContentInfo)
  57. {
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. if (bx_get('initial_members') && isset($CNF['URL_ENTRY_FANS'])){
  60. $this->_redirectAndExit($CNF['URL_ENTRY_FANS'] . '&profile_id=' . $aContentInfo['profile_id']);
  61. }
  62. else{
  63. $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  64. }
  65. }
  66. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  67. {
  68. $CNF = &$this->_oModule->_oConfig->CNF;
  69. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
  70. if ($oGroupProfile && isset($CNF['TABLE_ADMINS']))
  71. $this->_oModule->_oDb->deleteAdminsByGroupId($oGroupProfile->id());
  72. if (isset($CNF['OBJECT_CONNECTIONS']) && $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  73. $oConnection->onDeleteInitiatorAndContent($oGroupProfile->id());
  74. if(($oPrivacyView = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  75. $oPrivacyView->deleteGroupCustomByContentId($iContentId);
  76. if(($oPrivacyPost = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST'])) !== false)
  77. $oPrivacyPost->deleteGroupCustomByContentId($iContentId);
  78. return '';
  79. }
  80. protected function inviteMembers ($oGroupProfile, $aInitialProfiles)
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. if(empty($CNF['OBJECT_CONNECTIONS']) || !$aInitialProfiles)
  84. return;
  85. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  86. if(!$oConnection)
  87. return;
  88. $iGroupId = $oGroupProfile->id();
  89. // insert invited members, so they will join without confirmation
  90. foreach($aInitialProfiles as $iProfileId) {
  91. $oProfile = BxDolProfile::getInstance($iProfileId);
  92. if(!$oProfile)
  93. continue;
  94. if($oConnection->isConnected($iGroupId, $iProfileId, true) || $oConnection->isConnected($iGroupId, $iProfileId))
  95. continue;
  96. $this->_oModule->serviceAddMutualConnection ($iGroupId, $iProfileId, true);
  97. }
  98. }
  99. /**
  100. * Make author admin if their is in initial invitations list
  101. * @param $oGroupProfile group id
  102. * @param $aInitialProfiles array of initial profile ids
  103. * @return nothing
  104. */
  105. protected function makeAuthorAdmin ($oGroupProfile, $aInitialProfiles)
  106. {
  107. $this->makeAdmin (bx_get_logged_profile_id(), $oGroupProfile, $aInitialProfiles);
  108. }
  109. /**
  110. * Make profile admin if he is in initial invitations list
  111. * @param $iProfileId profile id
  112. * @param $oGroupProfile group id
  113. * @param $aInitialProfiles array of initial profile ids
  114. * @return nothing
  115. */
  116. protected function makeAdmin ($iProfileId, $oGroupProfile, $aInitialProfiles)
  117. {
  118. $CNF = &$this->_oModule->_oConfig->CNF;
  119. if (!isset($CNF['OBJECT_CONNECTIONS']) || !$CNF['OBJECT_CONNECTIONS'] || !is_array($aInitialProfiles) || !in_array($iProfileId, $aInitialProfiles))
  120. return;
  121. if (!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  122. return;
  123. if (!$oConnection->isConnected($oGroupProfile->id(), (int)$iProfileId))
  124. $oConnection->addConnection($oGroupProfile->id(), (int)$iProfileId);
  125. if (!$oConnection->isConnected((int)$iProfileId, $oGroupProfile->id()))
  126. $oConnection->addConnection((int)$iProfileId, $oGroupProfile->id());
  127. if (!$this->_oModule->_oDb->isAdmin ($oGroupProfile->id(), $iProfileId))
  128. $this->_oModule->_oDb->toAdmins ($oGroupProfile->id(), $iProfileId);
  129. }
  130. }
  131. /** @} */