Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
installs.php
1<?php
2
4
10
11final class Installs implements IAuthSettings
12{
13 private const FACEBOOK_INSTALLS_TTL = 840000;
14 public const FACEBOOK_INSTALLS_CACHE_ID = 'facebook|business|installs';
15
17 private static $current;
18
20 private $value;
21
22 private function __construct()
23 {}
24
25 public static function load() : ?self
26 {
27 if(!self::$current)
28 {
29 self::$current = new static();
30 $cache = Application::getInstance()->getManagedCache();
31 if ($cache->read(self::FACEBOOK_INSTALLS_TTL,self::FACEBOOK_INSTALLS_CACHE_ID))
32 {
33 self::$current->value = $cache->get(self::FACEBOOK_INSTALLS_CACHE_ID);
34 }
35 elseif
36 (
38 && ($response = $adapter->getExtension()->getInstalls())
39 && $response->isSuccess()
40 )
41 {
42 $cache->set(self::FACEBOOK_INSTALLS_CACHE_ID, self::$current->value = $response->fetch());
43 }
44 }
45
46 return self::$current;
47 }
48
49 public function getPixel()
50 {
51 return $this->value['PIXEL_ID'];
52 }
53 public function getPages()
54 {
55 return $this->value['PAGES'];
56 }
57 public function getInstagramProfiles()
58 {
59 return $this->value['INSTAGRAM_PROFILES'];
60 }
61 public function getBusinessManager()
62 {
63 return $this->value['BUSINESS_MANAGER_ID'];
64 }
65 public function getAdAccount()
66 {
67 return $this->value['AD_ACCOUNT_ID'];
68 }
69 public function getCatalog()
70 {
71 return $this->value['CATALOG_ID'];
72 }
73
74 public static function clearCache()
75 {
76 Application::getInstance()->getManagedCache()->clean(self::FACEBOOK_INSTALLS_CACHE_ID);
77 self::$current = null;
78 }
79
80 public function toArray(): array
81 {
82 return array_filter([
83 'business_manager_id' => $this->getBusinessManager(),
84 'ad_account_id' => $this->getAdAccount(),
85 'pixel_id' => $this->getPixel(),
86 'catalog_id' => $this->getCatalog(),
87 'page_id' => current($this->getPages() ?? []),
88 'ig_profile_id' => current($this->getInstagramProfiles() ?? [])
89 ]);
90 }
91}