• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/grid/panel/ui/actions/item/elementgroup/movetosectiongroupchild.php
  • Класс: BitrixIblockGridPanelUIActionsItemElementGroupMoveToSectionGroupChild
  • Вызов: MoveToSectionGroupChild::moveElementsToSection
private function moveElementsToSection(int $sectionId, bool $isSelectedAllRows, array $ids): Result
{
	$result = new Result();
	$entity = new CIBlockElement();

	if (!$this->getIblockRightsChecker()->canBindElementToSection($sectionId))
	{
		$message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_MOVE_TO_SECTION_GROUP_CHILD_ACCESS_DENIED_BIND_ELEMENT', [
			'#ID#' => $sectionId,
		]);
		$result->addError(
			new Error($message)
		);

		return $result;
	}

	$filter = [
		'IBLOCK_ID' => $this->getIblockId(),
	];
	if (!$isSelectedAllRows)
	{
		$filter['ID'] = $ids;
	}

	$rows = CIBlockElement::GetList(
		[],
		$filter + ['CHECK_PERMISSIONS' => 'N'],
		false,
		false,
		[
			'ID',
		]
	);
	while ($row = $rows->Fetch())
	{
		$id = (int)$row['ID'];

		if (!$this->getIblockRightsChecker()->canEditElement($id))
		{
			$message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_MOVE_TO_SECTION_GROUP_CHILD_ACCESS_DENIED_EDIT_ELEMENT', [
				'#ID#' => $id,
			]);
			$result->addError(
				new Error($message)
			);

			continue;
		}

		$fields = [
			'IBLOCK_SECTION_ID' => $sectionId,
			'IBLOCK_SECTION' => [
				$sectionId,
			],
		];
		$updateResult = $entity->Update($id, $fields);
		if (!$updateResult)
		{
			if ($entity->LAST_ERROR)
			{
				$result->addError(
					new Error($entity->LAST_ERROR)
				);
			}
		}
		else
		{
			$ipropValues = new ElementValues($this->getIblockId(), $id);
			$ipropValues->clearValues();
		}
	}

	return $result;
}