21 private int $iblockId;
24 private CIBlockElement $elementEntity;
25 private CIBlockSection $sectionEntity;
27 public static function getId(): string
34 $this->iblockId = $iblockId;
35 $this->columns = $columns;
36 $this->rights = $rights;
39 private function getElementEntity(): CIBlockElement
41 if (!isset($this->elementEntity))
43 $this->elementEntity =
new CIBlockElement();
44 $this->elementEntity->setIblock($this->
getIblockId());
47 return $this->elementEntity;
50 private function getSectionEntity(): CIBlockSection
52 if (!isset($this->sectionEntity))
54 $this->sectionEntity =
new CIBlockSection();
55 $this->sectionEntity->setIblock($this->
getIblockId());
58 return $this->sectionEntity;
63 return $this->iblockId;
68 return $this->columns;
75 $rows = $request->getPost(
'FIELDS');
82 foreach ($rows as $id => $fields)
89 [$type, $id] = $index;
91 $fields = $this->
getColumns()->prepareEditableColumnsValues($fields);
99 if (!$this->rights->canEditElement($id))
117 if (!$this->rights->canEditSection($id))
119 $message =
Loc::getMessage(
'IBLOCK_GRID_PANEL_UI_EDIT_ACTIONS_ITEM_ACCESS_DENIED', [
138 private function splitElementFields(array $fields): array
141 $propertyFields = [];
143 $propertyColumnIds = ElementPropertyProvider::getPropertyIdsFromColumnsIds(array_keys($fields));
144 foreach ($fields as $name => $value)
146 $propertyId = $propertyColumnIds[$name] ??
null;
147 if (isset($propertyId))
149 $propertyFields[$propertyId] = $value;
153 $elementFields[$name] = $value;
157 return [$elementFields, $propertyFields];
164 $fields = $this->prepareColumnsTypesValues($fields);
166 [$elementFields, $propertyFields] = $this->splitElementFields($fields);
168 if (!empty($elementFields))
170 $entity = $this->getElementEntity();
171 $entity->Update($id, $fields);
172 if ($entity->getLastError())
175 new Error($entity->getLastError())
180 if ($result->isSuccess() && !empty($propertyFields))
182 CIBlockElement::SetPropertyValuesEx($id, 0, $propertyFields);
192 $entity = $this->getSectionEntity();
193 $entity->Update($id, $fields);
195 if ($entity->getLastError())
198 new Error($entity->getLastError())
205 private function prepareColumnsTypesValues(array $fields): array
209 $columnId = $column->getId();
210 $value = $fields[$columnId] ??
null;
216 $editable = $column->getEditable();
217 if (!isset($editable))
221 elseif ($editable->getType() === Types::MULTISELECT)
223 if (is_array($value))
225 $fields[$columnId] = array_column($value,
'VALUE');
228 elseif ($editable->getType() === Types::IMAGE)
230 if ($value ===
'null')
232 $fields[$columnId] = [
246 $files = $request->getFile(
'FIELDS');
247 if (empty($files[
'name']))
252 foreach ($files[
'name'] as $rowId => $fields)
254 foreach ($fields as $fieldName => $fieldValue)
256 $rows[$rowId] ??= [];
257 $rows[$rowId][$fieldName] = [
258 'name' => $fieldValue,
259 'type' => $files[
'type'][$rowId][$fieldName] ??
null,
260 'size' => $files[
'size'][$rowId][$fieldName] ??
null,
261 'error' => $files[
'error'][$rowId][$fieldName] ??
null,
262 'tmp_name' => $files[
'tmp_name'][$rowId][$fieldName] ??
null,
263 'full_path' => $files[
'full_path'][$rowId][$fieldName] ??
null,
static getMessage($code, $replace=null, $language=null)