1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
mailservices.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Mail;
4
5
use Bitrix\Main\Entity;
6
use Bitrix\Main\Localization;
7
use Bitrix\Main\ORM;
8
9
Localization\Loc::loadMessages
(__FILE__);
10
27
class
MailServicesTable
extends
Entity\DataManager
28
{
29
30
public
static
function
getFilePath
()
31
{
32
return
__FILE__;
33
}
34
35
public
static
function
getTableName
()
36
{
37
return
'b_mail_mailservices'
;
38
}
39
40
public
static
function
checkFields
(
Entity
\
Result
$result
, $primary,
array
$data
)
41
{
42
parent::checkFields(
$result
, $primary,
$data
);
43
44
if
(isset(
$data
[
'SITE_ID'
]))
45
{
46
$selectResult =
\Bitrix\Main\SiteTable::getByPrimary
(
$data
[
'SITE_ID'
]);
47
if
(!$selectResult->fetch())
48
{
49
$field = static::getEntity()->getField(
'SITE_ID'
);
50
$result
->addError(
new
Entity
\
FieldError
(
51
$field,
52
Localization
\Loc::getMessage(
'MAIN_ENTITY_FIELD_INVALID'
,
array
(
'#FIELD_TITLE#'
=> $field->getTitle())),
53
Entity
\FieldError::INVALID_VALUE
54
));
55
}
56
}
57
58
if
(!empty(
$data
[
'ICON'
]))
59
{
60
if
(!is_scalar(
$data
[
'ICON'
]) || !preg_match(
'/[0-9]+/'
,
$data
[
'ICON'
]))
61
{
62
$field = static::getEntity()->getField(
'ICON'
);
63
$result
->addError(
new
Entity
\
FieldError
(
64
$field,
65
Localization
\Loc::getMessage(
'MAIN_ENTITY_FIELD_INVALID'
,
array
(
'#FIELD_TITLE#'
=> $field->getTitle())),
66
Entity
\FieldError::INVALID_VALUE
67
));
68
}
69
}
70
71
return
$result
;
72
}
73
74
public
static
function
add
(
array
$data
)
75
{
76
if
(isset(
$data
[
'ICON'
]) && is_array(
$data
[
'ICON'
]))
77
{
78
$iconError =
$data
[
'ICON'
][
'name'
] ? \CFile::checkImageFile(
$data
[
'ICON'
]) :
null
;
79
if
(is_null($iconError))
80
{
81
$data
[
'ICON'
][
'MODULE_ID'
] =
'mail'
;
82
83
\CFile::saveForDB(
$data
,
'ICON'
,
'mail/mailservices/icon'
);
84
}
85
}
86
87
return
parent::add(
$data
);
88
}
89
90
public
static
function
update
($primary,
array
$data
):
Entity
\
UpdateResult
91
{
92
if
(empty(
$data
))
93
return
new
Entity\UpdateResult();
94
95
$serviceForUpdate = static::getByPrimary(
96
$primary,
97
array
(
98
'select'
=>
array
(
99
'ID'
,
'SITE_ID'
,
'ACTIVE'
,
'SERVICE_TYPE'
,
100
),
101
)
102
)->fetch();
103
if
(!$serviceForUpdate)
104
{
105
$updateResult =
new
Entity\UpdateResult();
106
$updateResult->addError(
new
Entity
\
EntityError
(
Localization
\Loc::getMessage(
'mail_mailservice_not_found'
)));
107
108
return
$updateResult;
109
}
110
111
if
(isset(
$data
[
'ICON'
]) && is_array(
$data
[
'ICON'
]))
112
{
113
$iconError =
$data
[
'ICON'
][
'name'
] ? \CFile::checkImageFile(
$data
[
'ICON'
]) :
null
;
114
if
(is_null($iconError))
115
{
116
$data
[
'ICON'
][
'MODULE_ID'
] =
'mail'
;
117
118
\CFile::saveForDB(
$data
,
'ICON'
,
'mail/mailservices/icon'
);
119
}
120
}
121
122
$updateResult = parent::update($primary,
$data
);
123
124
if
($updateResult->isSuccess())
125
{
126
$serviceId = is_array($primary) ? $primary[
'ID'
] : $primary;
127
128
$isSiteChanged = isset(
$data
[
'SITE_ID'
]) &&
$data
[
'SITE_ID'
] != $serviceForUpdate[
'SITE_ID'
];
129
$isDeactivated = isset(
$data
[
'ACTIVE'
]) &&
$data
[
'ACTIVE'
] ==
'N'
&& $serviceForUpdate[
'ACTIVE'
] ==
'Y'
;
130
if
(($isSiteChanged || $isDeactivated) && $serviceForUpdate[
'SERVICE_TYPE'
] ==
'imap'
)
131
{
132
$emptyService = static::getList(
array
(
133
'select'
=>
array
(
'ID'
),
134
'filter'
=>
array
(
135
'=SITE_ID'
=> $serviceForUpdate[
'SITE_ID'
],
136
'ACTIVE'
=>
'Y'
,
137
'=SERVICE_TYPE'
=>
'imap'
,
138
'=SERVER'
=>
''
,
139
'=PORT'
=>
''
,
140
'=ENCRYPTION'
=>
''
,
141
'=LINK'
=>
''
,
142
),
143
'limit'
=> 1,
144
))->fetch();
145
}
146
147
if
($isSiteChanged || $isDeactivated && $emptyService)
148
{
149
$mbData = $emptyService
150
?
array
(
'SERVICE_ID'
=> $emptyService[
'ID'
])
151
:
array
(
'ACTIVE'
=>
'N'
,
'SERVICE_ID'
=> 0);
152
}
153
else
154
{
155
$mbData =
array
();
156
foreach
(
$data
as
$key
=> $value)
157
{
158
if
(empty($value))
159
continue
;
160
161
switch
(
$key
)
162
{
163
case
'ACTIVE'
:
164
case
'NAME'
:
165
case
'SERVER'
:
166
case
'PORT'
:
167
case
'LINK'
:
168
$mbData[
$key
] = $value;
169
break
;
170
case
'ENCRYPTION'
:
171
$mbData[
'USE_TLS'
] = $value;
172
break
;
173
}
174
}
175
}
176
177
$selectResult = \CMailbox::getList(
array
(),
array
(
'SERVICE_ID'
=> $serviceId));
178
while
($mailbox = $selectResult->fetch())
179
\CMailbox::update($mailbox[
'ID'
], $mbData);
180
}
181
182
return
$updateResult;
183
}
184
185
public
static
function
getIconSrc
($serviceName, $iconId =
null
)
186
{
187
if
($iconId)
188
{
189
$icon = \CFile::getFileArray($iconId);
190
191
return
$icon[
'SRC'
];
192
}
193
else
194
{
195
$icons =
array
(
196
'bitrix24'
=>
'/bitrix/images/mail/mailservice-icon/'
.
Localization
\Loc::getMessage(
'mail_mailservice_bitrix24_icon'
),
197
'gmail'
=>
'/bitrix/images/mail/mailservice-icon/post-gmail-icon.svg'
,
198
'icloud'
=>
'/bitrix/images/mail/mailservice-icon/post-icloud-icon.svg'
,
199
'outlook.com'
=>
'/bitrix/images/mail/mailservice-icon/post-outlook-icon.svg'
,
200
'office365'
=>
'/bitrix/images/mail/mailservice-icon/post-office360-icon.svg'
,
201
'yahoo'
=>
'/bitrix/images/mail/mailservice-icon/post-yahoo-icon.svg'
,
202
'aol'
=>
'/bitrix/images/mail/mailservice-icon/post-aol-icon.svg'
,
203
'yandex'
=>
'/bitrix/images/mail/mailservice-icon/post-yandex-icon.svg'
,
204
'mail.ru'
=>
'/bitrix/images/mail/mailservice-icon/post-mail-icon.svg'
,
205
'ukr.net'
=>
'/bitrix/images/mail/mailservice-icon/post-ukrnet-icon.svg'
,
206
'exchange'
=>
'/bitrix/images/mail/mailservice-icon/post-imap-icon.svg'
,
207
'exchangeOnline'
=>
'/bitrix/images/mail/mailservice-icon/post-exchange-icon.svg'
,
208
'other'
=>
'/bitrix/images/mail/mailservice-icon/post-imap-icon.svg'
,
209
);
210
211
if
($icons[$serviceName])
212
return
$icons[$serviceName];
213
}
214
215
return
null
;
216
}
217
218
public
static
function
getOAuthHelper
(
$data
)
219
{
220
switch
(
$data
[
'NAME'
])
221
{
222
case
'gmail'
:
223
return
Helper\OAuth\Google::getInstance();
224
case
'yandex'
:
225
return
Helper\OAuth\Yandex::getInstance();
226
case
'mail.ru'
:
227
return
Helper\OAuth\Mailru::getInstance();
228
case
'office365'
:
229
case
'outlook.com'
:
230
case
'exchangeOnline'
:
231
return
Helper\OAuth\Office365::getInstance();
232
}
233
}
234
235
public
static
function
delete
($primary):
Entity
\
DeleteResult
236
{
237
$serviceForDelete = static::getByPrimary($primary)->fetch();
238
if
(!$serviceForDelete)
239
{
240
$deleteResult =
new
Entity\DeleteResult();
241
$deleteResult->addError(
new
Entity
\
EntityError
(
Localization
\Loc::getMessage(
'mail_mailservice_not_found'
)));
242
243
return
$deleteResult;
244
}
245
246
$deleteResult = parent::delete($primary);
247
248
if
($deleteResult->isSuccess())
249
{
250
$serviceId = is_array($primary) ? $primary[
'ID'
] : $primary;
251
252
if
(in_array($serviceForDelete[
'SERVICE_TYPE'
],
array
(
'controller'
,
'domain'
,
'crdomain'
)))
253
{
254
$mbData =
array
(
'ACTIVE'
=>
'N'
,
'SERVICE_ID'
=> 0);
255
}
256
else
257
{
258
$emptyService = static::getList(
array
(
259
'filter'
=>
array
(
260
'=SITE_ID'
=> $serviceForDelete[
'SITE_ID'
],
261
'ACTIVE'
=>
'Y'
,
262
'=SERVER'
=>
''
,
263
'=PORT'
=>
''
,
264
'=ENCRYPTION'
=>
''
,
265
'=LINK'
=>
''
266
),
267
'limit'
=> 1
268
))->fetch();
269
270
$mbData = $emptyService
271
?
array
(
'SERVICE_ID'
=> $emptyService[
'ID'
],
'NAME'
=> $emptyService[
'NAME'
])
272
:
array
(
'ACTIVE'
=>
'N'
,
'SERVICE_ID'
=> 0);
273
}
274
275
$selectResult = \CMailbox::getList(
array
(),
array
(
'SERVICE_ID'
=> $serviceId));
276
while
($mailbox = $selectResult->fetch())
277
\CMailbox::update($mailbox[
'ID'
], $mbData);
278
}
279
280
return
$deleteResult;
281
}
282
283
public
static
function
getMap
()
284
{
285
return
array
(
286
'ID'
=>
array
(
287
'data_type'
=>
'integer'
,
288
'primary'
=>
true
,
289
'autocomplete'
=>
true
,
290
),
291
'SITE_ID'
=>
array
(
292
'data_type'
=>
'string'
,
293
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_site_field'
),
294
'required'
=>
true
295
),
296
'ACTIVE'
=>
array
(
297
'data_type'
=>
'boolean'
,
298
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_active_field'
),
299
'values'
=>
array
(
'N'
,
'Y'
),
300
'required'
=>
true
301
),
302
'SORT'
=>
array
(
303
'data_type'
=>
'integer'
,
304
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_sort_field'
)
305
),
306
'SERVICE_TYPE'
=>
array
(
307
'data_type'
=>
'enum'
,
308
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_type_field'
),
309
'values'
=>
array
(
'imap'
,
'controller'
,
'domain'
,
'crdomain'
),
310
'required'
=>
true
311
),
312
'NAME'
=>
array
(
313
'data_type'
=>
'string'
,
314
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_name_field'
),
315
'required'
=>
true
316
),
317
'SERVER'
=>
array
(
318
'data_type'
=>
'string'
,
319
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_server_field'
),
320
'save_data_modification'
=>
function
()
321
{
322
return
array
(
323
function
($value)
324
{
325
return
mb_strtolower($value);
326
}
327
);
328
},
329
'fetch_data_modification'
=>
function
()
330
{
331
return
array
(
332
function
($value)
333
{
334
return
mb_strtolower($value);
335
}
336
);
337
},
338
),
339
'PORT'
=>
array
(
340
'data_type'
=>
'integer'
,
341
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_port_field'
),
342
),
343
'ENCRYPTION'
=>
array
(
344
'data_type'
=>
'boolean'
,
345
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_encryption_field'
),
346
'values'
=>
array
(
'N'
,
'Y'
),
347
),
348
'LINK'
=>
array
(
349
'data_type'
=>
'string'
,
350
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_link_field'
),
351
),
352
'ICON'
=>
array
(
353
'data_type'
=>
'integer'
,
354
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_icon_field'
),
355
),
356
'TOKEN'
=>
array
(
357
'data_type'
=>
'string'
,
358
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_token_field'
),
359
),
360
'FLAGS'
=>
array
(
361
'data_type'
=>
'integer'
,
362
'title'
=>
Localization
\Loc::getMessage(
'mail_mailservice_entity_flags_field'
),
363
),
364
'SITE'
=>
array
(
365
'data_type'
=>
'Bitrix\Main\Site'
,
366
'reference'
=>
array
(
'=this.SITE_ID'
=>
'ref.LID'
),
367
),
368
new
Entity\StringField(
'SMTP_SERVER'
),
369
new
Entity\IntegerField(
'SMTP_PORT'
),
370
new
Entity\BooleanField(
'SMTP_LOGIN_AS_IMAP'
, [
371
'values'
=>
array
(
'N'
,
'Y'
),
372
'default_value'
=>
'N'
,
373
]),
374
new
Entity\BooleanField(
'SMTP_PASSWORD_AS_IMAP'
, [
375
'values'
=>
array
(
'N'
,
'Y'
),
376
'default_value'
=>
'N'
,
377
]),
378
new
ORM\Fields\BooleanField
(
379
'SMTP_ENCRYPTION'
,
380
array
(
381
'values'
=>
array
(
'N'
,
'Y'
),
382
)
383
),
384
new
ORM\Fields\BooleanField
(
385
'UPLOAD_OUTGOING'
,
386
array
(
387
'values'
=>
array
(
'N'
,
'Y'
),
388
)
389
),
390
);
391
}
392
393
}
Bitrix\Mail\MailServicesTable
Определения
mailservices.php:28
Bitrix\Mail\MailServicesTable\getMap
static getMap()
Определения
mailservices.php:283
Bitrix\Mail\MailServicesTable\getOAuthHelper
static getOAuthHelper($data)
Определения
mailservices.php:218
Bitrix\Mail\MailServicesTable\getFilePath
static getFilePath()
Определения
mailservices.php:30
Bitrix\Mail\MailServicesTable\add
static add(array $data)
Определения
mailservices.php:74
Bitrix\Mail\MailServicesTable\getIconSrc
static getIconSrc($serviceName, $iconId=null)
Определения
mailservices.php:185
Bitrix\Mail\MailServicesTable\checkFields
static checkFields(Entity\Result $result, $primary, array $data)
Определения
mailservices.php:40
Bitrix\Mail\MailServicesTable\update
static update($primary, array $data)
Определения
mailservices.php:90
Bitrix\Mail\MailServicesTable\getTableName
static getTableName()
Определения
mailservices.php:35
Bitrix\Main\DB\Result
Определения
result.php:20
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Определения
loc.php:65
Bitrix\Main\ORM\Data\DataManager\getByPrimary
static getByPrimary($primary, array $parameters=array())
Определения
datamanager.php:330
Bitrix\Main\ORM\Data\DeleteResult
Определения
deleteresult.php:12
Bitrix\Main\ORM\Data\UpdateResult
Определения
updateresult.php:14
Bitrix\Main\ORM\EntityError
Определения
entityerror.php:12
Bitrix\Main\ORM\Fields\BooleanField
Определения
booleanfield.php:20
Bitrix\Main\ORM\Fields\FieldError
Определения
fielderror.php:14
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
Bitrix\Main\Entity
Определения
ufield.php:9
Bitrix\Main\Localization
Определения
culture.php:8
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
bitrix
modules
mail
lib
mailservices.php
Создано системой
1.14.0