Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sms.php
1
<?php
2
namespace
Bitrix\Calendar\Sharing\Notification
;
3
4
use
Bitrix\Calendar\Sharing
;
5
use
Bitrix\Main\Loader
;
6
use Bitrix\Notifications;
7
use
Bitrix\Main\PhoneNumber
;
8
9
class
Sms
extends
Service
10
{
11
private
const
TEMPLATE_Q =
'SHARING_EVENT_INVITE'
;
12
private
const
TEMPLATE_Y =
'SHARING_EVENT_ACCEPTED'
;
13
private
const
TEMPLATE_N =
'SHARING_EVENT_DECLINED'
;
14
private
const
TEMPLATE_N_NO_LINK =
'SHARING_EVENT_DECLINED_2'
;
15
21
public
function
includeNotificationsModule
(): bool
22
{
23
if
(!
Loader::includeModule
(
'notifications'
))
24
{
25
return
false
;
26
}
27
28
return
Notifications\Account::isServiceAvailable() && Notifications\Account::isConnected();
29
}
30
31
public
function
notifyAboutMeetingStatus
(
string
$to): void
32
{
33
if
(!$this->
includeNotificationsModule
())
34
{
35
return
;
36
}
37
38
$parsedPhone = PhoneNumber\Parser::getInstance()->parse($to);
39
if
(!$parsedPhone->isValid() || mb_strtolower($parsedPhone->getCountry()) !==
'ru'
)
40
{
41
return
;
42
}
43
$phoneNumberE164 = $parsedPhone->format(
PhoneNumber
\
Format::E164
);
44
45
$owner = $this->
getOwner
();
46
47
$templateCode = $this->
getTemplateCode
($owner);
48
$calendarLink =
null
;
49
if
($templateCode === self::TEMPLATE_N)
50
{
51
$calendarLink = $this->
getShortCalendarLink
();
52
if
(is_null($calendarLink))
53
{
54
$templateCode = self::TEMPLATE_N_NO_LINK;
55
}
56
}
57
58
Notifications\Model\Message::create([
59
'PHONE_NUMBER'
=> $phoneNumberE164,
60
'TEMPLATE_CODE'
=> $templateCode,
61
'LANGUAGE_ID'
=> LANGUAGE_ID,
62
'PLACEHOLDERS'
=> $this->
getPlaceholders
($templateCode, $owner, $calendarLink),
63
])->enqueue();
64
}
65
66
protected
function
getTemplateCode
(array $owner): string
67
{
68
$templateCode = self::TEMPLATE_Q;
69
70
if
($owner[
'STATUS'
] ===
'Y'
)
71
{
72
$templateCode = self::TEMPLATE_Y;
73
}
74
75
if
($owner[
'STATUS'
] ===
'N'
)
76
{
77
$templateCode = self::TEMPLATE_N;
78
}
79
80
return
$templateCode;
81
}
82
83
protected
function
getPlaceholders
(
string
$templateCode, array $owner, ?
string
$calendarLink): array
84
{
85
$eventName = $this->
event
->getName();
86
$eventDateTime = $this->
getEventFormattedDateTime
();
87
$calendarOwner = $owner[
'NAME'
];
88
$eventLink
= Sharing\Helper::getShortUrl($this->eventLink->getUrl());
89
90
if
($templateCode === self::TEMPLATE_Q)
91
{
92
return
[
93
'EVENT_NAME'
=> $eventName,
94
'DATE'
=> $eventDateTime,
95
'NAME'
=> $calendarOwner,
96
'URL'
=>
$eventLink
,
97
'URL_EVENT'
=>
$eventLink
,
// sms parameter
98
];
99
}
100
if
($templateCode === self::TEMPLATE_Y)
101
{
102
return
[
103
'EVENT_NAME'
=> $eventName,
104
'DATE'
=> $eventDateTime,
105
'NAME'
=> $calendarOwner,
106
'URL'
=>
$eventLink
,
107
'URL_EVENT'
=>
$eventLink
,
// sms parameter
108
];
109
}
110
if
($templateCode === self::TEMPLATE_N)
111
{
112
return
[
113
'EVENT_NAME'
=> $eventName,
114
'DATE'
=> $eventDateTime,
115
'NAME'
=> $calendarOwner,
116
'URL'
=> $calendarLink,
117
'URL_EVENT'
=>
$eventLink
,
// sms parameter
118
];
119
}
120
if
($templateCode === self::TEMPLATE_N_NO_LINK)
121
{
122
return
[
123
'EVENT_NAME'
=> $eventName,
124
'DATE'
=> $eventDateTime,
125
'NAME'
=> $calendarOwner,
126
'URL_EVENT'
=>
$eventLink
,
// sms parameter
127
];
128
}
129
return
[];
130
}
131
132
protected
function
getShortCalendarLink
(): ?string
133
{
134
$calendarLink = $this->
getCalendarLink
();
135
if
(!is_null($calendarLink))
136
{
137
return
Sharing\Helper::getShortUrl($this->
getCalendarLink
());
138
}
139
140
return
null
;
141
}
142
}
Bitrix\Calendar\Sharing\Notification\Service
Definition
service.php:10
Bitrix\Calendar\Sharing\Notification\Service\getCalendarLink
getCalendarLink()
Definition
service.php:123
Bitrix\Calendar\Sharing\Notification\Service\getEventFormattedDateTime
getEventFormattedDateTime()
Definition
service.php:80
Bitrix\Calendar\Sharing\Notification\Service\getOwner
getOwner()
Definition
service.php:91
Bitrix\Calendar\Sharing\Notification\Service\$eventLink
EventLink $eventLink
Definition
service.php:12
Bitrix\Calendar\Sharing\Notification\Sms
Definition
sms.php:10
Bitrix\Calendar\Sharing\Notification\Sms\getPlaceholders
getPlaceholders(string $templateCode, array $owner, ?string $calendarLink)
Definition
sms.php:83
Bitrix\Calendar\Sharing\Notification\Sms\notifyAboutMeetingStatus
notifyAboutMeetingStatus(string $to)
Definition
sms.php:31
Bitrix\Calendar\Sharing\Notification\Sms\getShortCalendarLink
getShortCalendarLink()
Definition
sms.php:132
Bitrix\Calendar\Sharing\Notification\Sms\getTemplateCode
getTemplateCode(array $owner)
Definition
sms.php:66
Bitrix\Calendar\Sharing\Notification\Sms\includeNotificationsModule
includeNotificationsModule()
Definition
sms.php:21
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Loader\includeModule
static includeModule($moduleName)
Definition
loader.php:69
Bitrix\Main\PhoneNumber\Format\E164
const E164
Definition
format.php:7
Bitrix\Main\PhoneNumber\PhoneNumber
Definition
phonenumber.php:6
Bitrix\Calendar\Sharing\Notification
Definition
mail.php:2
Bitrix\Calendar\Sharing
Definition
analytics.php:3
Bitrix\Main\PhoneNumber
Definition
format.php:3
modules
calendar
lib
sharing
notification
sms.php
Создано системой
1.10.0