• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/checklist/internals/checklist.php
  • Класс: BitrixTasksCheckListInternalsCheckList
  • Вызов: CheckList::processAdd
private function processAdd()
{
	/** @noinspection PhpVariableNamingConventionInspection */
	global $USER_FIELD_MANAGER;

	$addResult = new Result();

	$facade = $this->facade;
	$checkListTree = $this->checkListTree;
	$checkListDataController = $this->checkListDataController;
	$checkListMemberDataController = $this->checkListMemberDataController;

	$this->fillMandatoryFields();
	$this->recountSortIndexes(Application::getConnection());

	$fields = $this->getFields();
	$fieldsForTable = $facade::getFieldsForTable($fields);

	$tableAddResult = $checkListDataController::add($fieldsForTable);
	$id = ($tableAddResult->isSuccess()? $tableAddResult->getId() : false);

	if (!$id)
	{
		$facade::logError($tableAddResult->getErrorMessages()[0]);
		$addResult->addError('CHECKLIST_TABLE_ADD_FAILED', Loc::getMessage('TASKS_INTERNALS_CHECKLIST_CHECKLIST_TABLE_ADD_FAILED'));
		return $addResult;
	}

	if ($fields['PARENT_ID'] === 0)
	{
		$checkListTree::ensureNodeExists($id);
	}
	else
	{
		$attachResult = $checkListTree::attachNew($id, $fields['PARENT_ID']);
		if (!$attachResult->isSuccess())
		{
			$checkListDataController::delete($id);

			$addResult->loadErrors($attachResult->getErrors());
			return $addResult;
		}
	}

	foreach ($fields['MEMBERS'] as $userId => $data)
	{
		$checkListMemberDataController::add(['ITEM_ID' => $id, 'USER_ID' => $userId, 'TYPE' => $data['TYPE']]);
	}

	if (!empty($fields['ATTACHMENTS']) && ModuleManager::isModuleInstalled('disk'))
	{
		$userFields = ['UF_CHECKLIST_FILES' => $fields['ATTACHMENTS']];
		$USER_FIELD_MANAGER->Update($this->userFieldsEntityIdName, $id, $userFields, $this->userId);

		$this->setFields(['ATTACHMENTS' => $facade::getList(['ATTACHMENTS'], ['ID' => $id])[$id]['ATTACHMENTS']]);
	}

	$this->fields->setId($id);

	$facade::doAddPostActions($this->fields->getEntityId(), $this->userId, $this);

	return $addResult;
}