<?php

class TouristAttractionModel {

	public static function get($db, $city) {
		$city = (int)$city;

		// Step 1: Load address
		$q = "SELECT tourist_attraction.*,
			address.address,
			address.description AS address_description,
			address.latitude,
			address.longitude,
			address.timezone,
			address.postal
			FROM tourist_attraction
			LEFT JOIN address
			ON tourist_attraction.address_id = address.id
			WHERE
				tourist_attraction.city_id = ${city}
				AND tourist_attraction.active = true LIMIT 5";

		$r = pg_query($db, $q);
		if ($r && pg_num_rows($r)) {
			$results = pg_fetch_all($r);
		} else {
			return [NULL, "Locations not found"];
		}

		return [$results, NULL];
	}
}
