Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
interestsprovider.php
1<?php
2
4
10
12{
13 const SEARCH_TYPE = 'adinterest';
14 const ENTITY_TYPE = 'facebook_interests';
15
16 public function __construct(array $options = [])
17 {
18 parent::__construct();
19 $this->options['clientId'] = $options['clientId'];
20 }
21
22 public function isAvailable()
23 : bool
24 {
25 if($this->getOption('clientId'))
26 {
27 return true;
28 }
29
30 return false;
31 }
32
33 public function getItems(array $ids)
34 : array
35 {
36 return [];
37 }
38
39 public function getSelectedItems(array $ids)
40 : array
41 {
42 return [];
43 }
44
45 public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void
46 {
47 $service = Configurator::getService();
48 $service->setClientId($this->getOption('clientId'));
49 $searchQuery->setCacheable(false);
50
51 $response = Configurator::searchTargetingData(
52 AdCampaignFacebook::TYPE_CODE,
53 [
54 'q' => $searchQuery->getQuery(),
55 'type' => static::SEARCH_TYPE
56 ]
57 );
58
59 $items = [];
60
61 foreach($response as $value)
62 {
63 if(!isset($value['name']))
64 {
65 continue;
66 }
67
68 $topic = htmlspecialcharsbx($value['topic']);
69 $title = $value['name']. ($topic ?" ({$topic})" : "");
70 $items[] =
71 new Item(
72 [
73 'id' => $value['id'],
74 'entityId' => static::ENTITY_TYPE,
75 'title' => $title,
76 'customData' => ['audienceSize' => $value['audience_size']],
77 'tagOptions' => [
78 'bgColor' => "#{$this->stringToColor($title)}",
79 'textColor' => "#fff"
80 ]
81 ]
82 );
83 }
84
85 $dialog->addItems(
86 $items
87 );
88 }
89
90 protected function stringToColor($text)
91 {
92 $hx = dechex(crc32($text));
93
94 return substr($hx, 0, 6);
95 }
96}
doSearch(SearchQuery $searchQuery, Dialog $dialog)
getOption(string $option, $defaultValue=null)