Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
abstractconsentresponse.php
1
<?php
2
3
namespace
Bitrix\Sender\Consent
;
4
5
use
Bitrix\Main\Type\DateTime
;
6
use
Bitrix\Sender\ContactTable
;
7
use
Bitrix\Sender\Internals\Model\Posting\RecipientTable
;
8
use
Bitrix\Sender\Internals\SqlBatch
;
9
10
abstract
class
AbstractConsentResponse
implements
iConsentResponse
11
{
12
const
APPLY_ACTION
=
true
;
13
const
REJECT_ACTION
=
false
;
14
const
ORIGINATOR_ID
=
'sender'
;
15
22
public
abstract
function
loadData
($data) :
iConsentResponse
;
23
28
public
function
reject
()
29
{
30
return
$this->
updateContact
(static::REJECT_ACTION);
31
}
32
37
public
function
apply
()
38
{
39
\Bitrix\Main\UserConsent\Consent::addByContext($this->
getConsentId
(), self::ORIGINATOR_ID, $this->
getPostingId
());
40
return
$this->
updateContact
(static::APPLY_ACTION);
41
}
42
47
protected
abstract
function
getContactId
();
48
52
protected
abstract
function
getConsentId
();
53
57
protected
abstract
function
getPostingId
();
58
63
protected
abstract
function
isContactUpdated
($apply);
64
72
protected
function
updateContact
($apply)
73
{
74
$result =
false
;
75
if
($this->
isContactUpdated
($apply))
76
{
77
$contactId = $this->
getContactId
();
78
$type = ($apply?
ContactTable::CONSENT_STATUS_ACCEPT
:
ContactTable::CONSENT_STATUS_DENY
);
79
$isUnsub = ($apply?
'N'
:
'Y'
);
80
$result = ContactTable::update($contactId,[
81
'CONSENT_STATUS'
=> $type,
82
'IS_UNSUB'
=> $isUnsub,
83
'DATE_UPDATE'
=>
new
DateTime
()
84
])->isSuccess();
85
$recipients = RecipientTable::getList([
86
'select'
=> [
'ID'
,
'STATUS'
],
87
'filter'
=> [
88
'=CONTACT_ID'
=> $contactId,
89
'@STATUS'
=> [
RecipientTable::SEND_RESULT_NONE
,
RecipientTable::SEND_RESULT_WAIT_ACCEPT
]
90
]
91
])->fetchAll();
92
if
(!empty($recipients))
93
{
94
SqlBatch::update
(
RecipientTable::getTableName
(),array_map(
95
function
($recipient) use ($isUnsub)
96
{
97
$changeStatus = $recipient[
'STATUS'
] ===
RecipientTable::SEND_RESULT_WAIT_ACCEPT
;
98
return
[
99
'ID'
=> $recipient[
'ID'
],
100
'STATUS'
=> ($changeStatus?
RecipientTable::SEND_RESULT_NONE
: $recipient[
'STATUS'
]),
101
'IS_UNSUB'
=> $isUnsub
102
];
103
},
104
$recipients
105
));
106
}
107
}
108
return
$result;
109
}
110
}
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Sender\Consent\AbstractConsentResponse
Definition
abstractconsentresponse.php:11
Bitrix\Sender\Consent\AbstractConsentResponse\APPLY_ACTION
const APPLY_ACTION
Definition
abstractconsentresponse.php:12
Bitrix\Sender\Consent\AbstractConsentResponse\ORIGINATOR_ID
const ORIGINATOR_ID
Definition
abstractconsentresponse.php:14
Bitrix\Sender\Consent\AbstractConsentResponse\loadData
loadData($data)
Bitrix\Sender\Consent\AbstractConsentResponse\isContactUpdated
isContactUpdated($apply)
Bitrix\Sender\Consent\AbstractConsentResponse\apply
apply()
Definition
abstractconsentresponse.php:37
Bitrix\Sender\Consent\AbstractConsentResponse\getConsentId
getConsentId()
Bitrix\Sender\Consent\AbstractConsentResponse\REJECT_ACTION
const REJECT_ACTION
Definition
abstractconsentresponse.php:13
Bitrix\Sender\Consent\AbstractConsentResponse\reject
reject()
Definition
abstractconsentresponse.php:28
Bitrix\Sender\Consent\AbstractConsentResponse\getContactId
getContactId()
Bitrix\Sender\Consent\AbstractConsentResponse\updateContact
updateContact($apply)
Definition
abstractconsentresponse.php:72
Bitrix\Sender\Consent\AbstractConsentResponse\getPostingId
getPostingId()
Bitrix\Sender\ContactTable
Definition
contact.php:43
Bitrix\Sender\ContactTable\CONSENT_STATUS_DENY
const CONSENT_STATUS_DENY
Definition
contact.php:46
Bitrix\Sender\ContactTable\CONSENT_STATUS_ACCEPT
const CONSENT_STATUS_ACCEPT
Definition
contact.php:47
Bitrix\Sender\Internals\Model\Posting\RecipientTable
Definition
recipient.php:33
Bitrix\Sender\Internals\Model\Posting\RecipientTable\SEND_RESULT_WAIT_ACCEPT
const SEND_RESULT_WAIT_ACCEPT
Definition
recipient.php:39
Bitrix\Sender\Internals\Model\Posting\RecipientTable\SEND_RESULT_NONE
const SEND_RESULT_NONE
Definition
recipient.php:34
Bitrix\Sender\Internals\Model\Posting\RecipientTable\getTableName
static getTableName()
Definition
recipient.php:46
Bitrix\Sender\Internals\SqlBatch
Definition
sqlbatch.php:22
Bitrix\Sender\Internals\SqlBatch\update
static update($tableName, array $fields)
Definition
sqlbatch.php:72
Bitrix\Sender\Consent\iConsentResponse
Definition
iconsentresponse.php:6
Bitrix\Sender\Consent
Definition
abstractconsentmessagebuilder.php:3
modules
sender
lib
consent
abstractconsentresponse.php
Создано системой
1.10.0