BxBaseModGroupsFormsEntryHelper.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  57. {
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
  60. if ($oGroupProfile && isset($CNF['TABLE_ADMINS']))
  61. $this->_oModule->_oDb->deleteAdminsByGroupId($oGroupProfile->id());
  62. if (isset($CNF['OBJECT_CONNECTIONS']) && $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  63. $oConnection->onDeleteInitiatorAndContent($oGroupProfile->id());
  64. if(($oPrivacyView = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  65. $oPrivacyView->deleteGroupCustomByContentId($iContentId);
  66. if(($oPrivacyPost = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST'])) !== false)
  67. $oPrivacyPost->deleteGroupCustomByContentId($iContentId);
  68. return '';
  69. }
  70. protected function inviteMembers ($oGroupProfile, $aInitialProfiles)
  71. {
  72. if (!$aInitialProfiles)
  73. return;
  74. // insert invited members, so they will join without confirmation
  75. foreach ($aInitialProfiles as $iProfileId) {
  76. if (!($oProfile = BxDolProfile::getInstance($iProfileId)))
  77. continue;
  78. $this->_oModule->serviceAddMutualConnection ($oGroupProfile->id(), $oProfile->id(), true);
  79. }
  80. }
  81. /**
  82. * Make author admin if their is in initial invitations list
  83. * @param $oGroupProfile group id
  84. * @param $aInitialProfiles array of initial profile ids
  85. * @return nothing
  86. */
  87. protected function makeAuthorAdmin ($oGroupProfile, $aInitialProfiles)
  88. {
  89. $CNF = &$this->_oModule->_oConfig->CNF;
  90. $iAdminProfileId = bx_get_logged_profile_id();
  91. if (!isset($CNF['OBJECT_CONNECTIONS']) || !$CNF['OBJECT_CONNECTIONS'] || !is_array($aInitialProfiles) || !in_array($iAdminProfileId, $aInitialProfiles))
  92. return;
  93. if (!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  94. return;
  95. if (!$oConnection->isConnected($oGroupProfile->id(), (int)$iAdminProfileId))
  96. $oConnection->addConnection($oGroupProfile->id(), (int)$iAdminProfileId);
  97. if (!$oConnection->isConnected((int)$iAdminProfileId, $oGroupProfile->id()))
  98. $oConnection->addConnection((int)$iAdminProfileId, $oGroupProfile->id());
  99. if (!$this->_oModule->_oDb->isAdmin ($oGroupProfile->id(), $iAdminProfileId))
  100. $this->_oModule->_oDb->toAdmins ($oGroupProfile->id(), $iAdminProfileId);
  101. }
  102. }
  103. /** @} */