src/Admin/TermAdmin.php line 25

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Admin;
  4. use App\Entity\Season;
  5. use App\Entity\Term;
  6. use App\Repository\SeasonRepository;
  7. use App\Service\TermService;
  8. use Sonata\AdminBundle\Admin\AbstractAdmin;
  9. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  10. use Sonata\AdminBundle\Datagrid\ListMapper;
  11. use Sonata\AdminBundle\Form\FormMapper;
  12. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  13. use Sonata\AdminBundle\Show\ShowMapper;
  14. use Sonata\Form\Type\CollectionType;
  15. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  16. use Symfony\Component\Form\Extension\Core\Type\MoneyType;
  17. final class TermAdmin extends AbstractAdmin
  18. {
  19.     public function __construct(private TermService $termService, ?string $code null, ?string $class null, ?string $baseControllerName null)
  20.     {
  21.         parent::__construct($code$class$baseControllerName);
  22.     }
  23.     protected function configureDatagridFilters(DatagridMapper $filter): void
  24.     {
  25.     }
  26.     protected function configureListFields(ListMapper $list): void
  27.     {
  28.         $list
  29.             ->add('number'null, ['label' => 'Číslo zájezdu'])
  30.             ->add('isFull'null, ['label' => 'Vyprodáno'])
  31.             ->add('isReserved'null, ['label' => 'Rezerováno'])
  32.             ->add('onlyCar'null, ['label' => 'Pouze autem'])
  33.             ->add('onlyBus'null, ['label' => 'Pouze autobusem'])
  34.             ->add(ListMapper::NAME_ACTIONSnull, [
  35.                 'actions' => [
  36. //                    'generate' => ['template' => 'Admin/Term/generate.html.twig'],
  37. //                    'pdf' => ['template' => 'Admin/Term/download.html.twig'],
  38.                     'show' => [],
  39.                     'edit' => [],
  40.                     'delete' => [],
  41.                 ],
  42.             ]);
  43.     }
  44.     protected function configureFormFields(FormMapper $form): void
  45.     {
  46.         $season $this->termService->getActiveSeason();
  47.         /** @var Term $subject */
  48.         $subject $this->getSubject();
  49.         if (empty($subject->getTouristTax())) {
  50.             $subject->setTouristTax($subject->getDestination()->getDefaultTouristTax());
  51.         }
  52.         if (empty($subject->getTouristTaxChildren())) {
  53.             $subject->setTouristTaxChildren($subject->getDestination()->getChildrenTouristTax());
  54.         }
  55.         if (!$subject->getStart() instanceof \DateTime) {
  56.             $subject->setStart(new \DateTime('2025-01-01'));
  57.         }
  58.         if (!$subject->getEnd() instanceof \DateTime) {
  59. //            $subject->setEnd(new \DateTime('2024-12-31'));
  60.         }
  61.         if (!$subject->getSeason() instanceof Season) {
  62.             $subject->setSeason($season);
  63.         }
  64.         if (!empty($subject->getId())) {
  65.             $form->
  66.             tab('Základní nastavení');
  67.         }
  68.         $form
  69.             ->add('isFull'null, ['label' => 'Prodáno'])
  70.             ->add('isReserved'null, ['label' => 'Rezervováno'])
  71.             ->add('onlyCar'null, ['label' => 'Pouze vlastní doprava'])
  72.             ->add('onlyBus'null, ['label' => 'Pouze autobusová doprava'])
  73.             ->add('season'null, ['label' => 'Sezóna'])
  74.             ->add('number'null, ['label' => 'Číslo zájezdu'])
  75.             ->add('touristTax'MoneyType::class, ['label' => 'Pobytová taxa na osobu''currency' => 'CZK'])
  76.             ->add('touristTaxChildren'MoneyType::class, ['label' => 'Pobytová taxa 12 - 18 let''currency' => 'CZK'])
  77.             ->add('start'null, ['label' => 'Začátek''html5' => true'widget' => 'single_text'])
  78.             ->add('end'null, ['label' => 'Konec''html5' => true'widget' => 'single_text'])
  79.             ->add('numberOfDays'null, ['label' => 'Počet dní pob. / zaj.'])
  80.             ->add('departureDay'null, ['label' => 'Den odjezdu'])
  81.             ->add('priceType'ChoiceType::class, [
  82.                 'label' => 'Typ ceny',
  83.                 'choices' => [
  84.                     'Na zájezd' => 'term',
  85.                     'Na osobu' => 'person',
  86.                 ]
  87.             ]);
  88.         if (!empty($subject->getId())) {
  89.             $form->end()
  90.                 ->end()
  91.                 ->tab('Ceny')
  92.                 ->add('termPrices',
  93.                     CollectionType::class,
  94.                     [
  95.                         'by_reference' => false,
  96.                         'type_options' => ['delete' => true]
  97.                     ], [
  98.                         'edit' => 'inline',
  99.                         'inline' => 'table',
  100.                         'sortable' => 'position',
  101.                         'admin_code' => 'admin.term_price',
  102.                     ])
  103.                 ->end()
  104.                 ->end();
  105.         }
  106.     }
  107.     protected function configureShowFields(ShowMapper $show): void
  108.     {
  109.         $show
  110.             ->add('id')
  111.             ->add('number'null, ['label' => 'Číslo zájezdu'])
  112.             ->add('start'null, ['label' => 'Začátek'])
  113.             ->add('end'null, ['label' => 'Konec'])
  114.             ->add('numberOfDays'null, ['label' => 'Počet dní pob. / zaj.'])
  115.             ->add('departureDay'null, ['label' => 'Den odjezdu'])
  116.             ->add('priceType'null, ['label' => 'Typ ceny'])
  117.             ->add('createdAt'null, ['label' => 'Vytvořeno'])
  118.             ->add('updatedAt'null, ['label' => 'Poslední změna']);
  119.     }
  120.     protected function configureRoutes(RouteCollectionInterface $collection): void
  121.     {
  122.         $collection
  123.             ->add('download'$this->getRouterIdParameter() . '/download')
  124.             ->add('generate'$this->getRouterIdParameter() . '/generate');
  125.         if ($this->isChild()) {
  126.             return;
  127.         }
  128.         // This is the route configuration as a parent
  129.         $collection->clear();
  130.     }
  131. }