Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
elementrowassembler.php
1<?php
2
4
25
27{
29 protected Columns $columns;
30
31 public function __construct(
32 array $visibleColumnsIds,
35 )
36 {
37 parent::__construct($visibleColumnsIds);
38
39 $this->settings = $settings;
40 $this->columns = $columns;
41 }
42
46 protected function prepareFieldAssemblers(): array
47 {
48 $result = [];
49
50 $result[] = $this->getUserAssembler();
51
52 $result[] = new ElementCountFieldAssembler();
53
54 $result[] = new SectionCountFieldAssembler(
55 $this->settings->getIblockId()
56 );
57
58 $result[] = new SectionNameFieldAssembler(
59 ['NAME'],
60 $this->settings->getUrlBuilder()
61 );
62
63 array_push($result, ... $this->getPropertiesAssemblers());
64
65 return $result;
66 }
67
68 private function getUserAssembler(): FieldAssembler
69 {
70 $columnIds = [
71 'MODIFIED_BY',
72 'CREATED_BY',
73 ];
74
76 {
77 return new IntranetUserFieldAssembler($columnIds, '/company/personal/user/#ID#/');
78 }
79
80 return new UserFieldAssembler($columnIds);
81 }
82
83 private function getPropertiesAssemblers(): array
84 {
85 $result = [];
86
87 $customColumnIds = [];
88 foreach ($this->columns as $column)
89 {
90 $editable = $column->getEditable();
91 if (isset($editable) && $editable->getType() === Types::CUSTOM)
92 {
93 $customColumnIds[] = $column->getId();
94 }
95 }
96
97 $result[] = new StringFieldAssembler(
98 $this->settings->getIblockId(),
99 []
100 );
101
102 $result[] = new NumberFieldAssembler(
103 $this->settings->getIblockId(),
104 []
105 );
106
107 $result[] = new ListFieldAssembler(
108 $this->settings->getIblockId()
109 );
110
111 $result[] = new ElementFieldAssembler(
112 $this->settings->getIblockId(),
113 $customColumnIds
114 );
115
116 $result[] = new SectionFieldAssembler(
117 $this->settings->getIblockId(),
118 $customColumnIds
119 );
120
121 $result[] = new UserTypePropertyFieldAssembler(
122 $this->settings->getIblockId(),
123 $customColumnIds
124 );
125
126 $result[] = new FileFieldAssembler(
127 $this->settings->getIblockId()
128 );
129
130 $processedColumnsIds = [];
131 foreach ($result as $assembler)
132 {
136 array_push($processedColumnsIds, ...$assembler->getColumnIds());
137 }
138
139 $result[] = new MultipleFieldAssembler(
140 $this->settings->getIblockId(),
141 $processedColumnsIds
142 );
143
144 return $result;
145 }
146
147 public function prepareRows(array $rowsList): array
148 {
149 $result = parent::prepareRows($rowsList);
150
151 foreach ($result as &$row)
152 {
153 $rowType = $row['data']['ROW_TYPE'] ?? RowType::ELEMENT;
154 $row['id'] = RowType::getIndex($rowType, $row['data']['ID']);
155
156 if ($rowType === RowType::SECTION)
157 {
158 $row = $this->disableElementFieldsEditableForSection($row);
159 }
160 // TODO: CRUTCH! remove after main 23.600.0
161 else
162 {
163 $row['data']['~DETAIL_TEXT'] = (string)($row['data']['DETAIL_TEXT'] ?? '');
164 $row['data']['~PREVIEW_TEXT'] = (string)($row['data']['PREVIEW_TEXT'] ?? '');
165 }
166 }
167 unset($row);
168
169 return $result;
170 }
171
172 private function disableElementFieldsEditableForSection(array $row): array
173 {
174 $editableColumns = array_fill_keys([
175 'NAME',
176 'CODE',
177 'SORT',
178 'XML_ID',
179 ], true);
180
181 $row['editableColumns'] ??= [];
182 foreach ($this->getVisibleColumnIds() as $columnId)
183 {
184 if (!isset($row['editableColumns'][$columnId]))
185 {
186 $row['editableColumns'][$columnId] = isset($editableColumns[$columnId]);
187 }
188 }
189
190 return $row;
191 }
192}
__construct(array $visibleColumnsIds, ElementSettings $settings, Columns $columns)
static getIndex(string $type, string|int $id)
Definition rowtype.php:17
static isModuleInstalled($moduleName)