14 private int $iblockId;
15 private array $customEditableColumnIds;
16 private array $properties;
18 public function __construct(
int $iblockId, array $customEditableColumnIds)
20 $this->iblockId = $iblockId;
21 $this->customEditableColumnIds = $customEditableColumnIds;
24 $this->getPropertyColumnsIdsWithUserType()
27 $this->preloadResources();
37 private function preloadResources(): void
41 $APPLICATION->AddHeadScript(
'/bitrix/js/main/utils.js');
44 private function getPropertyColumnsIdsWithUserType(): array
53 '=IBLOCK_ID' => $this->iblockId,
57 foreach ($rows as $row)
59 $result[] = ElementPropertyProvider::getColumnIdByPropertyId($row[
'ID']);
65 private function getPropertiesWithUserType(): array
67 if (!isset($this->properties))
69 $this->properties = [];
71 $usedPropertyIds = ElementPropertyProvider::getPropertyIdsFromColumnsIds($this->
getColumnIds());
72 if (!empty($usedPropertyIds))
76 '=IBLOCK_ID' => $this->iblockId,
78 '@ID' => $usedPropertyIds,
81 foreach ($rows as $row)
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']);
92 return $this->properties;
97 $row[
'columns'] ??= [];
104 foreach ($this->getPropertiesWithUserType() as $propertyId => $property)
106 $columnId = ElementPropertyProvider::getColumnIdByPropertyId($propertyId);
107 $value = $row[
'data'][$columnId];
110 $viewValue = $this->getColumnValue($columnId, $property, $value);
111 if (isset($viewValue))
113 $row[
'columns'][$columnId] = is_array($viewValue) ? implode(
' / ', $viewValue) : $viewValue;
117 $isCustom = in_array($columnId, $this->customEditableColumnIds,
false);
120 $row[
'data'][
'~' . $columnId] = $this->getEditValue($columnId, $property, $value);
127 private function renderUserTypeFunction(Closure $callback,
string $name, $value, array $property)
129 return call_user_func_array(
136 'VALUE' => $name .
'[VALUE]',
137 'DESCRIPTION' => $name .
'[DESCRIPTION]',
143 private function getColumnValue(
string $columnId, array $property, $value)
149 if (isset($property[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTML']))
151 if ($property[
'MULTIPLE'] ===
'Y')
154 foreach ($value as $i => $valueItem)
156 $tmp[] = $this->renderUserTypeFunction(
157 Closure::fromCallable($property[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTML']),
158 $columnId .
"[n{$i}]",
166 $isCommaSeparator = in_array($property[
'USER_TYPE'], [
170 if ($isCommaSeparator)
175 return join($separator, $tmp);
179 return $this->renderUserTypeFunction(
180 Closure::fromCallable($property[
'PROPERTY_USER_TYPE'][
'GetPublicViewHTML']),
191 private function getEditValue(
string $columnId, array $property, $value)
193 if ($property[
'MULTIPLE'] ===
'Y')
195 if (isset($property[
'PROPERTY_USER_TYPE'][
'GetPublicEditHTMLMulty']))
197 return $this->renderUserTypeFunction(
198 Closure::fromCallable($property[
'PROPERTY_USER_TYPE'][
'GetPublicEditHTMLMulty']),
204 elseif (isset($property[
'PROPERTY_USER_TYPE'][
'GetPublicEditHTML']))
207 foreach ($value as $i => $valueItem)
209 $tmp[] = $this->renderUserTypeFunction(
210 Closure::fromCallable($property[
'PROPERTY_USER_TYPE'][
'GetPublicEditHTML']),
211 $columnId .
"[n{$i}]",
217 return join(
'', $tmp);
220 elseif (isset($property[
'PROPERTY_USER_TYPE'][
'GetPublicEditHTML']))
222 return $this->renderUserTypeFunction(
223 Closure::fromCallable($property[
'PROPERTY_USER_TYPE'][
'GetPublicEditHTML']),
static getList(array $parameters=array())