Skip to content

Commit

Permalink
feat: Поддержка множественных свойств инфоблоков
Browse files Browse the repository at this point in the history
  • Loading branch information
webarchitect609 committed Mar 5, 2022
1 parent 20ff23b commit d2a2bd1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

2.3.0
-----

### Добавлено:

- Поддержка множественных свойств инфоблоков при помощи `DynamicMultiplePropertiesTable`

2.2.1
-----

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
`getIblockId()`;
- при объявлении `Bitrix\Main\Entity\ReferenceField` (или `Bitrix\Main\ORM\Fields\Relations\Reference`)
воспользоваться созданным классом;
```php
use Bitrix\Iblock\ElementTable;
use Bitrix\Main\Entity\ReferenceField;
Expand Down
50 changes: 50 additions & 0 deletions src/main/Iblock/Property/DynamicMultiplePropertiesTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/** @noinspection PhpMissingReturnTypeInspection */

namespace WebArch\BitrixOrmTools\Iblock\Property;

use Bitrix\Main\ORM\Data\DataManager;
use Bitrix\Main\ORM\Fields\Field;
use Bitrix\Main\ORM\Fields\IntegerField;
use Bitrix\Main\ORM\Fields\StringField;
use Bitrix\Main\ORM\Fields\TextField;

abstract class DynamicMultiplePropertiesTable extends DataManager
{
protected const TABLE_PREFIX = 'b_iblock_element_prop_m';

/**
* Возвращает id инфоблока.
*
* @return int
*/
abstract public static function getIblockId(): int;

/**
* @inheritDoc
*/
public static function getTableName()
{
return self::TABLE_PREFIX . static::getIblockId();
}

/**
* @inheritDoc
* @return array<string, Field>
*/
public static function getMap()
{
return [
'ID' => (new IntegerField('ID'))->configurePrimary(true)
->configureAutocomplete(true)
->configureRequired(false),
'IBLOCK_ELEMENT_ID' => (new IntegerField('IBLOCK_ELEMENT_ID'))->configureRequired(true),
'IBLOCK_PROPERTY_ID' => (new IntegerField('IBLOCK_PROPERTY_ID'))->configureRequired(true),
'VALUE' => (new TextField('VALUE'))->configureRequired(true),
'VALUE_ENUM' => (new IntegerField('VALUE_ENUM')),
'VALUE_NUM' => (new IntegerField('VALUE_NUM')),
'DESCRIPTION' => (new StringField('DESCRIPTION'))->configureSize(255),
];
}
}
2 changes: 2 additions & 0 deletions src/main/Iblock/Property/DynamicSinglePropertiesTable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @noinspection PhpMissingReturnTypeInspection */

namespace WebArch\BitrixOrmTools\Iblock\Property;

use Bitrix\Iblock\PropertyTable;
Expand Down
16 changes: 16 additions & 0 deletions src/test/Fixture/DynamicMultiplePropertiesTableFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace WebArch\BitrixOrmTools\Test\Fixture;

use WebArch\BitrixOrmTools\Iblock\Property\DynamicMultiplePropertiesTable;

class DynamicMultiplePropertiesTableFixture extends DynamicMultiplePropertiesTable
{
/**
* @inheritDoc
*/
public static function getIblockId(): int
{
return 0;
}
}
17 changes: 17 additions & 0 deletions src/test/Fixture/DynamicSinglePropertiesTableFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace WebArch\BitrixOrmTools\Test\Fixture;

use WebArch\BitrixOrmTools\Iblock\Property\DynamicSinglePropertiesTable;

class DynamicSinglePropertiesTableFixture extends DynamicSinglePropertiesTable
{
/**
* @inheritDoc
*/
public static function getIblockId(): int
{
return 0;
}
}

0 comments on commit d2a2bd1

Please sign in to comment.