Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
transportbase.php
1<?php
10
15
21{
22 public const CODE = self::CODE_UNDEFINED;
23 public const CODE_ADS_VK = 'ads_vk';
24 public const CODE_ADS_FB = 'ads_fb';
25 public const CODE_ADS_YA = 'ads_ya';
26 public const CODE_ADS_GA = 'ads_ga';
27 public const CODE_ADS_LOOKALIKE_FB = 'ads_lookalike_fb';
28 public const CODE_ADS_LOOKALIKE_VK = 'ads_lookalike_vk';
29 public const CODE_ADS_LOOKALIKE_YANDEX = 'ads_lookalike_yandex';
30
32 protected $configuration;
33
35 protected $adsConfig;
36
40 public function __construct()
41 {
42 $this->configuration = new Message\Configuration();
43 }
44
50 public function getName()
51 {
52 return 'Ads';
53 }
54
60 public function getCode()
61 {
62 return static::CODE;
63 }
64
65 protected function getAdsType()
66 {
67 $map = Service::getTypeMap();
68 return $map[$this->getCode()];
69 }
70
77 {
78 return array(Recipient\Type::EMAIL, Recipient\Type::PHONE);
79 }
80
86 public function loadConfiguration()
87 {
89 }
90
92 {
93 $this->configuration = $configuration;
94 }
95
96 public function start()
97 {
98 $authAdapter = Retargeting\Service::getAuthAdapter($this->getAdsType());
99 if (!$authAdapter->hasAuth())
100 {
101 return false;
102 }
103
104 $this->adsConfig = new Retargeting\AdsAudienceConfig();
105
106 return true;
107 }
108
109 public function send(Message\Adapter $message)
110 {
111 $config = $message->getConfiguration();
112 $clientId = $config->get('CLIENT_ID');
113 $audienceId = $config->get('AUDIENCE_ID');
114 $audiencePhoneId = $config->get('AUDIENCE_PHONE_ID');
115 $audienceEmailId = $config->get('AUDIENCE_EMAIL_ID');
116
117
118 $adsContactType = null;
119 switch (Recipient\Type::getId($message->getRecipientType()))
120 {
121 case Recipient\Type::EMAIL:
122 $adsContactType = Retargeting\Audience::ENUM_CONTACT_TYPE_EMAIL;
123 break;
124
125 case Recipient\Type::PHONE:
126 $adsContactType = Retargeting\Audience::ENUM_CONTACT_TYPE_PHONE;
127 break;
128 }
129
130
131 $isSuccess = true;
132 $audiences = array();
133 if ($audienceId)
134 {
135 $audiences[] = array(
136 'id' => $audienceId,
137 'contactType' => $adsContactType
138 );
139 }
140 if ($audiencePhoneId)
141 {
142 $audiences[] = array(
143 'id' => $audiencePhoneId,
144 'contactType' => Retargeting\Audience::ENUM_CONTACT_TYPE_PHONE
145 );
146 }
147 if ($audienceEmailId)
148 {
149 $audiences[] = array(
150 'id' => $audienceEmailId,
151 'contactType' => Retargeting\Audience::ENUM_CONTACT_TYPE_EMAIL
152 );
153 }
154
155 if (count($audiences) == 0)
156 {
157 $isSuccess = false;
158 }
159
160 if (!$isSuccess)
161 {
162 return false;
163 }
164
165 foreach ($audiences as $audience)
166 {
167 $this->adsConfig->accountId = $config->get('ACCOUNT_ID');
168 $this->adsConfig->audienceId = $audience['id'];
169 $this->adsConfig->contactType = $audience['contactType'];
170 $this->adsConfig->type = $this->getAdsType();
171 $this->adsConfig->autoRemoveDayNumber = $config->get('AUTO_REMOVE_DAY_NUMBER');
172 $this->adsConfig->parentId = 'sender:'.$config->getId();
173
174 if ($adsContactType !== $this->adsConfig->contactType)
175 {
176 continue;
177 }
178
179 $contacts[$adsContactType] = array($message->getRecipientCode());
180 $this->addToAudience($clientId, $contacts);
181 }
182
183 return $isSuccess;
184 }
185
186 protected function addToAudience($clientId, $contacts)
187 {
188 $service = Retargeting\AdsAudience::getService();
189 $service->setClientId($clientId);
190 Retargeting\AdsAudience::useQueue();
191 return Retargeting\AdsAudience::addToAudience($this->adsConfig, $contacts);
192 }
193
194 public function end()
195 {
196
197 }
198}
saveConfiguration(Message\Configuration $configuration)