47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Presentation\Nastaveni;
|
|
|
|
use App\Core\MapovyPodklad;
|
|
use App\Presentation\BasePresenter;
|
|
use Nette\Application\UI\Form;
|
|
use Nette\Utils\ArrayHash;
|
|
|
|
|
|
final class NastaveniPresenter extends BasePresenter
|
|
{
|
|
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));
|
|
}
|
|
}
|