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/rest/lib/Repository/ |
Upload File : |
<?php namespace Bitrix\Rest\Repository; use Bitrix\Main\Entity\Query; use Bitrix\Rest\Entity\Collection\IntegrationCollection; use Bitrix\Rest\Entity\Integration; use Bitrix\Rest\Enum\APAuth\PasswordType; use Bitrix\Rest\Enum\Integration\ElementCodeType; use Bitrix\Rest\Preset\EO_Integration_Query; use Bitrix\Rest\Preset\IntegrationTable; class IntegrationRepository implements \Bitrix\Rest\Contract\Repository\IntegrationRepository { public function __construct( private readonly \Bitrix\Rest\Model\Mapper\Integration $mapper, ) {} public function getCloudPaidIntegrations(): IntegrationCollection { $integrationList = $this->buildNotSystemIntegrationsQuery() ->addSelect('*') ->setOrder(['ID' => 'ASC']) ->fetchAll(); return $this->createIntegrationCollectionFromModelArray($integrationList); } public function getBoxedPaidIntegrations(): IntegrationCollection { $integrationList = $this->buildNotSystemIntegrationsQuery() ->addSelect('*') ->setOrder(['ID' => 'ASC']) ->addFilter('!=ELEMENT_CODE', ElementCodeType::IN_WEBHOOK->value) ->fetchAll(); return $this->createIntegrationCollectionFromModelArray($integrationList); } public function hasUserIntegrations(): bool { $integration = $this->buildNotSystemIntegrationsQuery() ->setLimit(1) ->setSelect(['ID']); return !empty($integration->fetch()); } public function hasNotInWebhookUserIntegrations(): bool { $query = $this->buildNotSystemIntegrationsQuery() ->setLimit(1) ->setSelect(['ID']) ->addFilter('!=ELEMENT_CODE', ElementCodeType::IN_WEBHOOK->value); return !empty($query->fetch()); } /** * @return EO_Integration_Query */ private function buildNotSystemIntegrationsQuery(): Query { return IntegrationTable::query() ->where(Query::filter() ->logic('or') ->where([ ['PASSWORD.TYPE', PasswordType::User->value], ['PASSWORD.TYPE', null] ]) ); } public function getById(int $id): ?Integration { $integration = IntegrationTable::query() ->addSelect('*') ->where('ID', $id) ->setLimit(1) ->fetch(); if (!$integration) { return null; } return $this->mapper->mapArrayToEntity($integration); } /** * @param \Bitrix\Rest\Preset\EO_Integration_Collection $modelCollection * @return IntegrationCollection * @throws \Bitrix\Main\ArgumentException */ private function createIntegrationCollectionFromModelArray(array $modelCollection): IntegrationCollection { $collection = new IntegrationCollection(); foreach ($modelCollection as $model) { $collection->add($this->mapper->mapArrayToEntity($model)); } return $collection; } }