Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
lockedfieldassembler.php
1<?php
2
4
9use CCatalogAdminTools;
10
11Loader::requireModule('iblock');
12
17{
21 private array $lockedColumns;
22
26 public function __construct(ProductSettings $settings)
27 {
28 $this->initLockedColumns($settings);
29
30 parent::__construct(
31 $this->getProcessedColumnIds(),
32 $settings
33 );
34 }
35
41 private function initLockedColumns(ProductSettings $settings): void
42 {
43 $this->lockedColumns = [];
44
45 $lockedFieldNames = CCatalogAdminTools::getLockedGridFields([
46 'USE_NEW_CARD' => $settings->isNewCardEnabled(),
47 ]);
48
49 $removePrefix = 'CATALOG_';
50 foreach ($lockedFieldNames as $productType => $map)
51 {
52 foreach ($map as $columnId => $value)
53 {
54 $columnId = str_replace($removePrefix, '', $columnId);
55 $this->lockedColumns[$productType][$columnId] = $value === false;
56 }
57 }
58 }
59
65 private function getProcessedColumnIds(): array
66 {
67 if (empty($this->lockedColumns))
68 {
69 return [];
70 }
71
72 return array_keys(reset($this->lockedColumns));
73 }
74
81 private function isLockedField(array $row, string $columnId): bool
82 {
83 $rowType = $row['data']['ROW_TYPE'] ?? RowType::ELEMENT;
84 $productType = (int)($row['data']['TYPE'] ?? 0);
85
86 return
87 $rowType === RowType::ELEMENT
88 && isset($this->lockedColumns[$productType][$columnId])
89 && $this->lockedColumns[$productType][$columnId] === true
90 ;
91 }
92
93 #region override
94
98 protected function prepareRow(array $row): array
99 {
100 if (empty($this->getColumnIds()))
101 {
102 return $row;
103 }
104
105 foreach ($this->getColumnIds() as $columnId)
106 {
107 $isLocked = $this->isLockedField($row, $columnId);
108 if ($isLocked)
109 {
110 $row['editableColumns'][$columnId] = false;
111 }
112 }
113
114 return $row;
115 }
116
117 #endregion override
118}