• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/scrum/epic.php
  • Класс: BitrixTasksRestControllersScrumEpic
  • Вызов: Epic::addAction
public function addAction(array $fields)
{
	$epic = new EpicForm();

	$epicService = new EpicService($this->getUserId());

	$epic->setGroupId($fields['groupId']);
	$epic->setName($fields['name']);

	if (array_key_exists('description', $fields) && is_string($fields['description']))
	{
		$userFields = $epicService->getFilesUserField($this->getUserFieldManager(), $epic->getId());
		$epic->setDescription($this->sanitizeText($fields['description'], $userFields));
	}

	$createdBy = null;
	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;
		}
	}
	$epic->setCreatedBy($createdBy ?? $this->getUserId());

	$epic->setColor($fields['color']);

	$files = (is_array($fields['files']) ? $fields['files'] : []);

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

		return null;
	}

	if (!$epic->getName())
	{
		$this->errorCollection->add([new Error('Name not found')]);

		return null;
	}

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

		return null;
	}

	$epic = $epicService->createEpic($epic);
	if (!empty($epicService->getErrors()))
	{
		$this->errorCollection->add([new Error('Epic not created')]);
		return null;
	}

	if (!empty($files))
	{
		$epicService->attachFiles($this->getUserFieldManager(), $epic->getId(), $files);
		if (!empty($epicService->getErrors()))
		{
			$this->errorCollection->add([new Error('Epic files not attached')]);
			return null;
		}
	}

	return $epic->toArray();
}