• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/scrum/backlog.php
  • Класс: BitrixTasksRestControllersScrumBacklog
  • Вызов: Backlog::addAction
public function addAction(array $fields)
{
	$groupId = array_key_exists('groupId', $fields) ? (int) $fields['groupId'] : 0;

	if (!$groupId)
	{
		$this->errorCollection->add([new Error('Group id not found')]);

		return null;
	}

	if (!$this->checkAccess($groupId))
	{
		$this->errorCollection->add([new Error('Access denied')]);

		return null;
	}

	$backlogService = new BacklogService();

	$backlog = $backlogService->getBacklogByGroupId($groupId);
	if (!$backlog->isEmpty())
	{
		$this->errorCollection->add([new Error('Backlog already added')]);

		return null;
	}

	$createdBy = 0;
	if (array_key_exists('createdBy', $fields) && is_numeric($fields['createdBy']))
	{
		$createdBy = (int) $fields['createdBy'];
		if (!$this->existsUser($createdBy))
		{
			$this->errorCollection->add([new Error('createdBy user not found')]);

			return null;
		}
	}
	$createdBy = $createdBy ?? $this->getUserId();

	$modifiedBy = 0;
	if (array_key_exists('modifiedBy', $fields) && is_numeric($fields['modifiedBy']))
	{
		$modifiedBy = (int) $fields['modifiedBy'];
		if (!$this->existsUser($modifiedBy))
		{
			$this->errorCollection->add([new Error('modifiedBy user not found')]);

			return null;
		}
	}
	$modifiedBy = $modifiedBy ?? $this->getUserId();

	$backlog = new EntityForm();

	$backlog->setGroupId($groupId);
	$backlog->setCreatedBy($createdBy);
	$backlog->setModifiedBy($modifiedBy);

	$backlog = $backlogService->createBacklog($backlog);

	if (!empty($backlogService->getErrors()))
	{
		$this->errorCollection->add([new Error('Unable to add backlog')]);

		return null;
	}

	return [
		'id' => $backlog->getId(),
		'groupId' => $backlog->getGroupId(),
		'createdBy' => $backlog->getCreatedBy(),
		'modifiedBy' => $backlog->getModifiedBy(),
	];
}