Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Initiator.php
1<?php
2
4
7
9{
12 protected EdnaRu $utils;
14 protected string $providerId;
15
16 protected string $channelType = '';
17
18 public function __construct(
22 string $providerId
23 )
24 {
25 $this->optionManager = $optionManager;
26 $this->supportChecker = $supportChecker;
27 $this->utils = $utils;
28 $this->providerId = $providerId;
29 $this->cacheManager = new Providers\CacheManager($this->providerId);
30 }
31
35 public function getChannelType(): string
36 {
37 return $this->channelType;
38 }
39
43 public function getFromList(): array
44 {
45 if (!$this->supportChecker->canUse())
46 {
47 return [];
48 }
49
50 // load from cache
51 $cachedChannels = $this->cacheManager->getValue(Providers\CacheManager::CHANNEL_CACHE_ENTITY_ID);
52 if (!empty($cachedChannels))
53 {
54 return $cachedChannels;
55 }
56
57 $fromList = [];
58
59 // load from db
60 $res = ChannelTable::getChannelsByType($this->providerId, $this->getChannelType());
61 while ($channel = $res->fetch())
62 {
63 $fromList[] = [
64 'id' => (int)$channel['EXTERNAL_ID'],
65 'name' => $channel['NAME'],
66 'channelPhone' => $channel['ADDITIONAL_PARAMS']['channelAttribute'] ?? '',
67 ];
68 }
69
70 if (empty($fromList))
71 {
72 // get channels from provider
73 //$fromList = $this->utils->updateSavedChannelList($this->getChannelType());
74 \Bitrix\Main\Application::getInstance()->addBackgroundJob([$this->utils, 'updateSavedChannelList'], [$this->getChannelType()]);
75 }
76
77 // update cache
78 $this->cacheManager->setValue(Providers\CacheManager::CHANNEL_CACHE_ENTITY_ID, $fromList);
79
80 return $fromList;
81 }
82
83 public function isCorrectFrom($from): bool
84 {
85 $fromList = $this->getFromList();
86 foreach ($fromList as $item)
87 {
88 if ((int)$from === $item['id'])
89 {
90 return true;
91 }
92 }
93 return false;
94 }
95}
__construct(Providers\OptionManager $optionManager, Providers\SupportChecker $supportChecker, EdnaRu $utils, string $providerId)
Definition Initiator.php:18