Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
contact.php
1
<?php
8
namespace
Bitrix\Sender\Entity
;
9
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Main\Error
;
12
use
Bitrix\Main\DB\SqlQueryException
;
13
14
use
Bitrix\Sender\ContactTable
;
15
use
Bitrix\Sender\ContactListTable
;
16
use
Bitrix\Sender\MailingSubscriptionTable
;
17
use
Bitrix\Sender\Recipient
;
18
19
Loc::loadMessages
(__FILE__);
20
25
class
Contact
extends
Base
26
{
33
public
static
function
getList
(array $parameters = array())
34
{
35
if
(!isset($parameters[
'select'
]))
36
{
37
$parameters[
'select'
] = array(
38
'*'
,
39
);
40
}
41
if
(!isset($parameters[
'filter'
]))
42
{
43
$parameters[
'filter'
] = array();
44
}
45
46
return
ContactTable::getList($parameters);
47
}
48
54
protected
function
getDefaultData
()
55
{
56
return
array(
57
'NAME'
=>
''
,
58
'CODE'
=>
''
,
59
'TYPE_ID'
=> Recipient\Type::EMAIL,
60
'BLACKLISTED'
=>
'N'
,
61
'SET_LIST'
=> [],
62
'SUB_LIST'
=> [],
63
'UNSUB_LIST'
=> [],
64
);
65
}
66
75
protected
function
saveData
($id, array $data)
76
{
77
$setList = array_filter($data[
'SET_LIST'
],
'is_numeric'
);
78
$subList = array_filter($data[
'SUB_LIST'
],
'is_numeric'
);
79
$unsubList = array_filter($data[
'UNSUB_LIST'
],
'is_numeric'
);
80
81
$this->filterDataByEntityFields(ContactTable::getEntity(), $data);
82
83
try
84
{
85
$id = $this->saveByEntity(ContactTable::getEntity(), $id, $data);
86
}
87
catch
(
SqlQueryException
$exception)
88
{
89
if
(mb_strpos($exception->getMessage(),
'(1062) Duplicate entry'
) !==
false
)
90
{
91
$this->errors->setError(
new
Error
(
Loc::getMessage
(
'SENDER_ENTITY_CONTACT_ERROR_DUPLICATE'
)));
92
return
$id;
93
}
94
95
throw
$exception;
96
}
97
98
if
($this->
hasErrors
())
99
{
100
return
$id;
101
}
102
103
$this->
saveDataLists
($id, $setList, $subList, $unsubList);
104
105
return
$id;
106
}
107
108
protected
function
saveDataLists
($id, $setList, $subList, $unsubList)
109
{
110
$setList = array_unique($setList);
111
$unsubList = array_unique($unsubList);
112
$subList = array_unique($subList);
113
$subList = array_diff($subList, $unsubList);
114
115
ContactListTable::deleteList
([
'CONTACT_ID'
=> $id]);
116
foreach
($setList as $itemId)
117
{
118
ContactListTable::add([
'CONTACT_ID'
=> $id,
'LIST_ID'
=> $itemId]);
119
}
120
121
MailingSubscriptionTable::deleteList
([
'CONTACT_ID'
=> $id]);
122
foreach
($subList as $itemId)
123
{
124
MailingSubscriptionTable::add([
'CONTACT_ID'
=> $id,
'MAILING_ID'
=> $itemId,
'IS_UNSUB'
=>
'N'
]);
125
}
126
foreach
($unsubList as $itemId)
127
{
128
MailingSubscriptionTable::add([
'CONTACT_ID'
=> $id,
'MAILING_ID'
=> $itemId,
'IS_UNSUB'
=>
'Y'
]);
129
}
130
}
131
138
public
function
loadData
($id)
139
{
140
$data = ContactTable::getRowById($id);
141
if
($data)
142
{
143
$list = ContactListTable::getList([
144
'select'
=> [
'LIST_ID'
],
145
'filter'
=> [
'CONTACT_ID'
=> $id]
146
])->fetchAll();
147
$data[
'SET_LIST'
] = array_column($list,
'LIST_ID'
);
148
149
$list = MailingSubscriptionTable::getList([
150
'select'
=> [
'MAILING_ID'
],
151
'filter'
=> [
'CONTACT_ID'
=> $id,
'IS_UNSUB'
=>
'N'
]
152
])->fetchAll();
153
$data[
'SUB_LIST'
] = array_column($list,
'MAILING_ID'
);
154
155
$list = MailingSubscriptionTable::getList([
156
'select'
=> [
'MAILING_ID'
],
157
'filter'
=> [
'CONTACT_ID'
=> $id,
'IS_UNSUB'
=>
'Y'
]
158
])->fetchAll();
159
$data[
'UNSUB_LIST'
] = array_column($list,
'MAILING_ID'
);
160
}
161
162
return
$data;
163
}
164
170
public
function
remove
()
171
{
172
return
$this->removeByEntity(ContactTable::getEntity(), $this->
getId
());
173
}
174
181
public
static
function
removeById
($id)
182
{
183
return
static::create()->removeByEntity(ContactTable::getEntity(), $id);
184
}
185
192
public
static
function
removeFromBlacklistById
($id)
193
{
194
return
ContactTable::update($id, array(
'BLACKLISTED'
=>
'N'
))->isSuccess();
195
}
196
203
public
function
subscribe
($campaignId =
null
)
204
{
205
if
(!$this->
getId
())
206
{
207
return
false
;
208
}
209
210
$campaignId = $campaignId ?:
Campaign::getDefaultId
(SITE_ID);
211
return
MailingSubscriptionTable::addSubscription
(array(
212
'MAILING_ID'
=> $campaignId,
213
'CONTACT_ID'
=> $this->
getId
(),
214
));
215
}
216
223
public
function
unsubscribe
($campaignId =
null
)
224
{
225
if
(!$this->
getId
())
226
{
227
return
false
;
228
}
229
230
$campaignId = $campaignId ?:
Campaign::getDefaultId
(SITE_ID);
231
return
MailingSubscriptionTable::addUnSubscription
(array(
232
'MAILING_ID'
=> $campaignId,
233
'CONTACT_ID'
=> $this->
getId
(),
234
));
235
}
236
242
public
function
addToBlacklist
()
243
{
244
if
(!$this->
getId
())
245
{
246
return
false
;
247
}
248
249
return
ContactTable::update($this->
getId
(), array(
'BLACKLISTED'
=>
'Y'
))->isSuccess();
250
}
251
257
public
function
removeFromBlacklist
()
258
{
259
if
(!$this->
getId
())
260
{
261
return
false
;
262
}
263
264
return
self::removeFromBlacklistById
($this->
getId
());
265
}
266
273
public
function
addToList
($listId)
274
{
275
if
(!$this->
getId
())
276
{
277
return
false
;
278
}
279
280
return
ContactListTable::addIfNotExist
($this->
getId
(), $listId);
281
}
282
289
public
function
removeFromList
($listId)
290
{
291
if
(!$this->
getId
())
292
{
293
return
false
;
294
}
295
296
return
ContactListTable::delete(array(
297
'CONTACT_ID'
=> $this->
getId
(),
298
'LIST_ID'
=> $listId
299
))->isSuccess();
300
}
301
}
Bitrix\Main\DB\SqlQueryException
Definition
sqlexception.php:24
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sender\Connector\Base
Definition
base.php:13
Bitrix\Sender\Connector\Base\getId
getId()
Definition
base.php:206
Bitrix\Sender\ContactListTable
Definition
contactlist.php:34
Bitrix\Sender\ContactListTable\deleteList
static deleteList(array $filter)
Definition
contactlist.php:105
Bitrix\Sender\ContactListTable\addIfNotExist
static addIfNotExist($contactId, $listId)
Definition
contactlist.php:79
Bitrix\Sender\ContactTable
Definition
contact.php:43
Bitrix\Sender\Entity\Campaign\getDefaultId
static getDefaultId($siteId=null)
Definition
campaign.php:63
Bitrix\Sender\Entity\Contact
Definition
contact.php:26
Bitrix\Sender\Entity\Contact\saveDataLists
saveDataLists($id, $setList, $subList, $unsubList)
Definition
contact.php:108
Bitrix\Sender\Entity\Contact\removeFromBlacklistById
static removeFromBlacklistById($id)
Definition
contact.php:192
Bitrix\Sender\Entity\Contact\addToList
addToList($listId)
Definition
contact.php:273
Bitrix\Sender\Entity\Contact\getList
static getList(array $parameters=array())
Definition
contact.php:33
Bitrix\Sender\Entity\Contact\loadData
loadData($id)
Definition
contact.php:138
Bitrix\Sender\Entity\Contact\removeFromList
removeFromList($listId)
Definition
contact.php:289
Bitrix\Sender\Entity\Contact\addToBlacklist
addToBlacklist()
Definition
contact.php:242
Bitrix\Sender\Entity\Contact\getDefaultData
getDefaultData()
Definition
contact.php:54
Bitrix\Sender\Entity\Contact\subscribe
subscribe($campaignId=null)
Definition
contact.php:203
Bitrix\Sender\Entity\Contact\unsubscribe
unsubscribe($campaignId=null)
Definition
contact.php:223
Bitrix\Sender\Entity\Contact\removeById
static removeById($id)
Definition
contact.php:181
Bitrix\Sender\Entity\Contact\removeFromBlacklist
removeFromBlacklist()
Definition
contact.php:257
Bitrix\Sender\Entity\Contact\saveData
saveData($id, array $data)
Definition
contact.php:75
Bitrix\Sender\MailingSubscriptionTable
Definition
mailing.php:779
Bitrix\Sender\MailingSubscriptionTable\addUnSubscription
static addUnSubscription(array $parameters=array())
Definition
mailing.php:874
Bitrix\Sender\MailingSubscriptionTable\deleteList
static deleteList(array $filter)
Definition
mailing.php:899
Bitrix\Sender\MailingSubscriptionTable\addSubscription
static addSubscription(array $parameters=array())
Definition
mailing.php:851
Bitrix\Main\hasErrors
hasErrors()
Definition
errorableimplementation.php:17
Bitrix\Sender\Entity
Definition
ad.php:8
Bitrix\Sender\Recipient
Definition
agent.php:8
modules
sender
lib
entity
contact.php
Создано системой
1.10.0