ListControls::add

  1. Bitrix24 API (v. 23.675.0)
  2. tasks
  3. ListControls
  4. add
  • Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/dispatcher/publicaction/ui/listcontrols.php
  • Класс: BitrixTasksDispatcherPublicActionUiListControls
  • Вызов: ListControls::add
public function add($data, $parameters = array())
{
	global $DB;

	if (!User::isAuthorized())
	{
		throw new TasksException(Loc::getMessage('TASKS_LISTCONTROLS_AUTH_REQUIRED'));
	}

	$title = isset($data["title"]) ? trim($data["title"]) : "";

	$userEmail = isset($data["userEmail"]) ? trim($data["userEmail"]) : "";
	$userName = isset($data["userName"]) ? trim($data["userName"]) : "";
	$userLastName = isset($data["userLastName"]) ? trim($data["userLastName"]) : "";

	$responsibleId = 0;
	if (isset($data["responsibleId"]))
	{
		$responsibleId = intval($data["responsibleId"]);
	}
	else if ($userEmail === "")
	{
		$responsibleId = User::getId();
	}

	$deadline =
		isset($data["deadline"]) && $DB->FormatDate($data["deadline"], CSite::GetDateFormat("FULL"))
		? $data["deadline"]
		: ""
	;
	$description = isset($data["description"]) ? trim($data["description"]) : "";
	$project = isset($data["project"]) ? intval($data["project"]) : 0;
	$nameTemplate = isset($data["nameTemplate"]) ? trim($data["nameTemplate"]) : "";
	$ganttMode = isset($data["ganttMode"]) && ($data["ganttMode"] === true || $data["ganttMode"] === "1");

	if ($nameTemplate <> '')
	{
		preg_match_all(
			"/(#NAME#)|(#NOBR#)|(#\/NOBR#)|(#LAST_NAME#)|(#SECOND_NAME#)|(#NAME_SHORT#)|(#SECOND_NAME_SHORT#)|\s|\,/",
			$nameTemplate,
			$matches
		);
		$nameTemplate = implode("", $matches[0]);
	}
	else
	{
		$nameTemplate = CSite::GetNameFormat(false);
	}

	$fields = array(
		"TITLE" => $title,
		"DESCRIPTION" => $description,
		"SE_RESPONSIBLE" => array(
			$userEmail !== ""
				? array(
					"EMAIL" => $userEmail,
					"NAME" => $userName,
					"LAST_NAME" => $userLastName
				)
				: array(
					"ID" => $responsibleId
				)
		),
		"DEADLINE" => $deadline,
		"SITE_ID" => $data["siteId"],
		"GROUP_ID" => $project,
		"NAME_TEMPLATE" => $nameTemplate,
		"DESCRIPTION_IN_BBCODE" => "Y"
	);

	if (!$this->checkRights($fields))
	{
		throw new TasksException(Loc::getMessage('TASKS_LISTCONTROLS_ACCESS_DENIED'));
	}

	$taskData = TasksManagerTask::add(User::getId(), $fields);
	$taskItem = CTaskItem::getInstance($taskData["DATA"]["ID"], User::getId());

	try
	{
		$task = $taskItem->getData();
	}
	catch (TasksException $e)
	{
		throw new TasksException();
	}

	$task["GROUP_NAME"] = "";
	if ($task["GROUP_ID"])
	{
		$socGroup = CSocNetGroup::GetByID($task["GROUP_ID"]);
		if ($socGroup)
		{
			$task["GROUP_NAME"] = $socGroup["NAME"];
		}
	}

	IntegrationSocialNetwork::setLogDestinationLast(
		array(
			"USER" => array($task["RESPONSIBLE_ID"]),
			"SGROUP" => array($task["GROUP_ID"])
		)
	);

	$taskId = $taskItem->getId();

	$arPaths = array(
		"PATH_TO_TASKS_TASK" => isset($data["pathToTask"]) ? trim($data["pathToTask"]) : "",
	);

	$getListParameters = $this->unserializeArray("getListParams", $data);

	$result = array();
	$result["taskRaw"] = $task;
	$result["taskId"] = $task["ID"];
	$result["taskPath"] = CComponentEngine::MakePathFromTemplate(
		$arPaths["PATH_TO_TASKS_TASK"],
		array(
			"task_id" => $task["ID"],
			"group_id" => $project,
			"user_id" => User::getId(),
			"action" => "view"
		)
	);

	$result["position"] = $this->getTaskPosition($taskId, $getListParameters);

	if ($ganttMode)
	{
		$result["task"] = $this->getJson($task, $arPaths, $nameTemplate);
	}

	return $result;
}

Добавить комментарий