• Модуль: rpa
  • Путь к файлу: ~/bitrix/modules/rpa/lib/components/itemdetail.php
  • Класс: BitrixRpaComponentsItemDetail
  • Вызов: ItemDetail::init
protected function init(): void
{
	parent::init();
	if($this->getErrors())
	{
		return;
	}

	$command = null;

	$this->userFieldDispatcher = Dispatcher::instance();

	$typeId = (int) $this->arParams['typeId'];
	if($typeId > 0)
	{
		$this->type = TypeTable::getById($typeId)->fetchObject();
	}
	if(!$this->type)
	{
		$this->errorCollection[] = new Error(Loc::getMessage('RPA_NOT_FOUND_ERROR'));
		return;
	}
	if(!Driver::getInstance()->getUserPermissions()->canViewType($typeId))
	{
		$this->errorCollection[] = new Error(Loc::getMessage('RPA_TYPE_PERMISSION_ERROR'));
		return;
	}
	$id = (int) $this->arParams['id'];
	if($id > 0)
	{
		$this->item = $this->type->getItem($id);
		if(!$this->item)
		{
			$this->errorCollection[] = new Error(Loc::getMessage('RPA_ITEM_NOT_FOUND'));
			return;
		}

		$this->stage = $this->item->getStage();
		$stageId = (int)($this->arParams['stageId'] ?? null);
		if($stageId > 0)
		{
			$stage = $this->type->getStages()->getByPrimary($stageId);
			if(!$stage)
			{
				$this->errorCollection[] = new Error(Loc::getMessage('RPA_STAGE_NOT_FOUND_ERROR'));
			}
			else
			{
				$this->item->setStageId($stage->getId());
				$this->editorInitialMode = 'edit';
			}
		}
	}
	else
	{
		$this->stage = $this->type->getStages()->getAll()[0];
		if(!$this->stage)
		{
			$this->errorCollection[] = new Error(Loc::getMessage('RPA_FIRST_STAGE_NOT_FOUND_ERROR'));
		}
		else
		{
			$this->item = $this->type->createItem();
		}
	}

	if(!$this->stage)
	{
		$this->errorCollection[] = new Error(Loc::getMessage('RPA_STAGE_NOT_FOUND_ERROR'));
	}

	if(!$this->getErrors())
	{
		$checkAccessResult = $this->checkAccess();
		if(!$checkAccessResult->isSuccess())
		{
			$this->errorCollection->add($checkAccessResult->getErrors());
		}
	}
}