Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/messageservice/lib/Providers/Edna/ |
Upload File : |
<?php namespace Bitrix\MessageService\Providers\Edna; use Bitrix\MessageService\Providers; use Bitrix\MessageService\Internal\Entity\ChannelTable; class Initiator extends Providers\Base\Initiator { protected Providers\OptionManager $optionManager; protected Providers\SupportChecker $supportChecker; protected EdnaRu $utils; protected Providers\CacheManager $cacheManager; protected string $providerId; protected string $channelType = ''; public function __construct( Providers\OptionManager $optionManager, Providers\SupportChecker $supportChecker, EdnaRu $utils, string $providerId ) { $this->optionManager = $optionManager; $this->supportChecker = $supportChecker; $this->utils = $utils; $this->providerId = $providerId; $this->cacheManager = new Providers\CacheManager($this->providerId); } /** * @return string */ public function getChannelType(): string { return $this->channelType; } /** * @return array<array{id: int, name: string, channelPhone: string}> */ public function getFromList(): array { if (!$this->supportChecker->canUse()) { return []; } // load from cache $cachedChannels = $this->cacheManager->getValue(Providers\CacheManager::CHANNEL_CACHE_ENTITY_ID); if (!empty($cachedChannels)) { return $cachedChannels; } $fromList = []; // load from db $res = ChannelTable::getChannelsByType($this->providerId, $this->getChannelType()); while ($channel = $res->fetch()) { $fromList[] = [ 'id' => (int)$channel['EXTERNAL_ID'], 'name' => $channel['NAME'], 'channelPhone' => $channel['ADDITIONAL_PARAMS']['channelAttribute'] ?? '', ]; } if (empty($fromList)) { // get channels from provider //$fromList = $this->utils->updateSavedChannelList($this->getChannelType()); \Bitrix\Main\Application::getInstance()->addBackgroundJob([$this->utils, 'updateSavedChannelList'], [$this->getChannelType()]); } // update cache $this->cacheManager->setValue(Providers\CacheManager::CHANNEL_CACHE_ENTITY_ID, $fromList); return $fromList; } public function isCorrectFrom($from): bool { $fromList = $this->getFromList(); foreach ($fromList as $item) { if ((int)$from === $item['id']) { return true; } } return false; } }