Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accountfacebook.php
1<?
2
4
6use \Bitrix\Seo\Retargeting\Account;
7
9{
10 const TYPE_CODE = 'facebook';
11
12 const REGIONS_LIST_CACHE_TTL = 60*60*24*30; // 1 month
13
14 protected static $listRowMap = array(
15 'ID' => 'ACCOUNT_ID',
16 'NAME' => 'NAME',
17 );
18
19 public function getList()
20 {
21 return $this->getRequest()->send(array(
22 'methodName' => 'retargeting.account.list',
23 'parameters' => array()
24 ));
25 }
26
27 public function getProfile()
28 {
29 $response = $this->getRequest()->send(array(
30 'methodName' => 'retargeting.profile',
31 'parameters' => array()
32 ));
33
34 if ($response->isSuccess())
35 {
36 $data = $response->fetch();
37 return array(
38 'ID' => $data['ID'],
39 'NAME' => $data['NAME'],
40 'LINK' => $data['LINK'],
41 'PICTURE' => $data['PICTURE'] ? $data['PICTURE']['data']['url'] : null,
42 );
43 }
44
45 return null;
46 }
47
48 public function getRegionsList()
49 {
50 $cache = Application::getInstance()->getManagedCache();
51 $cacheId = 'seo|facebook|audience|region_list|'.LANGUAGE_ID;
52 $data = [];
53
54 if ($cache->read(static::REGIONS_LIST_CACHE_TTL, $cacheId))
55 {
56 $data = $cache->get($cacheId);
57 }
58 else
59 {
60 $result = $this->getRequest()->send(array(
61 'methodName' => 'retargeting.audience.regions',
62 'parameters' => array()
63 ));
64
65 if ($result->isSuccess())
66 {
67 foreach($result->getData() as $region)
68 {
69 $data[] = [
70 'id' => $region['key'],
71 'name' => $region['name']
72 ];
73 }
74 usort($data, function ($a, $b)
75 {
76 return strcmp($a['name'], $b['name']);
77 });
78 $cache->set($cacheId, $data);
79 }
80 }
81
82 return $data;
83 }
84}