From 5138b32717c9a54de0882e0319a70eda2bb2c63a Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 21 Feb 2013 22:25:51 -0800 Subject: Score page improvements. --- ajax/maps.ajax.php | 62 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 13 deletions(-) (limited to 'ajax') diff --git a/ajax/maps.ajax.php b/ajax/maps.ajax.php index 611080d..8ceade5 100644 --- a/ajax/maps.ajax.php +++ b/ajax/maps.ajax.php @@ -3,21 +3,35 @@ ob_start("ob_gzhandler"); include('../includes/mapclass.php'); include('../includes/maps.php'); +include('../includes/sqlEmbedded.php'); -//Remove the ending .js -$tmp = explode(".", $_GET['mapid']); -$mapID = $tmp[0] * 1; -if (!is_int($mapID)) exit; - -$map = getMapObjectByID($mapID); +if (isset($_GET['getmapidsbydate'])) { + //Remove the ending .js + $tmp = explode(".", $_GET['getmapidsbydate']); + $requestDate = $tmp[0]; + sendCacheHeaders(); + echo json_encode(getMapIDsByDate($requestDate)); + exit; +} +if (isset($_GET['mapid'])) { + //Remove the ending .js + $tmp = explode(".", $_GET['mapid']); + $mapID = $tmp[0] * 1; + if (!is_int($mapID)) exit; + $map = getMapObjectByID($mapID); + sendCacheHeaders(); + echo json_encode($map); + exit; +} -$expires = 365*24*60*60; -//TODO: Remove this line once we're confident in data in the mapObject. -$expires = 1*24*60*60; -header("Cache-Control: public, maxage=".$expires); -header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT'); -header("Content-type: text/javascript"); -echo json_encode($map); +function sendCacheHeaders() { + $expires = 365*24*60*60; + //TODO: Remove this line once we're confident in data in the mapObject. + $expires = 120; + header("Cache-Control: public, maxage=".$expires); + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT'); + header("Content-type: text/javascript"); +} function getMapObjectByID($mapID) { include_once('../includes/sqlEmbedded.php'); @@ -37,5 +51,27 @@ function getMapObjectByID($mapID) { } } +function getMapIDsByDate($date) { + global $mysqli; + $sql = "SELECT MIN(mapOfTheDay.mapId) AS mapId + FROM `mapOfTheDay` + INNER JOIN + ( + SELECT mapType, MIN(mapExpireTime) AS mapExpireTime + FROM mapOfTheDay + WHERE mapExpireTime > ? + GROUP BY mapType + ) AS expireTimes ON mapOfTheDay.mapType = expireTimes.mapType + AND mapOfTheDay.mapExpireTime = expireTimes.mapExpireTime + GROUP BY mapOfTheDay.mapType"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("s", $date); + $stmt->execute(); + $stmt->bind_result($mapID); + while ($stmt->fetch()) { + $ids[] = $mapID; + } + return $ids; +} ?> \ No newline at end of file -- cgit v1.2.3