Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
blacklist.php
1
<?php
2
3
namespace
Bitrix\Main\Mail\Internal
;
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Entity
;
7
use
Bitrix\Main\Type\DateTime
;
8
27
class
BlacklistTable
extends
Entity\DataManager
28
{
29
const
CategoryAuto
= 0;
30
const
CategoryManual
= 1;
31
37
public
static
function
getTableName
()
38
{
39
return
'b_main_mail_blacklist'
;
40
}
41
47
public
static
function
getMap
()
48
{
49
return
array(
50
'ID'
=> array(
51
'data_type'
=>
'integer'
,
52
'primary'
=>
true
,
53
'autocomplete'
=>
true
,
54
),
55
'CATEGORY_ID'
=> array(
56
'data_type'
=>
'integer'
,
57
'required'
=>
true
,
58
'default_value'
=> self::CategoryAuto,
59
),
60
'CODE'
=> array(
61
'data_type'
=>
'string'
,
62
'required'
=>
true
,
63
),
64
'DATE_INSERT'
=> array(
65
'data_type'
=>
'datetime'
,
66
'required'
=>
new
DateTime
(),
67
),
68
);
69
}
70
76
public
static
function
hasBlacklistedEmails
()
77
{
78
static
$hasEmails =
null
;
79
if
($hasEmails ===
null
)
80
{
81
$row = static::getRow([
82
'select'
=> [
'ID'
],
83
'limit'
=> 1,
84
'order'
=> [
'ID'
=>
'ASC'
],
85
'cache'
=> [
'ttl'
=> 36000]
86
]);
87
88
$hasEmails = $row !==
null
;
89
}
90
91
return
$hasEmails;
92
}
93
100
public
static
function
insertBatch
(array $list)
101
{
102
$connection =
Application::getConnection
();
103
$helper = $connection->getSqlHelper();
104
$tableName = static::getTableName();
105
$dateNow = $helper->convertToDbDateTime(
new
DateTime
());
106
107
foreach
(self::divideList($list) as $batchList)
108
{
109
$values = [];
110
foreach
($batchList as $code)
111
{
112
$code = trim($code);
113
if
(!$code)
114
{
115
continue
;
116
}
117
118
$code = $helper->forSql($code);
119
$values[] =
"$dateNow, \"$code\""
;
120
}
121
122
if
(empty($values))
123
{
124
return
;
125
}
126
127
$values =
'('
. implode(
'), ('
, $values) .
')'
;
128
129
$sql = $helper->getInsertIgnore($tableName,
'(DATE_INSERT, CODE)'
,
'VALUES '
. $values);
130
$connection->query($sql);
131
132
static::getEntity()->cleanCache();
133
}
134
}
135
136
protected
static
function
divideList
(array $list, $limit = 300)
137
{
138
$length = count($list);
139
if
($length < $limit)
140
{
141
return
array($list);
142
}
143
144
$result = array();
145
$partsCount = ceil($length / $limit);
146
for
($index = 0; $index < $partsCount; $index++)
147
{
148
$result[$index] = array_slice($list, $limit * $index, $limit);
149
}
150
151
return
$result;
152
}
153
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\Mail\Internal\BlacklistTable
Definition
blacklist.php:28
Bitrix\Main\Mail\Internal\BlacklistTable\CategoryAuto
const CategoryAuto
Definition
blacklist.php:29
Bitrix\Main\Mail\Internal\BlacklistTable\getMap
static getMap()
Definition
blacklist.php:47
Bitrix\Main\Mail\Internal\BlacklistTable\CategoryManual
const CategoryManual
Definition
blacklist.php:30
Bitrix\Main\Mail\Internal\BlacklistTable\divideList
static divideList(array $list, $limit=300)
Definition
blacklist.php:136
Bitrix\Main\Mail\Internal\BlacklistTable\getTableName
static getTableName()
Definition
blacklist.php:37
Bitrix\Main\Mail\Internal\BlacklistTable\insertBatch
static insertBatch(array $list)
Definition
blacklist.php:100
Bitrix\Main\Mail\Internal\BlacklistTable\hasBlacklistedEmails
static hasBlacklistedEmails()
Definition
blacklist.php:76
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\Mail\Internal
Definition
blacklist.php:3
modules
main
lib
mail
internal
blacklist.php
Создано системой
1.10.0