<?php
// required header
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
 
// include database and object files
include_once '../config/database.php';
include_once '../objects/poi.php';
 
// instantiate database and destination object
$database = new Database();
$db = $database->getConnection();
 
// initialize object
$poi = new Poi($db);
 
// query destinations
$stmt = $poi->readAll();
$num = $stmt->rowCount();
 
// check if more than 0 record found
if($num>0){
 
    // products array
    $pois_arr=array();
    $pois_arr["records"]=array();
 
    // retrieve our table contents
    // fetch() is faster than fetchAll()
    // http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop
    
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        // extract row
        // this will make $row['name'] to
        // just $name only

        extract($row);

        $poi_item=array(
            "Id" => $Id,
            "destinationId" => $destinationId,
            "typeId" => $typeId,
            "Name" => html_entity_decode($Name),
            "Description" => html_entity_decode($Description),
            "Street" => html_entity_decode($Street),
            "StreetNumber" => html_entity_decode($StreetNumber),
            "Postcode" => html_entity_decode($Postcode),
            "Latitude" => html_entity_decode($Latitude),
            "Longtitude" => html_entity_decode($Longtitude),
            "imageURL" => html_entity_decode($imageURL),
            "Recommended" => $Recommended,
        );
 
        array_push($pois_arr["records"], $poi_item);
    }
 
    // set response code - 200 OK
    http_response_code(200);


    // show destinations data in json format
    echo json_encode($pois_arr);
}
 
else{
 
    // set response code - 404 Not found
    http_response_code(404);
 
    // tell the user no destinations found
    echo json_encode(
        array("message" => "No POI found.")
    );
}
?>