BxBaseModGroupsFormsEntryHelper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 _processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile)
  21. {
  22. $sMsg = parent::_processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile);
  23. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  24. if ($sMsg && $oPrivacy->isPartiallyVisible($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]))
  25. return '';
  26. return $sMsg;
  27. }
  28. public function onDataAddAfter ($iAccountId, $iContentId)
  29. {
  30. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  31. return $s;
  32. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName())))
  33. return '';
  34. $this->inviteMembers ($oGroupProfile, bx_get('initial_members'));
  35. return '';
  36. }
  37. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  38. {
  39. if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
  40. return $s;
  41. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName())))
  42. return '';
  43. $this->inviteMembers ($oGroupProfile, bx_get('initial_members'));
  44. return '';
  45. }
  46. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  47. {
  48. $CNF = &$this->_oModule->_oConfig->CNF;
  49. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
  50. if ($oGroupProfile)
  51. $this->_oModule->_oDb->deleteAdminsByGroupId($oGroupProfile->id());
  52. if (isset($CNF['OBJECT_CONNECTIONS']) && $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  53. $oConnection->onDeleteInitiatorAndContent($oGroupProfile->id());
  54. return '';
  55. }
  56. protected function inviteMembers ($oGroupProfile, $aInitialProfiles)
  57. {
  58. if (!$aInitialProfiles)
  59. return;
  60. // insert invited members, so they will join without confirmation
  61. foreach ($aInitialProfiles as $iProfileId) {
  62. if (!($oProfile = BxDolProfile::getInstance($iProfileId)))
  63. continue;
  64. $this->_oModule->serviceAddMutualConnection ($oGroupProfile->id(), $oProfile->id(), true);
  65. }
  66. }
  67. }
  68. /** @} */