1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usertypepropertyfieldassembler.php
См. документацию.
1<?php
2
3namespace Bitrix\Iblock\Grid\Row\Assembler\Property;
4
5use Bitrix\Iblock\Grid\Column\ElementPropertyProvider;
6use Bitrix\Iblock\Grid\RowType;
7use Bitrix\Iblock\PropertyTable;
8use Bitrix\Main\Grid\Row\FieldAssembler;
9use CIBlockProperty;
10use Closure;
11
13{
14 private int $iblockId;
15 private array $customEditableColumnIds;
16 private array $properties;
17
18 public function __construct(int $iblockId, array $customEditableColumnIds)
19 {
20 $this->iblockId = $iblockId;
21 $this->customEditableColumnIds = $customEditableColumnIds;
22
23 parent::__construct(
24 $this->getPropertyColumnsIdsWithUserType()
25 );
26
27 $this->preloadResources();
28 }
29
37 private function preloadResources(): void
38 {
39 global $APPLICATION;
40
41 $APPLICATION->AddHeadScript('/bitrix/js/main/utils.js');
42 }
43
44 private function getPropertyColumnsIdsWithUserType(): array
45 {
46 $result = [];
47
49 'select' => [
50 'ID',
51 ],
52 'filter' => [
53 '=IBLOCK_ID' => $this->iblockId,
54 '!USER_TYPE' => null,
55 ],
56 ]);
57 foreach ($rows as $row)
58 {
59 $result[] = ElementPropertyProvider::getColumnIdByPropertyId($row['ID']);
60 }
61
62 return $result;
63 }
64
65 private function getPropertiesWithUserType(): array
66 {
67 if (!isset($this->properties))
68 {
69 $this->properties = [];
70
71 $usedPropertyIds = ElementPropertyProvider::getPropertyIdsFromColumnsIds($this->getColumnIds());
72 if (!empty($usedPropertyIds))
73 {
75 'filter' => [
76 '=IBLOCK_ID' => $this->iblockId,
77 '!USER_TYPE' => null,
78 '@ID' => $usedPropertyIds,
79 ],
80 ]);
81 foreach ($rows as $row)
82 {
83 $id = $row['ID'];
84
85 $this->properties[$id] = $row;
86 $this->properties[$id]['USER_TYPE_SETTINGS'] = $row['USER_TYPE_SETTINGS_LIST'];
87 $this->properties[$id]['PROPERTY_USER_TYPE'] = CIBlockProperty::GetUserType($row['USER_TYPE']);
88 }
89 }
90 }
91
92 return $this->properties;
93 }
94
95 protected function prepareRow(array $row): array
96 {
97 $row['columns'] ??= [];
98
99 if (($row['data']['ROW_TYPE'] ?? '') !== RowType::ELEMENT)
100 {
101 return $row;
102 }
103
104 foreach ($this->getPropertiesWithUserType() as $propertyId => $property)
105 {
106 $columnId = ElementPropertyProvider::getColumnIdByPropertyId($propertyId);
107 $value = $row['data'][$columnId];
108
109 // view
110 $viewValue = $this->getColumnValue($columnId, $property, $value);
111 if (isset($viewValue))
112 {
113 $row['columns'][$columnId] = is_array($viewValue) ? implode(' / ', $viewValue) : $viewValue;
114 }
115
116 // edit custom
117 $isCustom = in_array($columnId, $this->customEditableColumnIds, false);
118 if ($isCustom)
119 {
120 $row['data']['~' . $columnId] = $this->getEditValue($columnId, $property, $value);
121 }
122 }
123
124 return $row;
125 }
126
127 private function renderUserTypeFunction(Closure $callback, string $name, $value, array $property)
128 {
129 return call_user_func_array(
130 $callback,
131 [
132 $property,
133 $value,
134 [
135 'GRID' => 'PUBLIC',
136 'VALUE' => $name . '[VALUE]',
137 'DESCRIPTION' => $name . '[DESCRIPTION]',
138 ],
139 ]
140 );
141 }
142
143 private function getColumnValue(string $columnId, array $property, $value)
144 {
145 if ($value === null)
146 {
147 return null;
148 }
149 if (isset($property['PROPERTY_USER_TYPE']['GetPublicViewHTML']))
150 {
151 if ($property['MULTIPLE'] === 'Y')
152 {
153 $tmp = [];
154 foreach ($value as $i => $valueItem)
155 {
156 $tmp[] = $this->renderUserTypeFunction(
157 Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicViewHTML']),
158 $columnId . "[n{$i}]",
159 $valueItem,
160 $property
161 );
162 }
163
164 $separator = '';
165
166 // TODO: replace this hack (custom separator for some types of properties)
167 if (in_array(
168 $property['USER_TYPE'],
169 [
172 ]
173 ))
174 {
175 $separator = ', ';
176 }
177 elseif ($property['USER_TYPE'] === PropertyTable::USER_TYPE_DIRECTORY)
178 {
179 $separator = ' / ';
180 }
181
182 return join($separator, $tmp);
183 }
184 else
185 {
186 return $this->renderUserTypeFunction(
187 Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicViewHTML']),
188 $columnId,
189 $value,
190 $property
191 );
192 }
193 }
194
195 return null;
196 }
197
198 private function getEditValue(string $columnId, array $property, $value)
199 {
200 if ($property['MULTIPLE'] === 'Y')
201 {
202 if (isset($property['PROPERTY_USER_TYPE']['GetPublicEditHTMLMulty']))
203 {
204 return $this->renderUserTypeFunction(
205 Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicEditHTMLMulty']),
206 $columnId,
207 $value,
208 $property
209 );
210 }
211 elseif (isset($property['PROPERTY_USER_TYPE']['GetPublicEditHTML']))
212 {
213 $tmp = [];
214 foreach ($value as $i => $valueItem)
215 {
216 $tmp[] = $this->renderUserTypeFunction(
217 Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicEditHTML']),
218 $columnId . "[n{$i}]",
219 $valueItem,
220 $property
221 );
222 }
223
224 return join('', $tmp);
225 }
226 }
227 elseif (isset($property['PROPERTY_USER_TYPE']['GetPublicEditHTML']))
228 {
229 return $this->renderUserTypeFunction(
230 Closure::fromCallable($property['PROPERTY_USER_TYPE']['GetPublicEditHTML']),
231 $columnId,
232 $value,
233 $property
234 );
235 }
236
237 return null;
238 }
239}
global $APPLICATION
Определения include.php:80
__construct(int $iblockId, array $customEditableColumnIds)
const ELEMENT
Определения rowtype.php:7
const USER_TYPE_DATETIME
Определения propertytable.php:76
const USER_TYPE_DIRECTORY
Определения propertytable.php:93
const USER_TYPE_DATE
Определения propertytable.php:75
static getList(array $parameters=array())
Определения datamanager.php:431
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$i
Определения factura.php:643
$rows
Определения options.php:264