src/AdminBundle/Admin/Insurance/PayoutsAdmin.php line 14

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Insurance;
  3. use DateTime;
  4. use Sonata\AdminBundle\Admin\AbstractAdmin;
  5. use Sonata\AdminBundle\Datagrid\ListMapper;
  6. use Sonata\AdminBundle\Form\FormMapper;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. class PayoutsAdmin extends AbstractAdmin
  11. {
  12.     protected TranslatorInterface $translator;
  13.     public function setContainerServices(TranslatorInterface $translator): void
  14.     {
  15.         $this->translator $translator;
  16.     }
  17.     protected function configureFormFields(FormMapper $formMapper): void
  18.     {
  19.         $month = [];
  20.         for($i 1$i <= 12$i ++) {
  21.             $month[$i] = $this->translator->trans('date.mh_'.$i,[],'core','ru');
  22.         }
  23.         $nowYear = (new DateTime())->format('Y');
  24.         $years = [
  25.             $nowYear => $nowYear,
  26.             $nowYear-=> $nowYear-1,
  27.             $nowYear-=> $nowYear-2,
  28.         ];
  29.         $formMapper
  30.             ->with('Информация о страховом деле', ['class' => 'col-lg-6'])
  31.                 ->add('month'ChoiceType::class, ['label' => 'Месяц''choices' => array_flip($month)])
  32.                 ->add('year'ChoiceType::class, ['label' => 'Год''choices' => $years])
  33.                 ->add('amount'TextType::class, ['label' => 'Сумма'])
  34.             ->end();
  35.     }
  36.     /**
  37.      * @param ListMapper $listMapper
  38.      */
  39.     protected function configureListFields(ListMapper $listMapper): void
  40.     {
  41.         $month = [];
  42.         for($i 1$i <= 12$i ++) {
  43.             $month[$i] = $this->translator->trans('date.mh_'.$i,[],'core','ru');
  44.         }
  45.         $nowYear = (new DateTime())->format('Y');
  46.         $years = [
  47.             $nowYear => $nowYear,
  48.             $nowYear-=> $nowYear-1,
  49.             $nowYear-=> $nowYear-2,
  50.         ];
  51.         $listMapper->addIdentifier('id')
  52.             ->add('month''choice', ['label' => 'Месяц''choices' => $month])
  53.             ->add('year''choice', ['label' => 'Год''choices' => $years])
  54.             ->add('amount'null, ['label' => 'Сумма'])
  55.             ->add('_action''actions', [
  56.                 'label' => 'Действия',
  57.                 'actions' => [
  58.                     'edit' => [],
  59.                 ]
  60.             ])
  61.         ;
  62.     }
  63. }