• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/task.php
  • Класс: CTasks
  • Вызов: CTasks::GetGroupsWithTasksForUser
static function GetGroupsWithTasksForUser($userId)
{
	global $DB;

	$userId = (int)$userId;

	// EXISTS!
	$rc = $DB->Query(
		"SELECT GROUP_ID
		FROM b_tasks T
		WHERE (
			T.CREATED_BY = $userId
			OR T.RESPONSIBLE_ID = $userId
			OR EXISTS(
				SELECT 'x'
				FROM b_tasks_member TM
				WHERE TM.TASK_ID = T.ID
					AND TM.USER_ID = $userId
				)
			)
			AND GROUP_ID IS NOT NULL
			AND GROUP_ID != 0
		GROUP BY GROUP_ID
		"
	);

	if (!$rc)
	{
		throw new TasksException();
	}

	$arGroups = [];

	while ($ar = $rc->Fetch())
	{
		$arGroups[] = (int)$ar['GROUP_ID'];
	}

	return (array_unique($arGroups));
}