1
0

BxBaseModGroupsFormsEntryHelper.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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->makeAuthorAdmin ($oGroupProfile, bx_get('initial_members'));
  35. $this->inviteMembers ($oGroupProfile, bx_get('initial_members'));
  36. return '';
  37. }
  38. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  39. {
  40. if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
  41. return $s;
  42. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName())))
  43. return '';
  44. $this->inviteMembers ($oGroupProfile, bx_get('initial_members'));
  45. return '';
  46. }
  47. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  48. {
  49. $CNF = &$this->_oModule->_oConfig->CNF;
  50. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
  51. if ($oGroupProfile && isset($CNF['TABLE_ADMINS']))
  52. $this->_oModule->_oDb->deleteAdminsByGroupId($oGroupProfile->id());
  53. if (isset($CNF['OBJECT_CONNECTIONS']) && $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  54. $oConnection->onDeleteInitiatorAndContent($oGroupProfile->id());
  55. return '';
  56. }
  57. protected function inviteMembers ($oGroupProfile, $aInitialProfiles)
  58. {
  59. if (!$aInitialProfiles)
  60. return;
  61. // insert invited members, so they will join without confirmation
  62. foreach ($aInitialProfiles as $iProfileId) {
  63. if (!($oProfile = BxDolProfile::getInstance($iProfileId)))
  64. continue;
  65. $this->_oModule->serviceAddMutualConnection ($oGroupProfile->id(), $oProfile->id(), true);
  66. }
  67. }
  68. /**
  69. * Make author admin if their is in initial invitations list
  70. * @param $oGroupProfile group id
  71. * @param $aInitialProfiles array of initial profile ids
  72. * @return nothing
  73. */
  74. protected function makeAuthorAdmin ($oGroupProfile, $aInitialProfiles)
  75. {
  76. $CNF = &$this->_oModule->_oConfig->CNF;
  77. $iAdminProfileId = bx_get_logged_profile_id();
  78. if (!isset($CNF['OBJECT_CONNECTIONS']) || !$CNF['OBJECT_CONNECTIONS'] || !is_array($aInitialProfiles) || !in_array($iAdminProfileId, $aInitialProfiles))
  79. return;
  80. if (!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  81. return;
  82. if (!$oConnection->isConnected($oGroupProfile->id(), (int)$iAdminProfileId))
  83. $oConnection->addConnection($oGroupProfile->id(), (int)$iAdminProfileId);
  84. if (!$oConnection->isConnected((int)$iAdminProfileId, $oGroupProfile->id()))
  85. $oConnection->addConnection((int)$iAdminProfileId, $oGroupProfile->id());
  86. if (!$this->_oModule->_oDb->isAdmin ($oGroupProfile->id(), $iAdminProfileId))
  87. $this->_oModule->_oDb->toAdmins ($oGroupProfile->id(), $iAdminProfileId);
  88. }
  89. }
  90. /** @} */