1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
event.php
См. документацию.
1
<?php
8
namespace
Bitrix\Main\Sms
;
9
10
use
Bitrix\Main
;
11
use
Bitrix\Main\ORM\Query\Query
;
12
13
class
Event
14
{
15
const
ERR_SITE
=
'site'
;
16
const
ERR_TEMPLATES
=
'templates'
;
17
const
ERR_MODULE
=
'module'
;
18
19
protected
$eventName
;
20
protected
$fields
;
21
protected
$siteId
;
22
protected
$languageId
;
23
protected
$templateId
;
24
30
public
function
__construct
(
$eventName
,
array
$fields
= [])
31
{
32
$this->eventName =
$eventName
;
33
$this->fields =
$fields
;
34
}
35
40
public
function
setSite
(
$siteId
)
41
{
42
$this->siteId =
$siteId
;
43
return
$this;
44
}
45
50
public
function
setLanguage
(
$languageId
)
51
{
52
$this->languageId =
$languageId
;
53
return
$this;
54
}
55
60
public
function
setTemplate
(
$templateId
)
61
{
62
$this->templateId =
$templateId
;
63
return
$this;
64
}
65
70
public
function
send
($directly =
false
)
71
{
72
$result
=
new
Main\Result
();
73
74
if
(!
Main
\
Loader::includeModule
(
"messageservice"
))
75
{
76
$result
->addError(
new
Main
\
Error
(
"Module messageservice is not installed."
, self::ERR_MODULE));
77
return
$result
;
78
}
79
80
$senderId =
Main\Config\Option::get
(
"main"
,
"sms_default_service"
);
81
if
($senderId ==
''
)
82
{
83
//messageservice will try to use any available sender
84
$senderId =
null
;
85
}
86
87
$messageListResult = $this->
createMessageList
();
88
if
(!$messageListResult->isSuccess())
89
{
90
return
$result
->addErrors($messageListResult->getErrors());
91
}
92
$messageList = $messageListResult->getData();
93
94
foreach
($messageList as
$message
)
95
{
96
$smsMessage =
\Bitrix\MessageService\Sender\SmsManager::createMessage
([
97
'SENDER_ID'
=> $senderId,
98
'MESSAGE_FROM'
=>
$message
->getSender(),
99
'MESSAGE_TO'
=>
$message
->getReceiver(),
100
'MESSAGE_BODY'
=>
$message
->getText(),
101
]);
102
103
$event
=
new
Main\Event
(
'main'
,
'onBeforeSendSms'
, [
104
'message'
=> $smsMessage,
105
'template'
=>
$message
->getTemplate()
106
]);
107
$event
->send();
108
foreach
(
$event
->getResults() as $evenResult)
109
{
110
if
($evenResult->getType() ===
Main
\EventResult::ERROR)
111
{
112
continue
2;
113
}
114
}
115
116
if
($directly)
117
{
118
$smsResult = $smsMessage->sendDirectly();
119
}
120
else
121
{
122
$smsResult = $smsMessage->send();
123
}
124
125
if
(!$smsResult->isSuccess())
126
{
127
$result
->addErrors($smsResult->getErrors());
128
}
129
}
130
131
return
$result
;
132
}
133
137
public
function
createMessageList
():
Main
\
Result
138
{
139
$result
=
new
Main\Result
();
140
$context
= Main\Context::getCurrent();
141
142
if
($this->siteId ===
null
)
143
{
144
$this->siteId =
$context
->getSite();
145
if
($this->siteId ===
null
)
146
{
147
$result
->addError(
new
Main
\
Error
(
"Can't filter templates, the siteId is not set."
, self::ERR_SITE));
148
return
$result
;
149
}
150
}
151
152
if
($this->languageId ===
null
)
153
{
154
$this->languageId =
$context
->getLanguage();
155
}
156
157
$templates = $this->
fetchTemplates
();
158
if
($templates->isEmpty())
159
{
160
$result
->addError(
new
Main
\
Error
(
"Templates not found."
, self::ERR_TEMPLATES));
161
return
$result
;
162
}
163
164
$messageList = [];
165
foreach
($templates as
$template
)
166
{
167
$messageList[] =
Message::createFromTemplate
(
$template
, $this->fields);
168
}
169
$result
->setData($messageList);
170
171
return
$result
;
172
}
173
177
protected
function
fetchTemplates
()
178
{
179
$filter
= Query::filter()
180
->where(
"ACTIVE"
,
"Y"
)
181
->where(
"SITES.LID"
, $this->siteId);
182
183
if
($this->templateId !==
null
)
184
{
185
//specific template was supplied
186
$filter
->where(
"ID"
, $this->templateId);
187
}
188
else
189
{
190
//select templates by conditions
191
$filter
->where(
"EVENT_NAME"
, $this->eventName);
192
193
if
($this->languageId !==
null
)
194
{
195
$filter
->where(Query::filter()
196
->logic(
'or'
)
197
->where(
'LANGUAGE_ID'
, $this->languageId)
198
->where(
'LANGUAGE_ID'
,
''
)
199
->whereNull(
'LANGUAGE_ID'
)
200
);
201
}
202
}
203
204
$res
=
TemplateTable::getList
([
205
'select'
=> [
'*'
,
'SITES.SITE_NAME'
,
'SITES.SERVER_NAME'
,
'SITES.LID'
],
206
'filter'
=>
$filter
,
207
]);
208
209
return
$res
->fetchCollection();
210
211
}
212
}
Bitrix\Main\Config\Option\get
static get($moduleId, $name, $default="", $siteId=false)
Определения
option.php:30
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\Event
Определения
event.php:5
Bitrix\Main\Loader\includeModule
static includeModule($moduleName)
Определения
loader.php:67
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
Bitrix\Main\ORM\Data\Result
Определения
result.php:16
Bitrix\Main\Sms\Event\$eventName
$eventName
Определения
event.php:19
Bitrix\Main\Sms\Event\ERR_TEMPLATES
const ERR_TEMPLATES
Определения
event.php:16
Bitrix\Main\Sms\Event\setLanguage
setLanguage($languageId)
Определения
event.php:50
Bitrix\Main\Sms\Event\$templateId
$templateId
Определения
event.php:23
Bitrix\Main\Sms\Event\send
send($directly=false)
Определения
event.php:70
Bitrix\Main\Sms\Event\__construct
__construct($eventName, array $fields=[])
Определения
event.php:30
Bitrix\Main\Sms\Event\fetchTemplates
fetchTemplates()
Определения
event.php:177
Bitrix\Main\Sms\Event\ERR_SITE
const ERR_SITE
Определения
event.php:15
Bitrix\Main\Sms\Event\$siteId
$siteId
Определения
event.php:21
Bitrix\Main\Sms\Event\$fields
$fields
Определения
event.php:20
Bitrix\Main\Sms\Event\createMessageList
createMessageList()
Определения
event.php:137
Bitrix\Main\Sms\Event\setTemplate
setTemplate($templateId)
Определения
event.php:60
Bitrix\Main\Sms\Event\setSite
setSite($siteId)
Определения
event.php:40
Bitrix\Main\Sms\Event\$languageId
$languageId
Определения
event.php:22
Bitrix\Main\Sms\Event\ERR_MODULE
const ERR_MODULE
Определения
event.php:17
Bitrix\Main\Sms\Message\createFromTemplate
static createFromTemplate(Template $template, array $fields)
Определения
message.php:23
Bitrix\MessageService\Sender\SmsManager\createMessage
static createMessage(array $messageFields, Base $sender=null)
Определения
smsmanager.php:250
$template
$template
Определения
file_edit.php:49
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$result
$result
Определения
get_property_values.php:14
$filter
$filter
Определения
iblock_catalog_list.php:54
$context
$context
Определения
csv_new_setup.php:223
Bitrix\Main\ORM\Query
Определения
chain.php:3
Bitrix\Main\Sms
Определения
event.php:8
Bitrix\Main
$message
$message
Определения
payment.php:8
$event
$event
Определения
prolog_after.php:141
bitrix
modules
main
lib
sms
event.php
Создано системой
1.14.0