- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/scrum/kanban.php
- Класс: BitrixTasksRestControllersScrumKanban
- Вызов: Kanban::addStageAction
public function addStageAction(array $fields): ?int
{
$sprintId = array_key_exists('sprintId', $fields) ? (int) $fields['sprintId'] : 0;
if (!$sprintId)
{
$this->errorCollection->add([new Error('Sprint id not found')]);
return null;
}
$sprintService = new SprintService();
$sprint = $sprintService->getSprintById($sprintId);
if (!$sprint->getId())
{
$this->errorCollection->add([new Error('Sprint not found')]);
return null;
}
if (!$this->checkAccess($sprint->getGroupId()))
{
$this->errorCollection->add([new Error('Access denied')]);
return null;
}
if (!array_key_exists('name', $fields) || !is_string($fields['name']))
{
$this->errorCollection->add([new Error('Incorrect name format')]);
return null;
}
$stage = [
'TITLE' => $fields['name'],
'ENTITY_ID' => $sprint->getId(),
'ENTITY_TYPE' => StagesTable::WORK_MODE_ACTIVE_SPRINT,
];
$availableTypes = [
StagesTable::SYS_TYPE_NEW,
StagesTable::SYS_TYPE_PROGRESS,
StagesTable::SYS_TYPE_FINISH,
];
$type = StagesTable::SYS_TYPE_PROGRESS;
if (array_key_exists('type', $fields) && in_array($fields['type'], $availableTypes, true))
{
$type = $fields['type'];
}
$stage['SYSTEM_TYPE'] = $type;
$stage['SORT'] = is_numeric($fields['sort'] ?? null) ? (int) $fields['sort'] : 100;
$stage['COLOR'] = array_key_exists('color', $fields) ? (string) $fields['color'] : '00C4FB';
try
{
$result = StagesTable::add($stage);
if ($result->isSuccess())
{
return $result->getId();
}
else
{
$this->errorCollection->setError(new Error('System error'));
return null;
}
}
catch (Exception $exception)
{
$this->errorCollection->setError(new Error('System error'));
return null;
}
}