Obvody/app/Presentation/Nastaveni/NastaveniPresenter.php

54 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Presentation\Nastaveni;
use App\Core\MapovyPodklad;
use Nette\Application\UI\Form;
use Nette\Application\UI\Presenter;
use Nette\Utils\ArrayHash;
final class NastaveniPresenter extends Presenter
{
public function beforeRender(): void
{
if (!$this->getUser()->isLoggedIn()) {
$this->template->navrat = $this->storeRequest();
}
}
protected function createComponentPodkladForm(): Form
{
$form = new Form;
$form->addRadioList('podklad', 'Mapové podklady', MapovyPodklad::moznosti())
->setDefaultValue($this->aktualni())
->setRequired('Vyberte mapové podklady.');
$form->addSubmit('send', 'Uložit');
$form->addProtection('Platnost formuláře vypršela, odešlete ho znovu.');
$form->onSuccess[] = $this->podkladFormSucceeded(...);
return $form;
}
private function podkladFormSucceeded(Form $form, ArrayHash $values): void
{
$this->getHttpResponse()->setCookie(
MapovyPodklad::COOKIE,
MapovyPodklad::platny((string) $values->podklad),
'+1 year',
'/',
null,
null,
false,
);
$this->flashMessage('Nastavení bylo uloženo.');
$this->redirect('default');
}
private function aktualni(): string
{
return MapovyPodklad::platny($this->getHttpRequest()->getCookie(MapovyPodklad::COOKIE));
}
}