75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Presentation\Mapa;
|
|
|
|
use App\Core\Konstanty;
|
|
use App\Model\ObvodFacade;
|
|
use App\Model\ZaznamFacade;
|
|
use Nette;
|
|
use Nette\Application\Responses\TextResponse;
|
|
use Nette\Utils\Json;
|
|
|
|
|
|
final class MapaPresenter extends Nette\Application\UI\Presenter
|
|
{
|
|
/** Od tohoto počtu měsíců je obvod ve filtru stáří vykreslený červeně. */
|
|
public const STUPNICE_MESICU = 24;
|
|
|
|
/** Od tohoto počtu měsíců je rozpracovaný obvod vykreslený červeně. */
|
|
public const STUPNICE_PRIDELENI = 12;
|
|
|
|
public function __construct(
|
|
private ZaznamFacade $zaznam,
|
|
private ObvodFacade $obvod,
|
|
) {
|
|
}
|
|
|
|
public function beforeRender(): void
|
|
{
|
|
$this->template->appVersion = Konstanty::verze;
|
|
if (!$this->getUser()->isLoggedIn()) {
|
|
$this->template->navrat = $this->storeRequest();
|
|
}
|
|
}
|
|
|
|
public function actionGeojson(): void
|
|
{
|
|
$this->getHttpResponse()->setContentType('application/json', 'utf-8');
|
|
$this->sendResponse(new TextResponse($this->obvod->getGeoJson()));
|
|
}
|
|
|
|
public function actionDefault(?int $obvod = null, ?string $filtr = null): void
|
|
{
|
|
if (!$this->getUser()->isLoggedIn() && $filtr !== null && $filtr !== 'obvody') {
|
|
$this->redirect('this', ['obvod' => $obvod, 'filtr' => null]);
|
|
}
|
|
}
|
|
|
|
public function renderDefault(?int $obvod = null, ?string $filtr = null): void
|
|
{
|
|
$prihlaseny = $this->getUser()->isLoggedIn();
|
|
$povolene = ['obvody', 'stari', 'nedokoncene'];
|
|
if (!$prihlaseny || !in_array($filtr, $povolene, true)) {
|
|
$filtr = 'obvody';
|
|
}
|
|
|
|
$stari = [];
|
|
if ($prihlaseny) {
|
|
$stari = $this->zaznam->getStariObvodu();
|
|
foreach ($stari as &$polozka) {
|
|
$polozka['url'] = $this->link('Obvod:view', $polozka['id']);
|
|
}
|
|
unset($polozka);
|
|
}
|
|
|
|
$this->template->prihlaseny = $prihlaseny;
|
|
$this->template->obvod_id = $obvod;
|
|
$this->template->filtr = $filtr;
|
|
$this->template->maxMesicu = self::STUPNICE_MESICU;
|
|
$this->template->maxPrideleni = self::STUPNICE_PRIDELENI;
|
|
$this->template->stariJson = Json::encode($stari, htmlSafe: true, forceObjects: true);
|
|
}
|
|
}
|