src/Admin/TermAdmin.php line 25
<?phpdeclare(strict_types=1);namespace App\Admin;use App\Entity\Season;use App\Entity\Term;use App\Repository\SeasonRepository;use App\Service\TermService;use Sonata\AdminBundle\Admin\AbstractAdmin;use Sonata\AdminBundle\Datagrid\DatagridMapper;use Sonata\AdminBundle\Datagrid\ListMapper;use Sonata\AdminBundle\Form\FormMapper;use Sonata\AdminBundle\Route\RouteCollectionInterface;use Sonata\AdminBundle\Show\ShowMapper;use Sonata\Form\Type\CollectionType;use Symfony\Component\Form\Extension\Core\Type\ChoiceType;use Symfony\Component\Form\Extension\Core\Type\MoneyType;final class TermAdmin extends AbstractAdmin{public function __construct(private TermService $termService, ?string $code = null, ?string $class = null, ?string $baseControllerName = null){parent::__construct($code, $class, $baseControllerName);}protected function configureDatagridFilters(DatagridMapper $filter): void{}protected function configureListFields(ListMapper $list): void{$list->add('number', null, ['label' => 'Číslo zájezdu'])->add('isFull', null, ['label' => 'Vyprodáno'])->add('isReserved', null, ['label' => 'Rezerováno'])->add('onlyCar', null, ['label' => 'Pouze autem'])->add('onlyBus', null, ['label' => 'Pouze autobusem'])->add(ListMapper::NAME_ACTIONS, null, ['actions' => [// 'generate' => ['template' => 'Admin/Term/generate.html.twig'],// 'pdf' => ['template' => 'Admin/Term/download.html.twig'],'show' => [],'edit' => [],'delete' => [],],]);}protected function configureFormFields(FormMapper $form): void{$season = $this->termService->getActiveSeason();/** @var Term $subject */$subject = $this->getSubject();if (empty($subject->getTouristTax())) {$subject->setTouristTax($subject->getDestination()->getDefaultTouristTax());}if (empty($subject->getTouristTaxChildren())) {$subject->setTouristTaxChildren($subject->getDestination()->getChildrenTouristTax());}if (!$subject->getStart() instanceof \DateTime) {$subject->setStart(new \DateTime('2025-01-01'));}if (!$subject->getEnd() instanceof \DateTime) {// $subject->setEnd(new \DateTime('2024-12-31'));}if (!$subject->getSeason() instanceof Season) {$subject->setSeason($season);}if (!empty($subject->getId())) {$form->tab('Základní nastavení');}$form->add('isFull', null, ['label' => 'Prodáno'])->add('isReserved', null, ['label' => 'Rezervováno'])->add('onlyCar', null, ['label' => 'Pouze vlastní doprava'])->add('onlyBus', null, ['label' => 'Pouze autobusová doprava'])->add('season', null, ['label' => 'Sezóna'])->add('number', null, ['label' => 'Číslo zájezdu'])->add('touristTax', MoneyType::class, ['label' => 'Pobytová taxa na osobu', 'currency' => 'CZK'])->add('touristTaxChildren', MoneyType::class, ['label' => 'Pobytová taxa 12 - 18 let', 'currency' => 'CZK'])->add('start', null, ['label' => 'Začátek', 'html5' => true, 'widget' => 'single_text'])->add('end', null, ['label' => 'Konec', 'html5' => true, 'widget' => 'single_text'])->add('numberOfDays', null, ['label' => 'Počet dní pob. / zaj.'])->add('departureDay', null, ['label' => 'Den odjezdu'])->add('priceType', ChoiceType::class, ['label' => 'Typ ceny','choices' => ['Na zájezd' => 'term','Na osobu' => 'person',]]);if (!empty($subject->getId())) {$form->end()->end()->tab('Ceny')->add('termPrices',CollectionType::class,['by_reference' => false,'type_options' => ['delete' => true]], ['edit' => 'inline','inline' => 'table','sortable' => 'position','admin_code' => 'admin.term_price',])->end()->end();}}protected function configureShowFields(ShowMapper $show): void{$show->add('id')->add('number', null, ['label' => 'Číslo zájezdu'])->add('start', null, ['label' => 'Začátek'])->add('end', null, ['label' => 'Konec'])->add('numberOfDays', null, ['label' => 'Počet dní pob. / zaj.'])->add('departureDay', null, ['label' => 'Den odjezdu'])->add('priceType', null, ['label' => 'Typ ceny'])->add('createdAt', null, ['label' => 'Vytvořeno'])->add('updatedAt', null, ['label' => 'Poslední změna']);}protected function configureRoutes(RouteCollectionInterface $collection): void{$collection->add('download', $this->getRouterIdParameter() . '/download')->add('generate', $this->getRouterIdParameter() . '/generate');if ($this->isChild()) {return;}// This is the route configuration as a parent$collection->clear();}}