BxBaseModGroupsFormsEntryHelper.php 4.3 KB

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