Obvody/app/Presentation/Home/HomePresenter.php

52 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Presentation\Home;
use App\Core\Konstanty;
use Nette;
use Nette\Utils\Json;
use Nette\Utils\FileSystem;
final class HomePresenter extends Nette\Application\UI\Presenter
{
public function __construct(
) {
}
public function beforeRender(): void
{
$this->template->appVersion = Konstanty::verze;
if (!$this->getUser()->isLoggedIn()) {
$this->template->navrat = $this->storeRequest();
}
}
public function renderDefault(int $obvod = null): void
{
try {
// načti seznam obvodů:
$content = FileSystem::read('../www/data/geo-obvody.geojson');
// dekóduj geo-json:
$geoObvody = Json::decode($content, true);
} catch (Nette\Utils\JsonException $e) {
// Ošetření výjimky
}
if (empty($geoObvody))
return;
$obvody = array();
foreach ($geoObvody["features"] as $o) {
$obvody[] = $o["properties"]["number"];
}
asort($obvody);
$this->template->obvody = $obvody;
bdump($geoObvody["features"]);
bdump($obvody);
}
}