19 $queryResult = $this->getBaseQuery()->fetchAll();
22 foreach ($queryResult as $invitationFields)
24 $invitations->add($this->buildInvitation($invitationFields));
30 private function getBaseQuery():
Query
32 return UserToGroupTable::query()
36 'INITIATED_BY_USER_ID',
37 'SENDER_NAME' =>
'SENDER.NAME',
38 'SENDER_LAST_NAME' =>
'SENDER.LAST_NAME',
39 'SENDER_SECOND_NAME' =>
'SENDER.SECOND_NAME',
41 ->where(
'USER_ID', $this->userId)
44 ->registerRuntimeField(
49 Join::on(
'this.INITIATED_BY_USER_ID',
'ref.ID'),
50 [
'join_type' => Join::TYPE_INNER]
55 private function buildInvitation(array $invitationFields): Invitation
57 $nameFormat = \Bitrix\Main\Application::getInstance()->getContext()->getCulture()->getNameFormat();
58 $invitation = (
new Invitation());
61 'NAME' => $invitationFields[
'SENDER_NAME'],
62 'LAST_NAME' => $invitationFields[
'SENDER_LAST_NAME'],
63 'SECOND_NAME' => $invitationFields[
'SENDER_SECOND_NAME'],
65 $formattedName = \CUser::FormatName($nameFormat, $senderData);
66 $sender =
new Sender((
int)$invitationFields[
'INITIATED_BY_USER_ID'], $formattedName);
70 ->setReceiverId($this->userId)
71 ->setSpaceId((
int)$invitationFields[
'GROUP_ID'])
73 if ($invitationFields[
'DATE_UPDATE'] instanceof
DateTime)
75 $invitation->setInviteDate($invitationFields[
'DATE_UPDATE']);
85 ->where(
'GROUP_ID', $spaceId)
89 return !empty($queryResult) ? $this->buildInvitation($queryResult) :
null;