Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
abstractconsentresponse.php
1<?php
2
4
9
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();
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,
90 ]
91 ])->fetchAll();
92 if(!empty($recipients))
93 {
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}
static update($tableName, array $fields)
Definition sqlbatch.php:72