3declare(strict_types=1);
5namespace Bitrix\Socialnetwork\Collab\Control\Invite;
7use Bitrix\Main\Config\Option;
8use Bitrix\Main\DI\ServiceLocator;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\Main\Result;
12use Bitrix\Main\Validation\ValidationService;
13use Bitrix\Socialnetwork\Collab\Collab;
14use Bitrix\Socialnetwork\Collab\Control\Invite\Command\InvitationCommand;
15use Bitrix\Socialnetwork\Collab\Permission\UserRole;
16use Bitrix\Socialnetwork\Collab\Registry\CollabRegistry;
17use Bitrix\Socialnetwork\Collab\User\User;
18use Bitrix\Socialnetwork\UserToGroupTable;
24 protected const REQUEST_URL =
'/company/personal/user/#USER_ID#/requests/';
42 $validationResult = $this->validationService->validate($command);
43 if (!$validationResult->isSuccess())
45 return $validationResult;
48 $this->sender =
new User($command->getInitiatorId());
49 $this->recipient =
new User($command->getRecipientId());
50 $collab = CollabRegistry::getInstance()->get($command->getCollabId());
58 $this->relationId = $command->hasRelationId() ? $command->getRelationId() : $this->
getRelationId();
60 if ($this->relationId <= 0)
62 $result->addError(
new Error(
'No relation',
'INVITE_NO_RELATION'));
70 if ($messageResult ===
false)
81 $result->addError(
new Error(
'Invite is not sent',
'INVITE_NOT_SENT'));
90 return function(?
string $languageId =
null):
string {
92 $title = Loc::getMessage(
'SONET_COLLAB_INVITE_TEXT', [
93 '#NAME#' => $this->collab->getName(),
96 $confirm = Loc::getMessage(
'SONET_COLLAB_INVITE_CONFIRM',
null, $languageId)
100 $reject = Loc::getMessage(
'SONET_COLLAB_INVITE_REJECT',
null, $languageId)
104 return "{$title}\n\n{$confirm}\n\n{$reject}";
110 $confirmValue = $confirm ?
'Y' :
'N';
112 return "{$this->getRequestUrl()}?INVITE_GROUP={$this->relationId}&CONFIRM={$confirmValue}";
119 "TO_USER_ID" => $this->recipient->getId(),
120 "FROM_USER_ID" => $this->sender->getId(),
122 "NOTIFY_MODULE" =>
"socialnetwork",
123 "NOTIFY_EVENT" =>
"invite_group_btn",
134 return "SOCNET|INVITE_GROUP|{$this->recipient->getId()}|{$this->relationId}";
139 return fn(?
string $languageId =
null):
string => Loc::getMessage(
'SONET_COLLAB_INVITE_TEXT', [
140 '#NAME#' => rtrim(mb_substr($this->collab->getName(), 0, static::MAX_NOTIFY_LENGTH),
'.') .
'...',
146 return fn(?
string $languageId =
null):
string => Loc::getMessage(
'SONET_COLLAB_INVITE_TEXT', [
147 '#NAME#' => $this->collab->getName(),
155 'TITLE' =>
static fn(?
string $languageId =
null):
string => Loc::getMessage(
156 'SONET_COLLAB_INVITE_CONFIRM',
164 'TITLE' =>
static fn(?
string $languageId =
null):
string => Loc::getMessage(
165 'SONET_COLLAB_INVITE_REJECT',
183 return str_replace([
"#USER_ID#",
"#user_id#"], (
string)$this->recipient->getId(), $requestUrl);
188 $row = UserToGroupTable::query()
190 ->where(
'GROUP_ID', $this->collab->getId())
191 ->where(
'USER_ID', $this->recipient->getId())
192 ->where(
'ROLE', UserRole::REQUEST)
201 return (
int)$row[
'ID'];
204 protected function init(): void
206 $this->validationService = ServiceLocator::getInstance()->get(
'main.validation.service');
ValidationService $validationService
send(InvitationCommand $command)
getActionLink(bool $confirm=true)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)