This commit is contained in:
root
2025-11-13 19:52:28 +03:00
parent 8aeeb05b7d
commit 807dec3b6c
4646 changed files with 163445 additions and 626017 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\Public\Service\RestValidator\Trait;
abstract class BaseFieldValidator extends BaseValidator implements ValidatorFieldInterface
{
use Trait\FileValidatorTrait;
use Trait\OrmFieldTrait;
protected function __construct()
{
parent::__construct();
$this->setFileValidator(new Type\IblockFile());
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Main\Error;
use Bitrix\Main\Result;
abstract class BaseFilterFieldValidator extends BaseValidator implements ValidatorFilterInterface
{
protected array $scalarFields;
abstract protected function prepareFilterField(string $field): array;
public function run(array $rawData): Result
{
$result = new Result();
$this->prepareFilterLevel($rawData, $result);
return $result;
}
protected function getAllowedFilterFields(): array
{
return
$this->isExistsFieldAliases()
? array_values($this->getFieldAliases())
: $this->getFields()
;
}
protected function prepareFilterLevel(array $rawData, Result $result): void
{
$filterFields = array_fill_keys($this->getAllowedFilterFields(), true);
$fieldsMap = [];
if ($this->isExistsFieldAliases())
{
$fieldsMap = $this->getFieldAliases();
$fieldsMap = array_flip($fieldsMap);
}
foreach ($rawData as $filterKey => $filterValue)
{
if (is_string($filterKey))
{
$fieldInfo = $this->prepareFilterField($filterKey);
$fieldName = $fieldInfo['FIELD'];
if (!isset($filterFields[$fieldName]))
{
continue;
}
$realField = $fieldsMap[$fieldName] ?? $fieldName;
if (!$this->isCorrectValue($realField, $filterValue))
{
$result->addError($this->getValueError($filterKey));
}
}
elseif (is_int($filterKey) && is_array($filterValue))
{
$this->prepareFilterLevel($filterValue, $result);
}
}
}
protected function isCorrectValue(string $fieldName, mixed $value): bool
{
if ($this->isScalarField($fieldName))
{
return is_scalar($value);
}
if (is_array($value))
{
foreach ($value as $item)
{
if (!is_scalar($item))
{
return false;
}
}
return true;
}
return parent::isCorrectValue($fieldName, $value);
}
protected function getValueError($fieldName): Error
{
return new Error(
'Wrong format value of filter field `' . $fieldName . '`.'
);
}
public function setScalarFields(array $fields): static
{
$this->scalarFields = array_fill_keys($fields, true);
return $this;
}
public function getScalarFields(): array
{
return array_keys($this->scalarFields);
}
public function isScalarField(string $fieldName): bool
{
return isset($this->scalarFields[$fieldName]);
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Main\Error;
use Bitrix\Main\Result;
abstract class BaseValidator implements ValidatorInterface
{
protected static array $instances;
protected array $fieldAliases = [];
protected array $fields = [];
public static function getInstance(): static
{
$class = get_called_class();
if (!isset(self::$instances[$class]))
{
self::$instances[$class] = new $class();
}
return self::$instances[$class];
}
protected function __construct()
{
$this->init();
}
abstract protected function init(): void;
public function setFields(array $fields): static
{
$this->fields = $fields;
return $this;
}
public function getFields(): array
{
return $this->fields ?? [];
}
public function isExistsFieldAliases(): bool
{
return !empty($this->fieldAliases);
}
public function setFieldAliases(array $aliases): static
{
$preparedAliases = [];
foreach ($aliases as $field => $alias)
{
if (!is_string($field) || empty($field))
{
continue;
}
if (!is_string($alias) || empty($alias))
{
continue;
}
$preparedAliases[$field] = $alias;
}
$this->fieldAliases = $preparedAliases;
return $this;
}
public function getFieldAliases(): array
{
return $this->fieldAliases;
}
public function getAlias(string $fieldName): string
{
return $this->fieldAliases[$fieldName] ?? $fieldName;
}
public function getRealAlias(string $fieldName): ?string
{
return $this->fieldAliases[$fieldName] ?? null;
}
public function run(array $rawData): Result
{
$result = new Result();
$useAliases = $this->isExistsFieldAliases();
foreach ($this->getFields() as $fieldName)
{
$index = $useAliases ? $this->getRealAlias($fieldName) : $fieldName;
if ($index === null)
{
continue;
}
if (!isset($rawData[$index]))
{
continue;
}
if (!$this->isCorrectValue($fieldName, $rawData[$index]))
{
$result->addError($this->getValueError($index));
}
}
return $result;
}
protected function isCorrectValue(string $fieldName, mixed $value): bool
{
return is_scalar($value);
}
protected function getValueError($fieldName): Error
{
return new Error(
'Wrong format of field `' . $fieldName . '`.'
);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\ElementTable;
use Bitrix\Main\ORM\Entity;
class ElementFieldValidator extends BaseFieldValidator
{
protected function getEntity(): Entity
{
return ElementTable::getEntity();
}
protected function isCorrectValue(string $fieldName, mixed $value): bool
{
if ($fieldName === 'PREVIEW_PICTURE' || $fieldName === 'DETAIL_PICTURE')
{
$valueValidator = $this->getFileValidator();
return $valueValidator->isCorrectFormat($value);
}
else
{
return is_scalar($value);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Iblock\ElementTable;
use Bitrix\Main\ORM\Entity;
class ElementFilterFieldValidator extends BaseFilterFieldValidator
{
use Trait\OrmFilterTrait;
use Trait\IblockFilterOperationTrait;
protected function getEntity(): Entity
{
return ElementTable::getEntity();
}
protected function getProcessedScalarFields(): array
{
return [
'IBLOCK_ID',
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Main\ORM\Entity;
class PropertyFieldValidator extends BaseFieldValidator
{
protected function getEntity(): Entity
{
return PropertyTable::getEntity();
}
protected function getUnprocessedFields(): array
{
return [
'DEFAULT_VALUE',
'USER_TYPE_SETTINGS',
'USER_TYPE_SETTINGS_LIST'
];
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Main\ORM\Entity;
class PropertyFilterFieldValidator extends BaseFilterFieldValidator
{
use Trait\OrmFilterTrait;
use Trait\OrmFilterOperationTrait;
protected function getEntity(): Entity
{
return PropertyTable::getEntity();
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Main\ORM\Entity;
class PropertyScalarFilterValidator extends BaseFilterFieldValidator
{
use Trait\IblockFilterOperationTrait;
use Trait\OrmFieldTrait;
protected function getEntity(): Entity
{
return PropertyTable::getEntity();
}
protected function getUnprocessedFields(): array
{
return [
'SORT',
'DEFAULT_VALUE',
'ROW_COUNT',
'COL_COUNT',
'LIST_TYPE',
'FILE_TYPE',
'MULTIPLE_CNT',
'WITH_DESCRIPTION',
'USER_TYPE_SETTINGS',
'HINT',
];
}
protected function init(): void
{
$fields = $this->getProcessedFields();
$this->setFields($fields);
$this->setScalarFields($fields);
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Iblock\PropertyTable;
class PropertyValueFilterValidator extends BaseFilterFieldValidator
{
use Trait\IblockFilterOperationTrait;
private const FIELD_NAME_PREFIX = 'PROPERTY_';
protected int $iblockId;
public function setIblockId(int $iblockId): self
{
if ($iblockId < 0)
{
return $this;
}
if ($this->getIblockId() !== $iblockId)
{
$this->iblockId = $iblockId;
$this->setFields([]);
$this->setFieldAliases([]);
$this->init();
}
return $this;
}
public function getIblockId(): ?int
{
return $this->iblockId ?? null;
}
private function getPropertyIndex(int $propertyId): string
{
return self::FIELD_NAME_PREFIX . $propertyId;
}
protected function init(): void
{
$iblockId = $this->getIblockId();
if ($iblockId)
{
$fields = [];
$iterator = PropertyTable::getList([
'select' => [
'ID',
],
'filter' => [
'=IBLOCK_ID' => $this->getIblockId(),
'=ACTIVE' => 'Y',
'!=PROPERTY_TYPE' => PropertyTable::TYPE_FILE,
],
'order' => [
'ID' => 'ASC',
],
'cache' => [
'ttl' => 86400,
],
]);
while ($row = $iterator->fetch())
{
$propertyIndex = $this->getPropertyIndex((int)$row['ID']);
$fields[] = $propertyIndex;
}
unset(
$row,
$iterator,
);
$this->setFields($fields);
}
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\PropertyTable;
class SimpleNoFilePropertyValueValidator extends SimplePropertyValueValidator
{
protected function getPropertyFilter(int $iblockId): array
{
$filter = parent::getPropertyFilter($iblockId);
$filter['!=PROPERTY_TYPE'] = PropertyTable::TYPE_FILE;
return $filter;
}
}

View File

@@ -0,0 +1,240 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Main\Error;
use Bitrix\Main\Result;
class SimplePropertyValueValidator extends BaseValidator
{
use Trait\FileValidatorTrait;
private const FIELD_NAME_PREFIX = 'PROPERTY_';
protected int $iblockId;
protected array $properties;
public function setIblockId(int $iblockId): self
{
if ($iblockId < 0)
{
return $this;
}
if ($this->getIblockId() !== $iblockId)
{
$this->iblockId = $iblockId;
$this->setFieldAliases([]);
$this->init();
}
return $this;
}
public function getIblockId(): ?int
{
return $this->iblockId ?? null;
}
private function getPropertyIndex(int $propertyId): string
{
return self::FIELD_NAME_PREFIX . $propertyId;
}
protected function init(): void
{
$iblockId = $this->getIblockId();
if ($iblockId)
{
$fields = [];
$properties = [];
$iterator = PropertyTable::getList([
'select' => [
'ID',
'PROPERTY_TYPE',
'MULTIPLE',
],
'filter' => $this->getPropertyFilter($iblockId),
'order' => [
'ID' => 'ASC',
],
'cache' => [
'ttl' => 86400,
],
]);
while ($row = $iterator->fetch())
{
$row['ID'] = (int)$row['ID'];
$id = $row['ID'];
$propertyIndex = $this->getPropertyIndex($id);
$fields[] = $propertyIndex;
$properties[$propertyIndex] = $row;
}
unset(
$row,
$iterator,
);
$this->setFields($fields);
$this->properties = $properties;
}
}
protected function getPropertyFilter(int $iblockId): array
{
return [
'=IBLOCK_ID' => $iblockId,
'=ACTIVE' => 'Y',
'=USER_TYPE' => null,
];
}
protected function isPropertyExists(string $propertyIndex): bool
{
return isset($this->properties[$propertyIndex]);
}
protected function getPropertyType(string $propertyIndex): string
{
return $this->properties[$propertyIndex]['PROPERTY_TYPE'] ?? PropertyTable::TYPE_STRING;
}
protected function isPropertyMultiple(string $propertyIndex): bool
{
return ($this->properties[$propertyIndex]['MULTIPLE'] ?? 'N') === 'Y';
}
public function run(array $rawData): Result
{
$result = new Result();
$useAliases = $this->isExistsFieldAliases();
foreach ($this->getFields() as $propertyIndex)
{
$index = $useAliases ? $this->getRealAlias($propertyIndex) : $propertyIndex;
if ($index === null)
{
continue;
}
if (!isset($rawData[$index]))
{
continue;
}
if (!$this->isCorrectValue($propertyIndex, $rawData[$index]))
{
$result->addError(new Error(
'Wrong format value of field `' . $index . '`.'
));
}
}
return $result;
}
protected function isCorrectValue(string $fieldName, $value): bool
{
if (!$this->isPropertyExists($fieldName))
{
return true;
}
$value = $this->normalizeValueFormat($value);
if (!$this->isPropertyMultiple($fieldName) && count($value) > 1)
{
return false;
}
$isFile = $this->getPropertyType($fieldName) === PropertyTable::TYPE_FILE;
$result = true;
foreach ($value as $row)
{
if ($isFile)
{
$result = $this->isCorrectFileValue($row);
}
else
{
$result = $this->isCorrectNonFileValue($row);
}
if (!$result)
{
break;
}
}
return $result;
}
protected function isCorrectFileValue(mixed $value): bool
{
$validator = $this->getFileValidator();
return $validator->isCorrectFormat($value);
}
protected function isCorrectNonFileValue(mixed $value): bool
{
if (is_scalar($value))
{
return true;
}
if (is_array($value))
{
$value = array_change_key_case($value, CASE_UPPER);
if (isset($value['VALUE']) && is_scalar($value['VALUE']))
{
return true;
}
}
return false;
}
protected function normalizeValueFormat(mixed $value): array
{
if (!is_array($value))
{
return [$value];
}
if (isset($value['VALUE']))
{
return [$value['VALUE']];
}
if (isset($value['value']))
{
return [$value['value']];
}
if (array_is_list($value))
{
return $value;
}
$prepare = [];
$needNormalize = false;
foreach (array_keys($value) as $index)
{
if (is_int($index))
{
continue;
}
if (preg_match('/^n[0-9]+$/', $index, $prepare))
{
continue;
}
$needNormalize = true;
break;
}
return
$needNormalize
? [$value]
: $value
;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format\Type;
interface FileInterface
{
public function isCorrectFormat(mixed $value) : bool;
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format\Type;
class IblockFile implements FileInterface
{
public function isCorrectFormat(mixed $value): bool
{
if (!is_array($value))
{
return false;
}
$file = $value['VALUE'] ?? $value;
if (!is_array($file))
{
return false;
}
if (!isset($file['tmp_name']) && !isset($file['del']))
{
return false;
}
return true;
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format\Type;
class SkipFile implements FileInterface
{
public function isCorrectFormat(mixed $value): bool
{
return true;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
interface ValidatorFieldInterface
{
public function setFileValidator(Type\FileInterface $validator): static;
public function getFileValidator(): Type\FileInterface;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
interface ValidatorFilterInterface extends ValidatorInterface
{
public function setScalarFields(array $fields): static;
public function getScalarFields(): array;
public function isScalarField(string $fieldName): bool;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Format;
use Bitrix\Main\Result;
interface ValidatorInterface
{
public function setFields(array $fields): static;
public function getFields(): array;
public function isExistsFieldAliases();
public function setFieldAliases(array $aliases): static;
public function getFieldAliases(): array;
public function getAlias(string $fieldName): string;
public function getRealAlias(string $fieldName): ?string;
public function run(array $rawData): Result;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Iblock\Public\Service\RestValidator\Format\Type;
trait FileValidatorTrait
{
protected Type\FileInterface $fileValidator;
public function setFileValidator(Type\FileInterface $validator): static
{
$this->fileValidator = $validator;
return $this;
}
public function getFileValidator(): Type\FileInterface
{
return $this->fileValidator;
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Trait;
trait IblockFilterOperationTrait
{
protected function prepareFilterField(string $field): array
{
return \CIBlock::MkOperationFilter($field);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Main\ORM\Entity;
trait OrmFieldTrait
{
abstract public function setFields(array $fields);
abstract protected function getEntity(): Entity;
protected function getUnprocessedFields(): array
{
return [];
}
protected function getProcessedFields(): array
{
$result = [];
$unprocessedFields = $this->getUnprocessedFields();
$entity = $this->getEntity();
foreach ($entity->getScalarFields() as $field)
{
$name = $field->getColumnName();
if (in_array($name, $unprocessedFields, true))
{
continue;
}
$result[] = $name;
}
return $result;
}
protected function init(): void
{
$this->setFields($this->getProcessedFields());
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Trait;
trait OrmFilterOperationTrait
{
protected function prepareFilterField(string $field): array
{
$parser = new \CSQLWhere();
return $parser->MakeOperation($field);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Bitrix\Iblock\Public\Service\RestValidator\Trait;
use Bitrix\Main\ORM\Entity;
trait OrmFilterTrait
{
abstract public function setFields(array $fields);
abstract public function setScalarFields(array $fields);
abstract protected function getEntity(): Entity;
protected function getUnprocessedFields(): array
{
return [];
}
protected function getProcessedFields(): array
{
$result = [];
$unprocessedFields = $this->getUnprocessedFields();
$entity = $this->getEntity();
foreach ($entity->getScalarFields() as $field)
{
$name = $field->getColumnName();
if (in_array($name, $unprocessedFields, true))
{
continue;
}
$result[] = $name;
}
return $result;
}
protected function getProcessedScalarFields(): array
{
return [];
}
protected function init(): void
{
$this->setFields($this->getProcessedFields());
$this->setScalarFields($this->getProcessedScalarFields());
}
}

View File

@@ -4,6 +4,7 @@ namespace Bitrix\Iblock\UI\Input;
use Bitrix\Iblock\Integration\UI\EntitySelector\IblockPropertyElementProvider;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Type;
use Bitrix\Main\UI;
@@ -11,8 +12,19 @@ use Bitrix\Main\Web\Json;
class Element
{
protected static bool $uiIncluded;
public static function renderSelector(array $property, array|int|string|null $values, array $config): string
{
if (!isset(self::$uiIncluded))
{
self::$uiIncluded = Loader::includeModule('ui');
}
if (!self::$uiIncluded)
{
return '';
}
$rowId = trim((string)($config['ROW_ID'] ?? ''));
$fieldName = trim((string)($config['FIELD_NAME'] ?? ''));
if ($fieldName === '')
@@ -57,15 +69,34 @@ class Element
$config['CHANGE_EVENTS'] = is_string($config['CHANGE_EVENTS']) ? [$config['CHANGE_EVENTS']] : [];
}
$entityValues = [];
foreach ($values as $value)
{
$entityValues[] = [
$config['ENTITY_ID'],
$value,
];
}
$entities = [
[
'id' => $config['ENTITY_ID'],
'dynamicLoad' => true,
'dynamicSearch' => true,
'options'=> [
'iblockId' => (int)($property['LINK_IBLOCK_ID'] ?? 0),
'propertyType' => (string)($property['USER_TYPE'] ?? ''),
],
]
];
$config = Json::encode([
'containerId' => $containerId,
'fieldName' => $fieldName . ($multiple ? '[]' : ''),
'multiple' => $multiple,
'collectionType' => 'int',
'selectedItems' => $values,
'iblockId' => (int)($property['LINK_IBLOCK_ID'] ?? 0),
'userType' => (string)($property['USER_TYPE'] ?? ''),
'entityId' => $config['ENTITY_ID'],
'selectedItems' => $entityValues,
'entities' => $entities,
'searchMessages' => [
'title' => $config['SEARCH_TITLE'],
'subtitle' => $config['SEARCH_SUBTITLE'],
@@ -73,13 +104,13 @@ class Element
'changeEvents' => $config['CHANGE_EVENTS'],
]);
UI\Extension::load('iblock.field-selector');
UI\Extension::load('ui.field-selector');
return <<<HTML
<div id="$containerId"></div>
<script>
(function() {
const selector = new BX.Iblock.FieldSelector({$config});
const selector = new BX.UI.FieldSelector({$config});
selector.render();
})();
</script>

View File

@@ -4,6 +4,7 @@ namespace Bitrix\Iblock\UI\Input;
use Bitrix\Iblock\Integration\UI\EntitySelector\IblockPropertySectionProvider;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Type;
use Bitrix\Main\UI;
@@ -11,8 +12,19 @@ use Bitrix\Main\Web\Json;
class Section
{
protected static bool $uiIncluded;
public static function renderSelector(array $property, array|int|string|null $values, array $config): string
{
if (!isset(self::$uiIncluded))
{
self::$uiIncluded = Loader::includeModule('ui');
}
if (!self::$uiIncluded)
{
return '';
}
$rowId = trim((string)($config['ROW_ID'] ?? ''));
$fieldName = trim((string)($config['FIELD_NAME'] ?? ''));
if ($fieldName === '')
@@ -57,15 +69,34 @@ class Section
$config['CHANGE_EVENTS'] = is_string($config['CHANGE_EVENTS']) ? [$config['CHANGE_EVENTS']] : [];
}
$entityValues = [];
foreach ($values as $value)
{
$entityValues[] = [
$config['ENTITY_ID'],
$value,
];
}
$entities = [
[
'id' => $config['ENTITY_ID'],
'dynamicLoad' => true,
'dynamicSearch' => true,
'options'=> [
'iblockId' => (int)($property['LINK_IBLOCK_ID'] ?? 0),
'propertyType' => (string)($property['USER_TYPE'] ?? ''),
],
]
];
$config = Json::encode([
'containerId' => $containerId,
'fieldName' => $fieldName . ($multiple ? '[]' : ''),
'multiple' => $multiple,
'collectionType' => 'int',
'selectedItems' => $values,
'iblockId' => (int)($property['LINK_IBLOCK_ID'] ?? 0),
'userType' => (string)($property['USER_TYPE'] ?? ''),
'entityId' => $config['ENTITY_ID'],
'selectedItems' => $entityValues,
'entities' => $entities,
'searchMessages' => [
'title' => $config['SEARCH_TITLE'],
'subtitle' => $config['SEARCH_SUBTITLE'],
@@ -73,13 +104,13 @@ class Section
'changeEvents' => $config['CHANGE_EVENTS'],
]);
UI\Extension::load('iblock.field-selector');
UI\Extension::load('ui.field-selector');
return <<<HTML
<div id="$containerId"></div>
<script>
(function() {
const selector = new BX.Iblock.FieldSelector($config);
const selector = new BX.UI.FieldSelector($config);
selector.render();
})();
</script>

View File

@@ -1,10 +1,4 @@
<?php
/**
* Bitrix Framework
* @package bitrix
* @subpackage iblock
* @copyright 2001-2018 Bitrix
*/
namespace Bitrix\Iblock;

View File

@@ -1,10 +1,11 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\ORM\Fields\Validators;
use Bitrix\Main;
use Bitrix\Main\ORM;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM;
use Bitrix\Main\ORM\Fields\Validators;
/**
* Class ElementTable
@@ -388,7 +389,7 @@ class ElementTable extends ORM\Data\DataManager
/**
* Add iblock element.
*
* @param array $data Element data.
* @param array $data Element data.
* @return ORM\Data\AddResult
*/
public static function add(array $data): ORM\Data\AddResult
@@ -404,8 +405,8 @@ class ElementTable extends ORM\Data\DataManager
/**
* Updates iblock element by primary key.
*
* @param mixed $primary Element primary key.
* @param array $data Element data.
* @param mixed $primary Element primary key.
* @param array $data Element data.
* @return ORM\Data\UpdateResult
*/
public static function update($primary, array $data): ORM\Data\UpdateResult
@@ -421,7 +422,7 @@ class ElementTable extends ORM\Data\DataManager
/**
* Deletes iblock element by primary key.
*
* @param mixed $primary Element primary key.
* @param mixed $primary Element primary key.
* @return ORM\Data\DeleteResult
*/
public static function delete($primary): ORM\Data\DeleteResult

View File

@@ -219,4 +219,9 @@ abstract class BaseFieldAssembler extends FieldAssembler
return $result;
}
}
protected function isCustomEditable(string $columnId): bool
{
return in_array($columnId, $this->customEditableColumnIds);
}
}

View File

@@ -124,11 +124,6 @@ final class ElementFieldAssembler extends BaseFieldAssembler
unset($row, $rows);
}
private function isCustomEditable(string $columnId): bool
{
return in_array($columnId, $this->customEditableColumnIds);
}
private function getEditValue(string $rowId, string $columnId, array $property, $values): string
{
return Element::renderSelector(

View File

@@ -122,11 +122,6 @@ final class SectionFieldAssembler extends BaseFieldAssembler
}
}
private function isCustomEditable(string $columnId): bool
{
return in_array($columnId, $this->customEditableColumnIds);
}
private function getEditValue(string $rowId, string $columnId, array $property, $values): string
{
return Section::renderSelector(

View File

@@ -5,24 +5,14 @@ namespace Bitrix\Iblock\Grid\Row\Assembler\Property;
use Bitrix\Iblock\Grid\Column\ElementPropertyProvider;
use Bitrix\Iblock\Grid\RowType;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Main\Grid\Row\FieldAssembler;
use CIBlockProperty;
use Closure;
final class UserTypePropertyFieldAssembler extends FieldAssembler
final class UserTypePropertyFieldAssembler extends BaseFieldAssembler
{
private int $iblockId;
private array $customEditableColumnIds;
private array $properties;
public function __construct(int $iblockId, array $customEditableColumnIds)
{
$this->iblockId = $iblockId;
$this->customEditableColumnIds = $customEditableColumnIds;
parent::__construct(
$this->getPropertyColumnsIdsWithUserType()
);
parent::__construct($iblockId, $customEditableColumnIds);
$this->preloadResources();
}
@@ -41,66 +31,61 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
$APPLICATION->AddHeadScript('/bitrix/js/main/utils.js');
}
private function getPropertyColumnsIdsWithUserType(): array
protected function getPropertyFilter(): array
{
$result = [];
$rows = PropertyTable::getList([
'select' => [
'ID',
],
'filter' => [
'=IBLOCK_ID' => $this->iblockId,
'!USER_TYPE' => null,
],
]);
foreach ($rows as $row)
{
$result[] = ElementPropertyProvider::getColumnIdByPropertyId($row['ID']);
}
return $result;
return [
'!USER_TYPE' => null,
];
}
private function getPropertiesWithUserType(): array
protected function validateProperty(array $property): ?array
{
if (!isset($this->properties))
$property['USER_TYPE_SETTINGS'] = $property['USER_TYPE_SETTINGS_LIST'];
$property['PROPERTY_USER_TYPE'] = CIBlockProperty::GetUserType($property['USER_TYPE']);
if (
$property['PROPERTY_TYPE'] === PropertyTable::TYPE_ELEMENT
|| $property['PROPERTY_TYPE'] === PropertyTable::TYPE_SECTION
)
{
$this->properties = [];
$usedPropertyIds = ElementPropertyProvider::getPropertyIdsFromColumnsIds($this->getColumnIds());
if (!empty($usedPropertyIds))
$property['LINK_IBLOCK_ID'] = (int)$property['LINK_IBLOCK_ID'];
if ($property['LINK_IBLOCK_ID'] <= 0)
{
$rows = PropertyTable::getList([
'filter' => [
'=IBLOCK_ID' => $this->iblockId,
'!USER_TYPE' => null,
'@ID' => $usedPropertyIds,
],
]);
foreach ($rows as $row)
{
$id = $row['ID'];
$this->properties[$id] = $row;
$this->properties[$id]['USER_TYPE_SETTINGS'] = $row['USER_TYPE_SETTINGS_LIST'];
$this->properties[$id]['PROPERTY_USER_TYPE'] = CIBlockProperty::GetUserType($row['USER_TYPE']);
}
$property['LINK_IBLOCK_ID'] = null;
}
}
return $this->properties;
// TODO: remove this hack after refactoring \CIBlockPropertyEmployee::GetPublicEditHTMLMulty and \CIBlockPropertyEmployee::GetPublicEditHTML
if (
$property['PROPERTY_TYPE'] === PropertyTable::TYPE_STRING
&& $property['USER_TYPE'] === PropertyTable::USER_TYPE_EMPLOYEE
)
{
$property['SETTINGS'] ??= [];
$property['SETTINGS']['USE_ENTITY_SELECTOR'] = true;
}
return $property;
}
protected function prepareRow(array $row): array
{
$row['columns'] ??= [];
if (($row['data']['ROW_TYPE'] ?? '') !== RowType::ELEMENT)
if (!self::isElementRow($row))
{
return $row;
}
$columnIds = $this->getColumnIds();
if (empty($columnIds))
{
return $row;
}
$rowId = RowType::getIndex(self::getRowType($row), (string)($row['data']['ID'] ?? ''));
$row['columns'] ??= [];
/*
foreach ($this->getPropertiesWithUserType() as $propertyId => $property)
{
$columnId = ElementPropertyProvider::getColumnIdByPropertyId($propertyId);
@@ -120,11 +105,31 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
$row['data']['~' . $columnId] = $this->getEditValue($columnId, $property, $value);
}
}
*/
foreach ($columnIds as $columnId)
{
$property = $this->properties[$columnId];
$value = $row['data'][$columnId] ?? null;
// view
$viewValue = $this->getColumnValue($rowId, $columnId, $property, $value);
if (isset($viewValue))
{
$row['columns'][$columnId] = is_array($viewValue) ? implode(' / ', $viewValue) : $viewValue;
}
// edit custom
if ($this->isCustomEditable($columnId))
{
$row['data']['~' . $columnId] = $this->getEditValue($rowId, $columnId, $property, $value);
}
}
return $row;
}
private function renderUserTypeFunction(Closure $callback, string $name, $value, array $property)
private function renderUserTypeFunction(Closure $callback, string $rowId, string $name, $value, array $property)
{
return call_user_func_array(
$callback,
@@ -132,6 +137,8 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
$property,
$value,
[
'ROW_ID' => $rowId,
'FIELD_NAME' => $name,
'GRID' => 'PUBLIC',
'VALUE' => $name . '[VALUE]',
'DESCRIPTION' => $name . '[DESCRIPTION]',
@@ -140,7 +147,7 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
);
}
private function getColumnValue(string $columnId, array $property, $value)
private function getColumnValue(string $rowId, string $columnId, array $property, $value)
{
if ($value === null)
{
@@ -155,6 +162,7 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
{
$tmp[] = $this->renderUserTypeFunction(
Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicViewHTML']),
$rowId,
$columnId . "[n{$i}]",
$valueItem,
$property
@@ -185,6 +193,7 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
{
return $this->renderUserTypeFunction(
Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicViewHTML']),
$rowId,
$columnId,
$value,
$property
@@ -195,7 +204,7 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
return null;
}
private function getEditValue(string $columnId, array $property, $value)
private function getEditValue(string $rowId, string $columnId, array $property, $value)
{
if ($property['MULTIPLE'] === 'Y')
{
@@ -203,6 +212,7 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
{
return $this->renderUserTypeFunction(
Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicEditHTMLMulty']),
$rowId,
$columnId,
$value,
$property
@@ -215,6 +225,7 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
{
$tmp[] = $this->renderUserTypeFunction(
Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicEditHTML']),
$rowId,
$columnId . "[n{$i}]",
$valueItem,
$property
@@ -228,6 +239,7 @@ final class UserTypePropertyFieldAssembler extends FieldAssembler
{
return $this->renderUserTypeFunction(
Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicEditHTML']),
$rowId,
$columnId,
$value,
$property

View File

@@ -1,9 +1,15 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
use Bitrix\Main\ORM\Fields\BooleanField;
use Bitrix\Main\ORM\Fields\IntegerField;
use Bitrix\Main\ORM\Fields\Relations\Reference;
use Bitrix\Main\ORM\Fields\StringField;
use bitrix\Main\ORM\Fields\Validators\LengthValidator;
use Bitrix\Main\ORM\Query\Join;
/**
* Class IblockFieldTable
@@ -32,14 +38,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_IblockField wakeUpObject($row)
* @method static \Bitrix\Iblock\EO_IblockField_Collection wakeUpCollection($rows)
*/
class IblockFieldTable extends Entity\DataManager
class IblockFieldTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_fields';
}
@@ -49,45 +55,29 @@ class IblockFieldTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'IBLOCK_ID' => array(
'data_type' => 'integer',
'primary' => true,
'title' => Loc::getMessage('IBLOCK_FIELD_ENTITY_IBLOCK_ID_FIELD'),
return [
'IBLOCK_ID' => (new IntegerField('IBLOCK_ID'))
->configurePrimary(true)
->configureTitle(Loc::getMessage('IBLOCK_FIELD_ENTITY_IBLOCK_ID_FIELD'))
,
'FIELD_ID' => (new StringField('FIELD_ID'))
->configurePrimary(true)
->addValidator(new LengthValidator(null, 50))
->configureTitle(Loc::getMessage('IBLOCK_FIELD_ENTITY_FIELD_ID_FIELD'))
,
'IS_REQUIRED' => (new BooleanField('IS_REQUIRED'))
->configureValues('N', 'Y')
->configureTitle(Loc::getMessage('IBLOCK_FIELD_ENTITY_IS_REQUIRED_FIELD'))
,
'DEFAULT_VALUE' => (new StringField('DEFAULT_VALUE'))
->configureTitle(Loc::getMessage('IBLOCK_FIELD_ENTITY_DEFAULT_VALUE_FIELD'))
,
'IBLOCK' => new Reference(
'IBLOCK', IblockTable::class,
Join::on('this.IBLOCK_ID', 'ref.ID')
),
'FIELD_ID' => array(
'data_type' => 'string',
'primary' => true,
'validation' => array(__CLASS__, 'validateFieldId'),
'title' => Loc::getMessage('IBLOCK_FIELD_ENTITY_FIELD_ID_FIELD'),
),
'IS_REQUIRED' => array(
'data_type' => 'boolean',
'values' => array('N','Y'),
'title' => Loc::getMessage('IBLOCK_FIELD_ENTITY_IS_REQUIRED_FIELD'),
),
'DEFAULT_VALUE' => array(
'data_type' => 'string',
'title' => Loc::getMessage('IBLOCK_FIELD_ENTITY_DEFAULT_VALUE_FIELD'),
),
'IBLOCK' => array(
'data_type' => 'Bitrix\Iblock\Iblock',
'reference' => array('=this.IBLOCK_ID' => 'ref.ID')
),
);
}
/**
* Returns validators for FIELD_ID field.
*
* @return array
*/
public static function validateFieldId()
{
return array(
new Entity\Validator\Length(null, 50),
);
];
}
}

View File

@@ -1,9 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class IblockGroupTable
@@ -33,14 +34,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_IblockGroup_Collection wakeUpCollection($rows)
*/
class IblockGroupTable extends Entity\DataManager
class IblockGroupTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_group';
}
@@ -50,7 +51,7 @@ class IblockGroupTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'IBLOCK_ID' => array(
@@ -91,4 +92,4 @@ class IblockGroupTable extends Entity\DataManager
new Entity\Validator\Length(null, 1),
);
}
}
}

View File

@@ -1,9 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class IblockMessageTable
@@ -31,14 +32,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_IblockMessage wakeUpObject($row)
* @method static \Bitrix\Iblock\EO_IblockMessage_Collection wakeUpCollection($rows)
*/
class IblockMessageTable extends Entity\DataManager
class IblockMessageTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_messages';
}
@@ -48,7 +49,7 @@ class IblockMessageTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'IBLOCK_ID' => array(

View File

@@ -0,0 +1,186 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM\Data\AddResult;
use Bitrix\Main\ORM\Data\DataManager;
use Bitrix\Main\ORM\Data\DeleteResult;
use Bitrix\Main\ORM\Data\UpdateResult;
use Bitrix\Main\ORM\EntityError;
use Bitrix\Main\ORM\Fields\BooleanField;
use Bitrix\Main\ORM\Fields\IntegerField;
use Bitrix\Main\ORM\Fields\Relations\Reference;
use Bitrix\Main\ORM\Fields\StringField;
use Bitrix\Main\ORM\Fields\Validators\LengthValidator;
use Bitrix\Main\TaskOperationTable;
/**
* Class RightTable
*
* Fields:
* <ul>
* <li> ID int mandatory
* <li> IBLOCK_ID int mandatory
* <li> GROUP_CODE string(50) mandatory
* <li> ENTITY_TYPE string(32) mandatory
* <li> ENTITY_ID int mandatory
* <li> DO_INHERIT string(1) mandatory
* <li> TASK_ID int mandatory
* <li> OP_SREAD string(1) mandatory
* <li> OP_EREAD string(1) mandatory
* <li> XML_ID string(32) optional
* <li> IBLOCK_ID reference to {@link IblockTable}
* <li> TASK_ID reference to {@link TaskOperationTable}
* </ul>
*
* @package Bitrix\Iblock
**/
class IblockRightTable extends DataManager
{
public static function getTableName(): string
{
return 'b_iblock_right';
}
public static function getMap(): array
{
return [
new IntegerField(
'ID',
[
'primary' => true,
'autocomplete' => true,
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_ID_FIELD'),
]
),
new IntegerField(
'IBLOCK_ID',
[
'required' => true,
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_IBLOCK_ID_FIELD'),
]
),
new StringField(
'GROUP_CODE',
[
'required' => true,
'validation' => function()
{
return [
new LengthValidator(null, 50),
];
},
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_GROUP_CODE_FIELD'),
]
),
new StringField(
'ENTITY_TYPE',
[
'required' => true,
'validation' => function()
{
return [
new LengthValidator(null, 32),
];
},
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_ENTITY_TYPE_FIELD'),
]
),
new IntegerField(
'ENTITY_ID',
[
'required' => true,
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_ENTITY_ID_FIELD'),
]
),
new BooleanField(
'DO_INHERIT',
[
'required' => true,
'data_type' => 'boolean',
'values' => ['N', 'Y'],
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_DO_INHERIT_FIELD'),
]
),
new IntegerField(
'TASK_ID',
[
'required' => true,
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_TASK_ID_FIELD'),
]
),
new BooleanField(
'OP_SREAD',
[
'data_type' => 'boolean',
'values' => ['N', 'Y'],
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_OP_SREAD_FIELD'),
]
),
new BooleanField(
'OP_EREAD',
[
'data_type' => 'boolean',
'values' => ['N', 'Y'],
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_OP_EREAD_FIELD'),
]
),
new StringField(
'XML_ID',
[
'validation' => function()
{
return [
new LengthValidator(null, 32),
];
},
'title' => Loc::getMessage('IBLOCK_RIGHTS_ENTITY_XML_ID_FIELD'),
]
),
new Reference(
'IBLOCK',
IblockTable::class,
['=this.IBLOCK_ID' => 'ref.ID'],
['join_type' => 'LEFT']
),
new Reference(
'TASK',
TaskOperationTable::class,
['=this.TASK_ID' => 'ref.ID'],
['join_type' => 'LEFT']
),
];
}
public static function add(array $data): AddResult
{
$result = new AddResult();
$result->addError(new EntityError(
Loc::getMessage('IBLOCK_RIGHTS_ENTITY_ADD_BLOCK')
));
return $result;
}
public static function update($primary, array $data): UpdateResult
{
$result = new UpdateResult();
$result->addError(new EntityError(
Loc::getMessage('IBLOCK_RIGHTS_ENTITY_UPDATE_BLOCK')
));
return $result;
}
public static function delete($primary): DeleteResult
{
$result = new DeleteResult();
$result->addError(new EntityError(
Loc::getMessage('IBLOCK_RIGHTS_ENTITY_DELETE_BLOCK')
));
return $result;
}
}

View File

@@ -1,9 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class IblockRssTable
@@ -33,14 +34,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_IblockRss_Collection wakeUpCollection($rows)
*/
class IblockRssTable extends Entity\DataManager
class IblockRssTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_rss';
}
@@ -50,7 +51,7 @@ class IblockRssTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'ID' => array(
@@ -105,4 +106,4 @@ class IblockRssTable extends Entity\DataManager
new Entity\Validator\Length(null, 250),
);
}
}
}

View File

@@ -1,9 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class IblockSiteTable
@@ -31,14 +32,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_IblockSite wakeUpObject($row)
* @method static \Bitrix\Iblock\EO_IblockSite_Collection wakeUpCollection($rows)
*/
class IblockSiteTable extends Entity\DataManager
class IblockSiteTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_site';
}
@@ -48,7 +49,7 @@ class IblockSiteTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'IBLOCK_ID' => array(

View File

@@ -1,4 +1,5 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Iblock\ORM\ElementEntity;
@@ -22,7 +23,6 @@ use Bitrix\Main\ORM\Query\Query;
use Bitrix\Main\Type\DateTime;
use CIBlockProperty;
/**
* Class IblockTable
*

View File

@@ -1,9 +1,8 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class InheritedPropertyTable
@@ -21,14 +20,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_InheritedProperty wakeUpObject($row)
* @method static \Bitrix\Iblock\EO_InheritedProperty_Collection wakeUpCollection($rows)
*/
class InheritedPropertyTable extends Entity\DataManager
class InheritedPropertyTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_iproperty';
}
@@ -38,7 +37,7 @@ class InheritedPropertyTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'ID' => array(

View File

@@ -1,29 +1,29 @@
<?php
namespace Bitrix\Iblock\Model;
use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM\Data\Result;
use Bitrix\Iblock;
Loc::loadMessages(__FILE__);
class PropertyFeature
{
const EVENT_ID_FEATURE_LIST = 'OnPropertyFeatureBuildList'; // event name for build feature list
public const EVENT_ID_FEATURE_LIST = 'OnPropertyFeatureBuildList'; // event name for build feature list
const FEATURE_ID_LIST_PAGE_SHOW = 'LIST_PAGE_SHOW'; // show property in element list
const FEATURE_ID_DETAIL_PAGE_SHOW = 'DETAIL_PAGE_SHOW'; // detail page show property
public const FEATURE_ID_LIST_PAGE_SHOW = 'LIST_PAGE_SHOW'; // show property in element list
public const FEATURE_ID_DETAIL_PAGE_SHOW = 'DETAIL_PAGE_SHOW'; // detail page show property
/**
* Add features for new property. Do not check features in database.
*
* @param int $propertyId Property id.
* @param array $features Feature list.
* @return Main\Entity\Result
* @return Result
*/
public static function addFeatures($propertyId, array $features): Main\Entity\Result
public static function addFeatures($propertyId, array $features): Result
{
$result = new Main\Entity\Result();
$result = new Result();
$propertyId = (int)$propertyId;
if ($propertyId <= 0)
@@ -74,11 +74,11 @@ class PropertyFeature
*
* @param int $propertyId Property id.
* @param array $features Feature list.
* @return Main\Entity\Result
* @return Result
*/
public static function updateFeatures($propertyId, array $features): Main\Entity\Result
public static function updateFeatures($propertyId, array $features): Result
{
$result = new Main\Entity\Result();
$result = new Result();
$propertyId = (int)$propertyId;
if ($propertyId <= 0)
@@ -148,11 +148,11 @@ class PropertyFeature
*
* @param int $propertyId Property id.
* @param array $features Feature list.
* @return Main\Entity\Result
* @return Result
*/
public static function setFeatures($propertyId, array $features): Main\Entity\Result
public static function setFeatures($propertyId, array $features): Result
{
$result = new Main\Entity\Result();
$result = new Result();
$propertyId = (int)$propertyId;
if ($propertyId <= 0)

View File

@@ -1,9 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class PropertyEnumerationTable
@@ -36,14 +37,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_PropertyEnumeration_Collection wakeUpCollection($rows)
*/
class PropertyEnumerationTable extends Entity\DataManager
class PropertyEnumerationTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_property_enum';
}
@@ -53,7 +54,7 @@ class PropertyEnumerationTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'ID' => array(

View File

@@ -1,11 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main,
Bitrix\Main\ORM,
Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM;
/**
* Class PropertyFeatureTable
@@ -43,7 +42,7 @@ class PropertyFeatureTable extends ORM\Data\DataManager
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_property_feature';
}
@@ -53,7 +52,7 @@ class PropertyFeatureTable extends ORM\Data\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return [
'ID' => new ORM\Fields\IntegerField('ID', [
@@ -112,7 +111,7 @@ class PropertyFeatureTable extends ORM\Data\DataManager
/**
* Delete all features for property.
*
* @param int $property Property Id.
* @param int $property Property id.
* @return void
*/
public static function deleteByProperty($property)
@@ -127,4 +126,4 @@ class PropertyFeatureTable extends ORM\Data\DataManager
);
unset($helper, $conn);
}
}
}

View File

@@ -2,9 +2,9 @@
namespace Bitrix\Iblock;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM;
use Bitrix\Main\Type\DateTime;
use Bitrix\Main\Localization\Loc;
/**
* Class PropertyTable
@@ -364,4 +364,111 @@ class PropertyTable extends ORM\Data\DataManager
unset($settings);
}
}
/**
* Fetch modifier for user type settings from old iblock core.
*
* @param array $fields Fetch result fields.
* @return array|null
*/
public static function userTypeSettingsFetchModifer(array $fields): ?array
{
$userTypeId = (string)($fields['USER_TYPE'] ?? '');
if ($userTypeId === '')
{
unset($fields['USER_TYPE_SETTINGS_LIST']);
return $fields;
}
$settingsListExists = array_key_exists('USER_TYPE_SETTINGS_LIST', $fields);
$rawSettingsExists = array_key_exists('USER_TYPE_SETTINGS', $fields);
if (!$settingsListExists && !$rawSettingsExists)
{
return null;
}
if ($settingsListExists)
{
$fields['USER_TYPE_SETTINGS'] =
!empty($fields['USER_TYPE_SETTINGS_LIST']) && is_array($fields['USER_TYPE_SETTINGS_LIST'])
? $fields['USER_TYPE_SETTINGS_LIST']
: false
;
unset($fields['USER_TYPE_SETTINGS_LIST']);
}
else
{
$value = (string)$fields['USER_TYPE_SETTINGS'];
if ($value !== '')
{
try
{
$value = unserialize(
$value,
['allowed_classes' => false]
);
}
catch (\Exception)
{
$value = false;
}
}
$fields['USER_TYPE_SETTINGS'] = !empty($value) && is_array($value) ? $value : false;
}
return $fields;
}
/**
* Fetch modifier for user type default value from old iblock core.
*
* @param array $fields Fetch result fields.
* @return array|null
*/
public static function defaultValueFetchModifier(array $fields): ?array
{
if (!array_key_exists('DEFAULT_VALUE', $fields))
{
return null;
}
$userTypeId = (string)($fields['USER_TYPE'] ?? '');
if ($userTypeId === '')
{
return null;
}
$userType = \CIBlockProperty::getUserType($userTypeId);
if (!isset($userType['ConvertFromDB']))
{
return null;
}
if (!is_callable($userType['ConvertFromDB']))
{
return null;
}
$value = [
'VALUE' => $fields['DEFAULT_VALUE'],
'DESCRIPTION' => '',
];
$value = call_user_func_array(
$userType['ConvertFromDB'],
[
$fields,
$value,
]
);
$fields['DEFAULT_VALUE'] = $value['VALUE'] ?? null;
return $fields;
}
/**
* Add fetch modifiers for emulate old iblock core.
*
* @param ORM\Query\Result $result getList result.
* @return void
*/
public static function fillOldCoreFetchModifiers(ORM\Query\Result $result): void
{
$result->addFetchDataModifier([__CLASS__, 'userTypeSettingsFetchModifer']);
$result->addFetchDataModifier([__CLASS__, 'defaultValueFetchModifier']);
}
}

View File

@@ -1,14 +1,14 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Iblock\ORM\CommonElementTable;
use Bitrix\Main,
Bitrix\Main\Localization\Loc;
use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM\Data\DataManager;
use Bitrix\Main\ORM\Fields\Relations\Reference;
use Bitrix\Main\ORM\Query\Join;
Loc::loadMessages(__FILE__);
/**
* Class SectionElementTable
*
@@ -25,14 +25,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_SectionElement wakeUpObject($row)
* @method static \Bitrix\Iblock\EO_SectionElement_Collection wakeUpCollection($rows)
*/
class SectionElementTable extends Main\Entity\DataManager
class SectionElementTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_section_element';
}
@@ -42,7 +42,7 @@ class SectionElementTable extends Main\Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'IBLOCK_SECTION_ID' => new Main\Entity\IntegerField('IBLOCK_SECTION_ID', array(

View File

@@ -1,8 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class SectionPropertyTable
@@ -37,7 +39,7 @@ use Bitrix\Main\Localization\Loc;
* @method static \Bitrix\Iblock\EO_SectionProperty_Collection wakeUpCollection($rows)
*/
class SectionPropertyTable extends Entity\DataManager
class SectionPropertyTable extends DataManager
{
//ABCDE - for numbers
public const NUMBERS_WITH_SLIDER = 'A';

View File

@@ -1,4 +1,5 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Localization\Loc;

View File

@@ -8,10 +8,8 @@
namespace Bitrix\Iblock;
use Bitrix\Main,
Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
class SenderEventHandler
{

View File

@@ -1,9 +1,10 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class SequenceTable
@@ -32,14 +33,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_Sequence_Collection wakeUpCollection($rows)
*/
class SequenceTable extends Entity\DataManager
class SequenceTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_sequence';
}
@@ -49,7 +50,7 @@ class SequenceTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'IBLOCK_ID' => array(
@@ -85,4 +86,4 @@ class SequenceTable extends Entity\DataManager
new Entity\Validator\Length(null, 50),
);
}
}
}

View File

@@ -1,24 +0,0 @@
<?php
namespace Bitrix\Iblock;
/**
* Class SiteTable
* @package Bitrix\Iblock
* @deprecated
*
* DO NOT WRITE ANYTHING BELOW THIS
*
* <<< ORMENTITYANNOTATION
* @method static EO_Site_Query query()
* @method static EO_Site_Result getByPrimary($primary, array $parameters = [])
* @method static EO_Site_Result getById($id)
* @method static EO_Site_Result getList(array $parameters = [])
* @method static EO_Site_Entity getEntity()
* @method static \Bitrix\Iblock\EO_Site createObject($setDefaultValues = true)
* @method static \Bitrix\Iblock\EO_Site_Collection createCollection()
* @method static \Bitrix\Iblock\EO_Site wakeUpObject($row)
* @method static \Bitrix\Iblock\EO_Site_Collection wakeUpCollection($rows)
*/
class SiteTable extends IblockSiteTable
{
}

View File

@@ -1,9 +1,11 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main\Entity;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
use Bitrix\Main\ORM\Data\DataManager;
use Bitrix\Main\ORM\Data\DeleteResult;
/**
* Class TypeLanguageTable
@@ -33,14 +35,14 @@ Loc::loadMessages(__FILE__);
* @method static \Bitrix\Iblock\EO_TypeLanguage wakeUpObject($row)
* @method static \Bitrix\Iblock\EO_TypeLanguage_Collection wakeUpCollection($rows)
*/
class TypeLanguageTable extends Entity\DataManager
class TypeLanguageTable extends DataManager
{
/**
* Returns DB table name for entity
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_type_lang';
}
@@ -50,7 +52,7 @@ class TypeLanguageTable extends Entity\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'IBLOCK_TYPE_ID' => array(
@@ -157,7 +159,7 @@ class TypeLanguageTable extends Entity\DataManager
*
* @param string $iblockTypeId Iblock type identifier.
*
* @return \Bitrix\Main\Entity\EventResult
* @return DeleteResult
*/
public static function deleteByIblockTypeId($iblockTypeId)
{
@@ -168,7 +170,6 @@ class TypeLanguageTable extends Entity\DataManager
$sql = "DELETE FROM ".$entity->getDBTableName()." WHERE IBLOCK_TYPE_ID = '".$helper->forSql($iblockTypeId)."'";
$connection->queryExecute($sql);
$result = new \Bitrix\Main\Entity\DeleteResult();
return $result;
return new DeleteResult();
}
}

View File

@@ -1,11 +1,11 @@
<?php
namespace Bitrix\Iblock;
use Bitrix\Main;
use Bitrix\Main\ORM;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM;
Loc::loadMessages(__FILE__);
/**
* Class TypeTable
*
@@ -42,7 +42,7 @@ class TypeTable extends ORM\Data\DataManager
*
* @return string
*/
public static function getTableName()
public static function getTableName(): string
{
return 'b_iblock_type';
}
@@ -52,7 +52,7 @@ class TypeTable extends ORM\Data\DataManager
*
* @return array
*/
public static function getMap()
public static function getMap(): array
{
return array(
'ID' => array(

View File

@@ -1,402 +0,0 @@
<?
namespace Bitrix\Iblock\Update;
use Bitrix\Main\Application;
use Bitrix\Main\Update\Stepper;
use Bitrix\Main\Config\Option;
use Bitrix\Main\UI\Filter\DateType;
/**
* Class FilterOption
* The class is designed to convert the settings of the old administrative filter into a new one.
* @package Bitrix\Main\Dev\Converter
*/
class FilterOption extends Stepper
{
protected static $moduleId = "iblock";
protected $deleteFile = true;
protected $limit = 100;
/**
* The method records the necessary data for conversion into an option.
*
* @param string $filterId Filter id.
* @param string $tableId Grid id.
* @param array $ratioFields Fields of the old and new filter.
* array(
* "find_name" => "NAME",
* "find_lang" => "LID",
* ...
* )
*
* @throws \Bitrix\Main\ArgumentNullException
* @throws \Bitrix\Main\ArgumentOutOfRangeException
*/
public static function setFilterToConvert($filterId, $tableId, array $ratioFields)
{
$listFilter = Option::get(self::$moduleId, "listFilterToConvert", "");
if ($listFilter !== "" )
$listFilter = unserialize($listFilter);
$listFilter = is_array($listFilter) ? $listFilter : array();
if (!array_key_exists($filterId, $listFilter))
{
$listFilter[$filterId] = array(
"offset" => 0,
"tableId"=> $tableId,
"ratioFields" => $ratioFields
);
Option::set(self::$moduleId, "listFilterToConvert", serialize($listFilter));
}
}
public function execute(array &$option)
{
$listFilter = Option::get(self::$moduleId, "listFilterToConvert", "");
if ($listFilter !== "" )
$listFilter = unserialize($listFilter);
$listFilter = is_array($listFilter) ? $listFilter : array();
if (empty($listFilter))
{
Option::delete(self::$moduleId, array("name" => "listFilterToConvert"));
$GLOBALS["CACHE_MANAGER"]->cleanDir("user_option");
return false;
}
$connection = Application::getInstance()->getConnection();
$sqlHelper = $connection->getSqlHelper();
foreach ($listFilter as $filterId => $filter)
{
$queryObject = $connection->query("SELECT * FROM `b_filters` WHERE `FILTER_ID` = '".$sqlHelper->forSql(
$filterId)."' ORDER BY ID ASC LIMIT ".$this->limit." OFFSET ".$filter["offset"]);
$selectedRowsCount = $queryObject->getSelectedRowsCount();
while ($oldFilter = $queryObject->fetch())
{
$filters = array();
$listNewPresetName = [];
$oldFields = unserialize($oldFilter["FIELDS"]);
if (is_array($oldFields))
{
list($newFields, $newRows) = $this->convertOldFieldsToNewFields(
$oldFields, $filter["ratioFields"]);
$presetId = "filter_".(time()+(int)$oldFilter["ID"]);
$filters[$presetId] = array(
"name" => $oldFilter["NAME"],
"fields" => $newFields,
"filter_rows" => implode(",", $newRows)
);
$listNewPresetName[$presetId] = $oldFilter["NAME"];
}
if (empty($filters))
{
continue;
}
$queryOptionCurrentFilter = $connection->query(
"SELECT * FROM `b_user_option` WHERE
`CATEGORY` = 'main.ui.filter' AND
`USER_ID` = '".$sqlHelper->forSql($oldFilter["USER_ID"])."' AND
`NAME` = '".$sqlHelper->forSql($filter["tableId"])."'"
);
if ($optionCurrentFilter = $queryOptionCurrentFilter->fetch())
{
$optionCurrentFilterValue = unserialize($optionCurrentFilter["VALUE"]);
if (is_array($optionCurrentFilterValue))
{
if (!empty($optionCurrentFilterValue["filters"]))
{
// This is a check whether presets exist with that name.
foreach ($optionCurrentFilterValue["filters"] as $currentFilter)
{
$name = (!empty($currentFilter["name"]) ? $currentFilter["name"] : "");
$listNewPresetName = array_filter($listNewPresetName, function($oldName) use ($name) {
return ($oldName !== $name);
});
}
$filters = array_intersect_key($filters, $listNewPresetName);
$optionCurrentFilterValue["filters"] = array_merge(
$optionCurrentFilterValue["filters"], $filters);
$optionCurrentFilterValue["update_default_presets"] = true;
$connection->query(
"UPDATE `b_user_option` SET
`VALUE` = '" . $sqlHelper->forSql(serialize($optionCurrentFilterValue)) . "' WHERE
`ID` = '" . $sqlHelper->forSql($optionCurrentFilter["ID"]) . "'"
);
}
}
}
else
{
$optionNewFilter = array();
$optionNewFilter["filters"] = $filters;
$optionNewFilter["update_default_presets"] = true;
$connection->query(
"INSERT INTO `b_user_option`
(`ID`, `USER_ID`, `CATEGORY`, `NAME`, `VALUE`, `COMMON`) VALUES
(NULL, '".$sqlHelper->forSql($oldFilter["USER_ID"])."', 'main.ui.filter', '".
$sqlHelper->forSql($filter["tableId"])."', '".$sqlHelper->forSql(serialize($optionNewFilter)).
"', '".$sqlHelper->forSql($oldFilter["COMMON"])."')"
);
}
}
if ($selectedRowsCount < $this->limit)
{
unset($listFilter[$filterId]);
}
else
{
$listFilter[$filterId]["offset"] = $listFilter[$filterId]["offset"] + $selectedRowsCount;
}
}
$GLOBALS["CACHE_MANAGER"]->cleanDir("user_option");
if (!empty($listFilter))
{
Option::set(self::$moduleId, "listFilterToConvert", serialize($listFilter));
return true;
}
else
{
Option::delete(self::$moduleId, array("name" => "listFilterToConvert"));
return false;
}
}
protected function convertOldFieldsToNewFields(array $oldFields, array $ratioFields)
{
$newFields = [];
$newRows = [];
foreach ($oldFields as $fieldId => $field)
{
if ($field["hidden"] !== "false" || (array_key_exists($fieldId, $ratioFields) &&
array_key_exists($ratioFields[$fieldId], $newFields)))
continue;
if (preg_match("/_FILTER_PERIOD/", $fieldId, $matches, PREG_OFFSET_CAPTURE))
{
$searchResult = current($matches);
$oldDateType = $field["value"];
$dateFieldId = substr($fieldId, 0, $searchResult[1]);
$dateValue = array_key_exists($dateFieldId."_FILTER_DIRECTION", $oldFields) ?
$oldFields[$dateFieldId."_FILTER_DIRECTION"]["value"] : "";
$newDateType = $this->getNewDateType($oldDateType, $dateValue);
$custom = false;
if (substr($dateFieldId, -2) == "_1")
{
$custom = true;
$fieldId = substr($dateFieldId, 0, strlen($dateFieldId)-2);
}
else
{
$fieldId = $dateFieldId;
}
if (!$custom)
{
if ((substr($fieldId, -5) == "_from"))
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-5);
}
elseif ((substr($fieldId, -3) == "_to"))
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-3);
}
}
$from = "";
$to = "";
if ($newDateType == DateType::EXACT || $newDateType == DateType::RANGE)
{
if (array_key_exists($fieldId."_1", $oldFields))
{
$from = $oldFields[$fieldId."_1"]["value"];
$to = $oldFields[$fieldId."_2"]["value"];
}
elseif (array_key_exists($fieldId."_from", $oldFields))
{
$from = $oldFields[$fieldId."_from"]["value"];
$to = $oldFields[$fieldId."_to"]["value"];
}
}
$newFields[$ratioFields[$fieldId]."_datesel"] = $newDateType;
$newFields[$ratioFields[$fieldId]."_from"] = $from;
$newFields[$ratioFields[$fieldId]."_to"] = $to;
$newFields[$ratioFields[$fieldId]."_days"] = "";
$newFields[$ratioFields[$fieldId]."_month"] = "";
$newFields[$ratioFields[$fieldId]."_quarter"] = "";
$newFields[$ratioFields[$fieldId]."_year"] = "";
}
elseif (substr($fieldId, -2) === "_1")
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-2);
if (array_key_exists($fieldId, $ratioFields) && array_key_exists($fieldId."_2", $oldFields) &&
!array_key_exists($fieldId."_FILTER_PERIOD", $oldFields))
{
$newFields[$ratioFields[$fieldId]."_numsel"] = "range";
$newFields[$ratioFields[$fieldId]."_from"] = $field["value"];
$newFields[$ratioFields[$fieldId]."_to"] = $oldFields[$fieldId."_2"]["value"];
}
}
elseif (isset($ratioFields[$fieldId."_integer"]))
{
$fieldId = $fieldId."_integer";
$newFields[$ratioFields[$fieldId]."_numsel"] = "exact";
$newFields[$ratioFields[$fieldId]."_from"] = $field["value"];
$newFields[$ratioFields[$fieldId]."_to"] = $field["value"];
}
elseif (substr($fieldId, -6) === "_start")
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-6);
if (array_key_exists($fieldId, $ratioFields) && array_key_exists($fieldId."_end", $oldFields) &&
!array_key_exists($fieldId."_FILTER_PERIOD", $oldFields))
{
$newFields[$ratioFields[$fieldId]."_numsel"] = "range";
$newFields[$ratioFields[$fieldId]."_start"] = $field["value"];
$newFields[$ratioFields[$fieldId]."_end"] = $oldFields[$fieldId."_end"]["value"];
}
}
elseif ((bool)strtotime($field["value"]))
{
if ((substr($fieldId, -5) == "_from"))
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-5);
}
elseif ((substr($fieldId, -3) == "_to"))
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-3);
}
$from = "";
$to = "";
if (array_key_exists($fieldId."_from", $oldFields))
{
$from = $oldFields[$fieldId."_from"]["value"];
$to = $oldFields[$fieldId."_to"]["value"];
}
if ($from || $to)
{
$newFields[$ratioFields[$fieldId]."_datesel"] = DateType::RANGE;
$newFields[$ratioFields[$fieldId]."_from"] = $from;
$newFields[$ratioFields[$fieldId]."_to"] = $to;
$newFields[$ratioFields[$fieldId]."_days"] = "";
$newFields[$ratioFields[$fieldId]."_month"] = "";
$newFields[$ratioFields[$fieldId]."_quarter"] = "";
$newFields[$ratioFields[$fieldId]."_year"] = "";
}
}
elseif (substr($fieldId, -5) == "_from" && !array_key_exists($fieldId."_FILTER_DIRECTION", $oldFields))
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-5);
$rangeType = (($oldFields[$fieldId."_from"] === $oldFields[$fieldId."_to"]) ? "exact" : "range");
$newFields[$ratioFields[$fieldId]."_numsel"] = $rangeType;
$newFields[$ratioFields[$fieldId]."_from"] = $field["value"];
}
elseif (substr($fieldId, -3) == "_to")
{
$fieldId = substr($fieldId, 0, strlen($fieldId)-3);
if (!array_key_exists($fieldId."_from"."_FILTER_DIRECTION", $oldFields))
{
$rangeType = (($oldFields[$fieldId."_from"] === $oldFields[$fieldId."_to"]) ? "exact" : "range");
$newFields[$ratioFields[$fieldId]."_numsel"] = $rangeType;
$newFields[$ratioFields[$fieldId]."_to"] = $field["value"];
}
}
elseif (array_key_exists($fieldId, $ratioFields))
{
$newFields[$ratioFields[$fieldId]] = $field["value"];
}
if (!in_array($ratioFields[$fieldId], $newRows) && $ratioFields[$fieldId])
{
$newRows[] = $ratioFields[$fieldId];
}
}
return array($newFields, $newRows);
}
protected function getNewDateType($oldDateType, $oldDateValue)
{
$newDateType = DateType::EXACT;
switch ($oldDateType)
{
case "day":
switch ($oldDateValue)
{
case "previous":
$newDateType = DateType::YESTERDAY;
break;
case "current":
$newDateType = DateType::CURRENT_DAY;
break;
case "next":
$newDateType = DateType::TOMORROW;
break;
}
break;
case "week":
switch ($oldDateValue)
{
case "previous":
$newDateType = DateType::LAST_WEEK;
break;
case "current":
$newDateType = DateType::CURRENT_WEEK;
break;
case "next":
$newDateType = DateType::NEXT_WEEK;
break;
}
break;
case "month":
switch ($oldDateValue)
{
case "previous":
$newDateType = DateType::LAST_MONTH;
break;
case "current":
$newDateType = DateType::CURRENT_MONTH;
break;
case "next":
$newDateType = DateType::NEXT_MONTH;
break;
}
break;
case "quarter":
switch ($oldDateValue)
{
case "current":
$newDateType = DateType::CURRENT_QUARTER;
break;
case "previous":
case "next":
$newDateType = DateType::RANGE;
break;
}
break;
case "year":
$newDateType = DateType::RANGE;
break;
case "exact":
$newDateType = DateType::EXACT;
break;
case "before":
case "after":
case "interval":
$newDateType = DateType::RANGE;
break;
}
return $newDateType;
}
}

View File

@@ -1,118 +0,0 @@
<?
namespace Bitrix\Iblock\Update;
use Bitrix\Main\Application;
use Bitrix\Main\Update\Stepper;
use Bitrix\Main\Config\Option;
/**
* Class GridOption
* The class is designed to convert the settings of the old administrative grid into a new one.
* @package Bitrix\Main\Dev\Converter
*/
class GridOption extends Stepper
{
protected static $moduleId = "iblock";
protected $deleteFile = true;
protected $limit = 100;
/**
* The method records the necessary data for conversion into an option.
* @param string $tableId Grid id.
* @throws \Bitrix\Main\ArgumentNullException
* @throws \Bitrix\Main\ArgumentOutOfRangeException
*/
public static function setGridToConvert($tableId)
{
$listGrid = Option::get(self::$moduleId, "listGridToConvert", "");
if ($listGrid !== "")
{
$listGrid = unserialize($listGrid);
}
$listGrid = is_array($listGrid) ? $listGrid : [];
if (!array_key_exists($tableId, $listGrid))
{
$listGrid[$tableId] = [
"offset" => 0,
"tableId"=> $tableId,
];
Option::set(self::$moduleId, "listGridToConvert", serialize($listGrid));
}
}
public function execute(array &$option)
{
$listGrid = Option::get(self::$moduleId, "listGridToConvert", "");
if ($listGrid !== "" )
{
$listGrid = unserialize($listGrid);
}
$listGrid = is_array($listGrid) ? $listGrid : [];
if (empty($listGrid))
{
Option::delete(self::$moduleId, ["name" => "listGridToConvert"]);
$GLOBALS["CACHE_MANAGER"]->cleanDir("user_option");
return false;
}
$connection = Application::getInstance()->getConnection();
$sqlHelper = $connection->getSqlHelper();
foreach ($listGrid as $tableId => $table)
{
$queryObject = $connection->query("SELECT * FROM `b_user_option` WHERE `CATEGORY` = 'list' AND `NAME` = '".
$sqlHelper->forSql($table["tableId"])."' ORDER BY ID ASC LIMIT ".$this->limit." OFFSET ".$table["offset"]);
$selectedRowsCount = $queryObject->getSelectedRowsCount();
while ($optionOldGrid = $queryObject->fetch())
{
$oldGridData = (!empty($optionOldGrid["VALUE"]) ? unserialize($optionOldGrid["VALUE"]) : []);
if (!$oldGridData)
{
continue;
}
$queryResultObject = $connection->query(
"SELECT ID FROM `b_user_option` WHERE `CATEGORY` = 'main.interface.grid' AND `NAME` = '".
$sqlHelper->forSql($table["tableId"])."' AND `USER_ID` = '".$optionOldGrid["USER_ID"]."'");
if (!$queryResultObject->fetch())
{
if (!array_diff_key(array_flip(["page_size", "by", "order", "columns"]), $oldGridData))
{
$gridOptions = new \CGridOptions($tableId);
$gridOptions->setSorting($oldGridData["by"], $oldGridData["order"]);
$gridOptions->setColumns($oldGridData["columns"]);
$options = $gridOptions->getOptions();
$options["views"]["default"]["page_size"] = intval($oldGridData["page_size"]);
\CUserOptions::setOption(
"main.interface.grid", $tableId, $options, false, $optionOldGrid["USER_ID"]);
}
}
}
if ($selectedRowsCount < $this->limit)
{
unset($listGrid[$tableId]);
}
else
{
$listGrid[$tableId]["offset"] = $listGrid[$tableId]["offset"] + $selectedRowsCount;
}
}
$GLOBALS["CACHE_MANAGER"]->cleanDir("user_option");
if (!empty($listGrid))
{
Option::set(self::$moduleId, "listGridToConvert", serialize($listGrid));
return true;
}
else
{
Option::delete(self::$moduleId, ["name" => "listGridToConvert"]);
return false;
}
}
}

View File

@@ -537,7 +537,7 @@ class ElementType extends BaseType
return;
}
}
$filter['ACTIVE'] = $userField['SETTINGS']['ACTIVE_FILTER'] === 'Y';
$filter['ACTIVE'] = (($userField['SETTINGS']['ACTIVE_FILTER'] ?? 'N') === 'Y');
$elements = self::getElements(
(int)$userField['SETTINGS']['IBLOCK_ID'],

View File

@@ -2,13 +2,13 @@
namespace Bitrix\Iblock\UserField\Types;
use Bitrix\Iblock;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Type;
use Bitrix\Iblock;
use CDBResult;
use CUserTypeManager;
use CIBlockSectionEnum;
use CUserTypeManager;
/**
* Class SectionType
@@ -96,7 +96,7 @@ class SectionType extends ElementType
{
$section = CIBlockSectionEnum::getTreeList(
(int)$userField['SETTINGS']['IBLOCK_ID'],
$userField['SETTINGS']['ACTIVE_FILTER']
$userField['SETTINGS']['ACTIVE_FILTER'] ?? 'N',
);
}
return $section;
@@ -180,7 +180,7 @@ class SectionType extends ElementType
return;
}
}
$filter['ACTIVE'] = $userField['SETTINGS']['ACTIVE_FILTER'] === 'Y';
$filter['ACTIVE'] = (($userField['SETTINGS']['ACTIVE_FILTER'] ?? 'N') === 'Y');
if (isset($additionalParameters['SKIP_CHECK_PERMISSIONS']) && $additionalParameters['SKIP_CHECK_PERMISSIONS'])
{