1
0
mirror of synced 2024-11-26 23:36:08 +03:00
bitrix-module/intaro.retailcrm/lib/service/hl.php

122 lines
3.2 KiB
PHP
Raw Normal View History

2021-05-31 16:33:02 +03:00
<?php
/**
* @category Integration
* @package Intaro\RetailCrm\Service
* @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\Service;
use Bitrix\Main\ArgumentException;
2021-09-08 10:05:09 +03:00
use Bitrix\Main\Entity\Base;
2021-05-31 16:33:02 +03:00
use Bitrix\Main\Entity\DataManager;
use Bitrix\Main\Loader;
use Bitrix\Highloadblock as Highloadblock;
use Bitrix\Main\LoaderException;
use Bitrix\Main\ObjectPropertyException;
use Bitrix\Main\SystemException;
/**
* Class Hl
*
* Позволяет получить DataManager для HL-блоков
*
* @package Intaro\RetailCrm\Service
*/
class Hl
{
/**
* Получение DataManager класса управления HLBlock
*
2021-09-08 10:05:09 +03:00
* @param int $hlBlockId
*
2021-05-31 16:33:02 +03:00
* @return \Bitrix\Main\Entity\DataManager|null
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\LoaderException
* @throws \Bitrix\Main\ObjectPropertyException
* @throws \Bitrix\Main\SystemException
*/
2021-09-08 10:05:09 +03:00
public static function getHlClassById(int $hlBlockId): ?DataManager
{
$entity = self::getBaseEntityByHlId($hlBlockId);
return $entity->getDataClass();
}
/**
* @param int $HlBlockId
*
* @return \Bitrix\Main\Entity\Base|null
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\LoaderException
* @throws \Bitrix\Main\ObjectPropertyException
* @throws \Bitrix\Main\SystemException
*/
public static function getBaseEntityByHlId(int $HlBlockId): ?Base
2021-05-31 16:33:02 +03:00
{
Loader::includeModule('highloadblock');
2021-09-08 10:05:09 +03:00
2021-05-31 16:33:02 +03:00
$hlblock = Highloadblock\HighloadBlockTable::getById($HlBlockId)->fetch();
2021-09-08 10:05:09 +03:00
2021-05-31 16:33:02 +03:00
if (!$hlblock) {
return null;
}
2021-09-08 10:05:09 +03:00
return Highloadblock\HighloadBlockTable::compileEntity($hlblock);
2021-05-31 16:33:02 +03:00
}
2021-09-08 10:05:09 +03:00
2021-05-31 16:33:02 +03:00
/**
2021-09-08 10:05:09 +03:00
* @param string|null $tableName
2021-05-31 16:33:02 +03:00
*
2021-09-08 10:05:09 +03:00
* @return \Bitrix\Main\Entity\Base|null
2021-05-31 16:33:02 +03:00
*/
2021-09-08 10:05:09 +03:00
public static function getBaseEntityByTableName(?string $tableName): ?Base
2021-05-31 16:33:02 +03:00
{
2021-09-08 10:05:09 +03:00
if (!$tableName) {
return null;
}
2021-05-31 16:33:02 +03:00
try {
Loader::includeModule('highloadblock');
2021-09-08 10:05:09 +03:00
2021-05-31 16:33:02 +03:00
$hlblock = Highloadblock\HighloadBlockTable::query()
->addSelect('*')
2021-09-08 10:05:09 +03:00
->where('TABLE_NAME', '=', $tableName)
2021-05-31 16:33:02 +03:00
->exec()
->fetch();
2021-09-08 10:05:09 +03:00
2021-05-31 16:33:02 +03:00
if (!$hlblock) {
return null;
}
2021-09-08 10:05:09 +03:00
return Highloadblock\HighloadBlockTable::compileEntity($hlblock);
2021-05-31 16:33:02 +03:00
} catch (ObjectPropertyException | ArgumentException | SystemException | LoaderException $exception) {
AddMessage2Log($exception->getMessage());
2021-09-08 10:05:09 +03:00
2021-05-31 16:33:02 +03:00
return null;
}
}
2021-09-08 10:05:09 +03:00
/**
* Получение DataManager класса управления HLBlock по названию таблицы
*
* @param string $name
* @return \Bitrix\Main\Entity\DataManager|null|string
*/
public static function getHlClassByTableName(string $name)
{
$entity = self::getBaseEntityByTableName($name);
if ($entity instanceof Base) {
return $entity->getDataClass();
}
return null;
}
2021-05-31 16:33:02 +03:00
}