SELECT
	id AS id,
	name AS name
FROM
	calendars
WHERE
	(
		resource_id
		IN
		(
			SELECT
				id
			FROM
				resources
			WHERE
				(
					(
						(kind = 'local')
						AND
						(
							sub_id
							IN
							(
								SELECT
									local_resource_id
								FROM
									local_resource_events
								WHERE
									(public = TRUE)
								/*
								GROUP BY
									local_resource_id
								 */
							)
						)
					)
					OR
					(
						(kind = 'caldav')
					)
				)
		)
	)
;
