Skip to content

Commit

Permalink
Ticket #3643 - Groups: Invited user should be auto accepted Join Grou…
Browse files Browse the repository at this point in the history
…p button was clicked.
  • Loading branch information
AntonLV committed Jan 6, 2022
1 parent b5b88f2 commit 9f82fec
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function sendMailInvitation ($oAlert, $iInvited, $iInviter = 0)
if(!$oConnection->isConnected($iInviter, $oAlert->iSender))
return;

if($this->_oModule->_oDb->getInviteByInvited($iInvited, $oAlert->iSender) != 0)
if($this->_oModule->_oDb->isInviteByInvited($iInvited, $oAlert->iSender))
return;

$sKey = BxDolKey::getInstance()->getNewKey(false, $CNF["INVITES_KEYS_LIFETIME"]);
Expand Down
26 changes: 16 additions & 10 deletions modules/base/groups/classes/BxBaseModGroupsDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,24 +370,30 @@ public function insertInvite($sKey, $sGroupProfileId, $iAuthorProfileId, $iInvit

public function getInviteByKey($sKey, $iGroupProfileId)
{
$aBindings = array(
$CNF = &$this->_oConfig->CNF;

return $this->getRow("SELECT * FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `key` = :key AND group_profile_id = :group_profile_id", [
'key' => $sKey,
'group_profile_id' => $iGroupProfileId
);
$CNF = $this->_oConfig->CNF;
return $this->getRow("SELECT * FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `key` = :key AND group_profile_id = :group_profile_id", $aBindings);
]);
}

public function getInviteByInvited($iInvitedProfileId, $iGroupProfileId)
{
$aBindings = array(
$CNF = &$this->_oConfig->CNF;

return $this->getRow("SELECT * FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `invited_profile_id` = :invited_profile_id AND group_profile_id = :group_profile_id", [
'invited_profile_id' => $iInvitedProfileId,
'group_profile_id' => $iGroupProfileId
);
$CNF = $this->_oConfig->CNF;
return $this->getOne("SELECT COUNT(*) FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `invited_profile_id` = :invited_profile_id AND group_profile_id = :group_profile_id", $aBindings);
]);
}


public function isInviteByInvited($iInvitedProfileId, $iGroupProfileId)
{
$aInvite = $this->getInviteByInvited($iInvitedProfileId, $iGroupProfileId);
return !empty($aInvite) && is_array($aInvite);
}

public function updateInviteByKey($sKey, $iGroupProfileId, $sColumn, $sValue)
{
$aBindings = array(
Expand Down
20 changes: 17 additions & 3 deletions modules/base/groups/classes/BxBaseModGroupsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1514,19 +1514,33 @@ public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
return false;
}

public function isInvited ($sKey, $iProfileId)
public function isInvited ($sKey, $iGroupProfileId)
{
$CNF = &$this->_oConfig->CNF;
$aData = $this->_oDb->getInviteByKey($sKey, $iProfileId);
$aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
if (!isset($aData['invited_profile_id']))
return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);

if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);

return true;
}

public function isInvitedByProfileId ($iProfileId, $iGroupProfileId)
{
$CNF = &$this->_oConfig->CNF;

$aData = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
if (!isset($aData['invited_profile_id']))
return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);

if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);

return true;
}

public function getRole($iGroupProfileId, $iFanProfileId)
{
if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
Expand Down
40 changes: 23 additions & 17 deletions modules/base/groups/classes/BxBaseModGroupsPageEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,38 @@ public function getCode ()
{
$CNF = &$this->_oModule->_oConfig->CNF;

$sRv = '';
$sKey = '';
if(!empty($CNF['TABLE_INVITES']) && ($sKey = bx_get('key')) !== false) {
$sId = $this->_oModule->getName() . '_popup_invite';
$sInvitation = '';
if(!empty($CNF['TABLE_INVITES'])) {
$sKey = '';
$iGroupProfileId = $this->_oProfile->id();

if(($sKey = bx_get('key')) !== false)
$mixedInvited = $this->_oModule->isInvited($sKey, $iGroupProfileId);
else if(($iProfileId = bx_get_logged_profile_id()) !== false)
$mixedInvited = $this->_oModule->isInvitedByProfileId($iProfileId, $iGroupProfileId);

$mixedInvited = $this->_oModule->isInvited($sKey, $this->_oProfile->id());
if ($mixedInvited === true) {
$sRv = $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
$sId = $this->_oModule->getName() . '_popup_invite';

$this->_oTemplate->addJs(array('invite_popup.js'));

$sInvitation .= $this->_oModule->_oTemplate->getJsCode('invite_popup', array(
'sPopupId' => $sId,
'sKey' => $sKey,
'sAcceptUrl' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aProfileInfo['content_id']),
'sDeclineUrl' => BX_DOL_URL_ROOT,
'iGroupProfileId' => $this->_oProfile->id(),
));
$sInvitation .= BxTemplFunctions::getInstance()->popupBox($sId, _t($CNF['T']['txt_invitation_popup_title']), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
'popup_id' => $sId,
'text' => _t($CNF['T']['txt_invitation_popup_text']),
'button_accept' => _t($CNF['T']['txt_invitation_popup_accept_button']),
'button_decline' => _t($CNF['T']['txt_invitation_popup_decline_button']),
));
)), true);
}
else
$sRv = $mixedInvited;
}

$this->_oTemplate->addJs(array('invite_popup.js'));
return ($sRv != '' ? $this->_oModule->_oTemplate->getJsCode('invite_popup', array(
'sPopupId' => $sId,
'sKey' => $sKey,
'sAcceptUrl' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aProfileInfo['content_id']),
'sDeclineUrl' => BX_DOL_URL_ROOT,
'iGroupProfileId' => $this->_oProfile->id(),
)) . BxTemplFunctions::getInstance()->popupBox($sId, _t($CNF['T']['txt_invitation_popup_title']), $sRv, true) : '') . parent::getCode();
return $sInvitation . parent::getCode();
}
}

Expand Down

0 comments on commit 9f82fec

Please sign in to comment.