• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/grid/panel/ui/actions/item/removeactionsitem.php
  • Класс: BitrixIblockGridPanelUIActionsItemRemoveActionsItem
  • Вызов: RemoveActionsItem::processRequest
public function processRequest(HttpRequest $request, bool $isSelectedAllRows): ?Result
{
	global $APPLICATION;

	/**
	 * @var CMain $APPLICATION
	 */

	$result = new Result();

	if ($isSelectedAllRows)
	{
		$ids = [];

		$rows = CIBlockElement::GetList(
			[],
			[
				'IBLOCK_ID' => $this->iblockId,
				'CHECK_PERMISSIONS' => 'N',
			],
			false,
			false,
			[
				'ID',
			]
		);
		while ($row = $rows->Fetch())
		{
			$ids[] = RowType::getIndex(
				RowType::ELEMENT,
				(int)$row['ID']
			);
		}

		$rows = CIBlockSection::GetList(
			[],
			[
				'IBLOCK_ID' => $this->iblockId,
				'CHECK_PERMISSIONS' => 'N',
			],
			false,
			[
				'ID',
			]
		);
		while ($row = $rows->Fetch())
		{
			$ids[] = RowType::getIndex(
				RowType::SECTION,
				(int)$row['ID']
			);
		}
	}
	else
	{
		$ids = $request->getPost('ID');
	}

	if (!is_array($ids) || empty($ids))
	{
		return $result;
	}

	foreach ($ids as $id)
	{
		[$type, $id] = RowType::parseIndex($id);

		if ($type === RowType::ELEMENT)
		{
			if (!$this->rights->canDeleteElement($id))
			{
				$message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_REMOVE_ACTIONS_ITEM_ACCESS_DENIED', [
					'#ID#' => $id,
				]);
				$result->addError(
					new Error($message)
				);

				continue;
			}

			$deleteResult = CIBlockElement::Delete($id);
		}
		else
		{
			if (!$this->rights->canDeleteSection($id))
			{
				$message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_REMOVE_ACTIONS_ITEM_ACCESS_DENIED', [
					'#ID#' => $id,
				]);
				$result->addError(
					new Error($message)
				);

				continue;
			}

			$deleteResult = CIBlockSection::Delete($id);
		}

		if (!$deleteResult)
		{
			$ex = $APPLICATION->GetException();
			if ($ex)
			{
				$result->addError(
					new Error($ex->GetString())
				);
			}
			else
			{
				$message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_ACTIONS_ITEM_REMOVE_ERROR_DELETE', [
					'#ID#' => $id,
				]);
				$result->addError(
					new Error($message)
				);
			}
		}
	}

	return $result;
}