<?php

$context = array();
$context['theme'] = get_template_directory_uri();
require_once(WP_PLUGIN_DIR . "/tospur/Dao/SearchDao.php");

$cityId = 1;
if ($_GET['cityId'])
    $cityId = $_GET['cityId'];
$houseType = 0;
if ($_GET['houseType'])
    $houseType = $_GET['houseType'];
$context['cityId'] = $cityId;
$context['houseType'] = $houseType;
$context['cityName'] = SearchDao::getCityNameWithId($cityId);
$context['select']['city'] = SearchDao::searchCity();
$context['select']['district'] = SearchDao::searchCity($cityId);
$plateArray = array();
foreach ($context['select']['district'] as $item) {
    $plateArray[$item->id] = array();
    foreach (SearchDao::searchCity($cityId, $item->id) as $i) {
        $plateArray[$item->id][] = $i;
    }
}
$context['select']['plate'] = json_encode($plateArray);
$context['select']['buildProperty'] = SearchDao::searchBuildProperty();
$context['select']['room'] = json_encode(SearchDao::searchRoom());
$context['select']['feature'] = json_encode(SearchDao::searchTagOrFeature(1));
$context['select']['unitPriceRange'] = SearchDao::searchUnitPriceRange($cityId);
if ($houseType == 2) {
    $context['select']['rentalPrice'] = SearchDao::searchRentalPrice($cityId);
} else {
    $context['select']['totalPrice'] = SearchDao::searchTotalPrice($cityId);
}
$context['select']['area'] = json_encode(SearchDao::searchArea($cityId));

$context['url'] = home_url();
Timber::render('index.html', $context);
?>