2021-05-31 16:33:02 +03:00
|
|
|
<?php
|
|
|
|
|
2024-04-29 11:44:31 +03:00
|
|
|
/**
|
|
|
|
* @category Integration
|
|
|
|
* @package Intaro\RetailCrm\Repository
|
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see http://retailcrm.ru/docs
|
|
|
|
*/
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
namespace Intaro\RetailCrm\Repository;
|
|
|
|
|
|
|
|
use CSite;
|
|
|
|
use RetailcrmConfigProvider;
|
2024-04-01 09:34:11 +03:00
|
|
|
use Bitrix\Iblock\IblockTable;
|
2021-05-31 16:33:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SiteRepository
|
|
|
|
* @package Intaro\RetailCrm\Repository
|
|
|
|
*/
|
|
|
|
class SiteRepository
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getDefaultServerName(): ?string
|
|
|
|
{
|
|
|
|
$rsSites = CSite::GetList($by, $sort, ['ACTIVE' => 'Y']);
|
|
|
|
|
|
|
|
while ($ar = $rsSites->Fetch()) {
|
|
|
|
if ($ar['DEF'] === 'Y') {
|
|
|
|
return RetailcrmConfigProvider::getProtocol() . $ar['SERVER_NAME'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2024-04-01 09:34:11 +03:00
|
|
|
|
|
|
|
public static function getDomainList(): ?array
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
$resultBlock = [];
|
|
|
|
$resultSites = [];
|
|
|
|
|
|
|
|
try {
|
|
|
|
$iBlockResult = IblockTable::GetList(['select' => ['ID', 'LID']], $sort, ['ACTIVE' => 'Y']);
|
|
|
|
|
|
|
|
while ($iBlock = $iBlockResult->Fetch()) {
|
|
|
|
$resultBlock[] = $iBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
$resultBlock = array_column($resultBlock, 'LID', 'ID');
|
|
|
|
|
|
|
|
$rsSites = CSite::GetList($by, $sort, ['ACTIVE' => 'Y']);
|
|
|
|
|
|
|
|
while ($site = $rsSites->Fetch()) {
|
|
|
|
$resultSites[] = $site;
|
|
|
|
}
|
|
|
|
|
|
|
|
$resultSites = array_column($resultSites, 'SERVER_NAME', 'LID');
|
|
|
|
|
|
|
|
foreach ($resultBlock as $id => $lid) {
|
|
|
|
if (isset($resultSites[$lid])) {
|
|
|
|
$result[$id] = RetailcrmConfigProvider::getProtocol() . $resultSites[$lid];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (\Throwable $exception) {
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
'SiteRepository:getDomainList',
|
|
|
|
'domain',
|
|
|
|
'Error when obtaining domains: ' . $exception->getMessage()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2021-05-31 16:33:02 +03:00
|
|
|
}
|