• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/dispatcher/publicaction/task/sorting.php
  • Класс: BitrixTasksDispatcherPublicActionTaskSorting
  • Вызов: Sorting::move
public function move($data)
{
	if (!TasksUtilUser::isAuthorized())
	{
		$this->errors->add("AUTH_REQUIRED", Loc::getMessage("TASKS_SORTING_AUTH_REQUIRED"));
		return false;
	}

	$sourceId = isset($data["sourceId"]) ? intval($data["sourceId"]) : 0;
	$targetId = isset($data["targetId"]) ? intval($data["targetId"]) : 0;
	$before = isset($data["before"]) && ($data["before"] === true || $data["before"] === "1");
	$newGroupId = isset($data["newGroupId"]) ? intval($data["newGroupId"]) : null;
	$newParentId = isset($data["newParentId"]) ? intval($data["newParentId"]) : null;
	$currentGroupId = isset($data["currentGroupId"]) ? intval($data["currentGroupId"]) : 0;

	if ($sourceId === $targetId || $sourceId < 1)
	{
		return array();
	}

	try
	{
		$sourceTask = new CTaskItem($sourceId, $this->userId);
		if (!$sourceTask->checkCanRead())
		{
			$this->errors->add("SOURCE_TASK_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_SOURCE_TASK"));
			return false;
		}
	}
	catch (CTaskAssertException $e)
	{
		$this->errors->add("SOURCE_TASK_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_SOURCE_TASK"));
		return false;
	}

	if ($currentGroupId && Loader::includeModule("socialnetwork"))
	{
		$group = CSocNetGroup::getByID($currentGroupId);
		$canSort = SocialNetworkGroup::can($currentGroupId, SocialNetworkGroup::ACTION_SORT_TASKS);
		if (!$group || !$canSort)
		{
			$this->errors->add("GROUP_PERMS_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_GROUP_PERMISSIONS"));
			return false;
		}
	}

	/*
	GROUP_ID and PARENT_ID could be changed after drag&drop manipulations.
	Target task is not required. Example: We want to move Task 1 after Project. In this case a target task is undefined.
		Task 1
		Project (without tasks)
	*/
	$newTaskData = array();
	if ($newGroupId !== null)
	{
		$newTaskData["GROUP_ID"] = $newGroupId;
	}

	if ($newParentId !== null)
	{
		$newTaskData["PARENT_ID"] = $newParentId;
	}

	if (count($newTaskData))
	{
		$sourceTask->update($newTaskData);
	}

	//But it's required for sorting
	if ($targetId < 1)
	{
		return array();
	}

	try
	{
		$targetTask = new CTaskItem($targetId, $this->userId);
		if (!$targetTask->checkCanRead())
		{
			$this->errors->add("TARGET_TASK_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_TARGET_TASK"));
			return false;
		}
	}
	catch (CTaskAssertException $e)
	{
		$this->errors->add("TARGET_TASK_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_TARGET_TASK"));
		return false;
	}

	SortingTable::setSorting($this->userId, $currentGroupId, $sourceId, $targetId, $before);
	return array();
}