Task::getList

  1. Bitrix24 API (v. 23.675.0)
  2. tasks
  3. Task
  4. getList
  • Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/manager/task.php
  • Класс: Bitrix\Tasks\Manager\Task
  • Вызов: Task::getList
static function getList($userId, array $listParameters = [], array $parameters = [])
{
	$data = [];
	$can = [];
	$params = [];

	$userId = (int) $userId;

	$errors = static::ensureHaveErrorCollection($parameters);

	// todo: get rid of LIST_PARAMETERS, if can. Move limit, filter, sort, etc.. to the first level

	if (array_key_exists('NAV_PARAMS', $listParameters) && !empty($listParameters['NAV_PARAMS']))
	{
		$params = ['NAV_PARAMS' => $listParameters['NAV_PARAMS']];
	}
	else
	{
		$navParams = static::prepareNav(
			($listParameters['limit'] ?? null),
			($listParameters['offset'] ?? null),
			($listParameters['page'] ?? null),
			($parameters['PUBLIC_MODE'] ?? null)
		);
		if (!empty($navParams))
		{
			$params = ['NAV_PARAMS' => $navParams];
		}
	}

	if (array_key_exists('TARGET_USER_ID', $parameters))
	{
		$params['TARGET_USER_ID'] = $parameters['TARGET_USER_ID'];
	}

	$params['DISTINCT'] = $parameters['DISTINCT'] ?? false;
	if (!array_key_exists('select', $listParameters) || !is_array($listParameters['select']))
	{
		$listParameters['select'] = [];
	}
	$getNewCommentsCount = in_array('NEW_COMMENTS_COUNT', $listParameters['select'], true);

	if (
		array_key_exists('SORTING', (array)($listParameters['order'] ?? []))
		&& array_key_exists('GROUP_ID', $listParameters['legacyFilter'])
	)
	{
		$params['SORTING_GROUP_ID'] = $listParameters['legacyFilter']['GROUP_ID'];
	}

	if (array_key_exists('USE_MINIMAL_SELECT_LEGACY', $parameters))
	{
		$params['USE_MINIMAL_SELECT_LEGACY'] = $parameters['USE_MINIMAL_SELECT_LEGACY'];
	}
	if (array_key_exists('MAKE_ACCESS_FILTER', $parameters))
	{
		$params['MAKE_ACCESS_FILTER'] = $parameters['MAKE_ACCESS_FILTER'];
	}

	if ($getNewCommentsCount)
	{
		$listParameters['select'][] = 'CREATED_DATE';
		$listParameters['select'][] = 'VIEWED_DATE';
	}

	if (
		!array_key_exists('RETURN_ACCESS', $parameters)
		|| (array_key_exists('RETURN_ACCESS', $parameters) && $parameters['RETURN_ACCESS'] != 'N')
	)
	{
		$listParameters['select'][] = 'ALLOW_CHANGE_DEADLINE';
		$listParameters['select'][] = 'TASK_CONTROL';
		$listParameters['select'][] = 'ALLOW_TIME_TRACKING';
	}

	// an exception about sql error may fall here
	[$items, $res] = \CTaskItem::fetchListArray(
		$userId,
		($listParameters['order'] ?? null),
		$listParameters['legacyFilter'] ?? null,
		$params,
		$listParameters['select']
	);

	if (is_array($items) && !empty($items))
	{
		(new \Bitrix\Tasks\Access\AccessCacheLoader())->preload($userId, array_column($items, 'ID'));

		foreach ($items as $taskData)
		{
			$taskId = $taskData['ID'];

			if (!array_key_exists('RETURN_ACCESS', $parameters) || $parameters['RETURN_ACCESS'] != 'N')
			{
				$taskData['ACTION'] = $can[$taskId]['ACTION'] = static::translateAllowedActionNames(
					\CTaskItem::getAllowedActionsArray($userId, $taskData, true)
				);
			}

			$data[$taskId] = $taskData;
		}
	}

	return [
		'DATA' => $data,
		'CAN' => $can,
		'ERRORS' => $errors,
		'AUX' => [
			'OBJ_RES' => $res,
		],
	];
}

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