Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messagebase.php
1<?php
10
18
19Loc::loadMessages(__FILE__);
20
25abstract class MessageBase implements Message\iBase, Message\iAds
26{
28 const CODE_ADS_VK = 'ads_vk';
29 const CODE_ADS_FB = 'ads_fb';
30 const CODE_ADS_YA = 'ads_ya';
31 const CODE_ADS_GA = 'ads_ga';
32 const CODE_ADS_LOOKALIKE_FB = 'ads_lookalike_fb';
33 const CODE_ADS_LOOKALIKE_VK = 'ads_lookalike_vk';
34 const CODE_ADS_LOOKALIKE_YANDEX = 'ads_lookalike_yandex';
35
37 protected $configuration;
38
42 public function __construct()
43 {
44 $this->configuration = new Message\Configuration();
45 }
46
51 public function getName()
52 {
53 return Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_NAME_'.mb_strtoupper($this->getCode()));
54 }
55
56 public function getCode()
57 {
58 return static::CODE;
59 }
60
61 public function getSupportedTransports()
62 {
63 return array(static::CODE);
64 }
65
66 protected function getAdsType()
67 {
68 $map = Service::getTypeMap();
69 return $map[$this->getCode()];
70 }
71
72 protected function setConfigurationOptions()
73 {
74 $this->configuration->setArrayOptions(array(
75 array(
76 'type' => 'string',
77 'code' => 'CLIENT_ID',
78 'name' => Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_CONFIG_CLIENT_ID'),
79 'required' => true,
80 ),
81 array(
82 'type' => 'string',
83 'code' => 'ACCOUNT_ID',
84 'name' => Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_CONFIG_ACCOUNT_ID'),
85 'required' => false,
86 ),
87 array(
88 'type' => 'string',
89 'code' => 'AUDIENCE_ID',
90 'name' => (($this->getCode() === self::CODE_ADS_VK)
91 ? Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_CONFIG_USER_LIST_ID')
92 : Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_CONFIG_AUDIENCE_ID')),
93 'required' => true,
94 ),
95 array(
96 'type' => 'string',
97 'code' => 'AUDIENCE_EMAIL_ID',
98 'name' => Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_CONFIG_AUDIENCE_EMAIL_ID'),
99 'required' => false,
100 ),
101 array(
102 'type' => 'string',
103 'code' => 'AUDIENCE_PHONE_ID',
104 'name' => Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_CONFIG_AUDIENCE_PHONE_ID'),
105 'required' => false,
106 ),
107 array(
108 'type' => 'integer',
109 'code' => 'AUTO_REMOVE_DAY_NUMBER',
110 'name' => Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_CONFIG_AUTO_REMOVE_DAY_NUMBER'),
111 'required' => false,
112 ),
113 ));
114 }
115
123 public function loadConfiguration($id = null)
124 {
125 if (!$this->configuration->hasOptions())
126 {
128 }
129
130 Entity\Message::create()
131 ->setCode($this->getCode())
132 ->loadConfiguration($id, $this->configuration);
133
134
135 $self = $this;
137 $this->configuration->setView(
138 function () use ($self, $configuration)
139 {
140 if ($configuration->get('AUDIENCE_EMAIL_ID') || $configuration->get('AUDIENCE_PHONE_ID'))
141 {
142 $audienceId = array(
143 Retargeting\Audience::ENUM_CONTACT_TYPE_EMAIL => $configuration->get('AUDIENCE_EMAIL_ID'),
144 Retargeting\Audience::ENUM_CONTACT_TYPE_PHONE => $configuration->get('AUDIENCE_PHONE_ID'),
145 );
146 }
147 else
148 {
149 $audienceId = $configuration->get('AUDIENCE_ID');
150 }
151
152
153 $containerNodeId = 'seo-ads-' . $configuration->getId();
154 ob_start();
155 $provider = Service::getAdsProvider($self->getAdsType(), $configuration->getOption('CLIENT_ID')->getValue());
156
157 $audienceSize = $self->getConfigurationOptionValue($configuration, 'AUDIENCE_SIZE');
158 $audienceRegion = $self->getConfigurationOptionValue($configuration, 'AUDIENCE_REGION');
159 $autoRemoveDays = $self->getConfigurationOptionValue($configuration, 'AUTO_REMOVE_DAY_NUMBER');
160 $audienceLookalike = $self->getConfigurationOptionValue($configuration, 'AUDIENCE_LOOKALIKE');
161 $geoDistribution = $self->getConfigurationOptionValue($configuration, 'GEO_DISTRIBUTION');
162 $deviceDistribution = $self->getConfigurationOptionValue($configuration, 'DEVICE_DISTRIBUTION');
163
164 $audienceLookalikeMode = $provider['IS_SUPPORT_LOOKALIKE_AUDIENCE'] && ($this instanceof iLookalikeAds);
165
166 $GLOBALS['APPLICATION']->IncludeComponent(
167 'bitrix:seo.ads.retargeting',
168 '',
169 array(
170 'INPUT_NAME_PREFIX' => 'CONFIGURATION_',
171 'CONTAINER_NODE_ID' => $containerNodeId,
172 'PROVIDER' => $provider,
173 'ACCOUNT_ID' => $configuration->getOption('ACCOUNT_ID')->getValue(),
174 'CLIENT_ID' => $configuration->getOption('CLIENT_ID')->getValue(),
175 'AUDIENCE_ID' => $audienceId,
176 'AUDIENCE_SIZE' => $audienceSize,
177 'AUDIENCE_REGION' => $audienceRegion,
178 'AUDIENCE_LOOKALIKE_MODE' => $audienceLookalikeMode,
179 'AUTO_REMOVE_DAY_NUMBER' => $autoRemoveDays,
180 'AUDIENCE_LOOKALIKE' => $audienceLookalike,
181 'GEO_DISTRIBUTION' => $geoDistribution,
182 'DEVICE_DISTRIBUTION' => $deviceDistribution,
183 'JS_DESTROY_EVENT_NAME' => '',
184 'TITLE_NODE_SELECTOR' => '[data-role="letter-title"]',
185 'HAS_ACCESS' => true, // TODO: check SENDER-module permissions
186 'MESSAGE_CODE' => $self::CODE,
187 )
188 );
189
190 $result = ob_get_clean();
191 $result .= "<div id=\"$containerNodeId\"></div>";
192 return $result;
193 }
194 );
195
197 }
198
199 private function getConfigurationOptionValue(Message\Configuration $configuration, string $optionName)
200 {
201 return $configuration->getOption($optionName)
202 ? $configuration->getOption($optionName)->getValue()
203 : null
204 ;
205 }
206
214 {
215 $config = $configuration;
216 $clientId = $config->getOption('CLIENT_ID')->getValue();
217 if (!$clientId)
218 {
219 $result = new Result();
220 $result->addError(new Error(Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_ERROR_NO_CLIENT')));
221
222 return $result;
223 }
224 $provider = Service::getAdsProvider($this->getAdsType(), $clientId);
225
226 if (
227 !$provider['IS_SUPPORT_LOOKALIKE_AUDIENCE'] &&
228 !$config->getOption('AUDIENCE_ID')->getValue() &&
229 !$config->getOption('AUDIENCE_EMAIL_ID')->getValue() &&
230 !$config->getOption('AUDIENCE_PHONE_ID')->getValue()
231 )
232 {
233 $result = new Result();
234 $result->addError(new Error(Loc::getMessage('SENDER_INTEGRATION_SEO_MESSAGE_ERROR_NO_AUDIENCE')));
235
236 return $result;
237 }
238
239 return Entity\Message::create()
240 ->setCode($this->getCode())
241 ->saveConfiguration($this->configuration);
242 }
243
250 public function removeConfiguration($id)
251 {
252 $result = Entity\Message::removeById($id);
253 return $result->isSuccess();
254 }
255
262 public function copyConfiguration($id)
263 {
264 return Entity\Message::create()
265 ->setCode($this->getCode())
266 ->copyConfiguration($id);
267 }
268}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
saveConfiguration(Message\Configuration $configuration)
static getAdsProvider($adsType, $clientId=null)
Definition service.php:70
$GLOBALS['____1444769544']
Definition license.php:1