Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
blacklist.php
1<?php
2
4
8
27class 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}
static getConnection($name="")
static divideList(array $list, $limit=300)