Skip to content

Instantly share code, notes, and snippets.

@SeRGei93
Last active August 29, 2022 13:59
Show Gist options
  • Save SeRGei93/deaaf73b9057c966a92d0b7e687c67bb to your computer and use it in GitHub Desktop.
Save SeRGei93/deaaf73b9057c966a92d0b7e687c67bb to your computer and use it in GitHub Desktop.
Bitrix Фейковая сущность для получения данных из любой таблицы
use Bitrix\Main\ORM\Entity;
use Bitrix\Main\ORM\Fields\IntegerField;
use Bitrix\Main\ORM\Fields\StringField;
use Bitrix\Main\ORM\Query\Filter\ConditionTree;
use Bitrix\Main\ORM\Query\Query;
// Создаём фейковую сущность только с нужными нам полями
$fakeEntity = Entity::compileEntity(
'MY_ORDER_PROPS_VARIANT',
[
(new IntegerField('ID'))
->configureAutocomplete(true)
->configurePrimary(true),
(new IntegerField('ORDER_PROPS_ID')),
(new StringField('NAME')),
(new StringField('XML_ID')),
(new IntegerField('SORT')),
(new StringField('DESCRIPTION'))
],
[
'namespace' => 'SlamSoft',
'table_name' => 'b_sale_order_props_variant'
]
);
/**
* Добавление фильтра
* получим элементы у которых есть DESCRIPTION
*/
$filter = (new ConditionTree())
->logic(ConditionTree::LOGIC_OR)
->whereNotNull('DESCRIPTION')
->where('DESCRIPTION', '');
// Выборка
$res = (new Query($fakeEntity))
->where($filter)
->setSelect(['*'])
->exec();
$result = [];
while ($obj = $res->fetchObject())
{
$result[] = $obj->collectValues();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment