src/AdminBundle/Admin/Insurance/ReviewAdmin.php line 17

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Insurance;
  3. use Sonata\AdminBundle\Admin\AbstractAdmin;
  4. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  5. use Sonata\AdminBundle\Datagrid\ListMapper;
  6. use Sonata\AdminBundle\Form\FormMapper;
  7. use Sonata\AdminBundle\Form\Type\ModelListType;
  8. use Sonata\AdminBundle\Route\RouteCollection;
  9. use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
  10. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. class ReviewAdmin extends AbstractAdmin
  14. {
  15.     /**
  16.      * @param RouteCollection $collection
  17.      */
  18.     protected function configureRoutes(RouteCollectionInterface $collection): void
  19.     {
  20.         $collection->remove('delete');
  21.         $collection->remove('view');
  22.     }
  23.     public function toString($object): string
  24.     {
  25.         return 'Отзыв пользователя '.$object->getUserName();
  26.     }
  27.     protected function configureFormFields(FormMapper $formMapper): void
  28.     {
  29.         $formMapper
  30.             ->with('Отзыв', ['class' => 'col-lg-6'])
  31.             ->add('state'ChoiceType::class, ['label' => 'Статус''choices' => [
  32.                 'Новый' => 0,
  33.                 'Опубликован' => 1,
  34.                 'Отклонен' => 2,
  35.                 'Комплаєнс' => 3,
  36.             ]])
  37.             ->add('user_name'null,['label' => 'Имя пользователя'])
  38.             ->add('email'null,['label' => 'Email пользователя'])
  39.             ->add('comment'TextareaType::class,['label' => 'Комментарий'])
  40.             ->add('response'TextareaType::class,['label' => 'Ответ'])
  41.             ->end()
  42.             ->with('Фото', ['class' => 'col-lg-6'])
  43.                 ->add('gallery'ModelListType::class, [
  44.                     'label' => 'Галерея изображений',
  45.                     'btn_list' => false,
  46.                     'required' => false,
  47.                 ], [
  48.                         'edit' => 'inline',
  49.                         'inline' => 'table',
  50.                         'sortable' => 'position',
  51.                         'link_parameters' => [
  52.                             'context' => 'insurance',
  53.                             'provider' => 'sonata.media.provider.image'
  54.                         ],
  55.                         'admin_code' => 'sonata.media.admin.gallery',
  56.                     ]
  57.                 )
  58.             ->end();
  59.     }
  60.     /**
  61.      * @param DatagridMapper $datagridMapper
  62.      */
  63.     protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
  64.     {
  65.         $datagridMapper->add('review_type'ChoiceFilter::class, [
  66.             'label' => 'Отзывы/Комплаєнс',
  67.             'field_type' => ChoiceType::class,
  68.             'field_options' => [
  69.                 'choices' => [
  70.                     'Отзывы' => 0,
  71.                     'Комплаєнс' => 1,
  72.                 ],
  73.                 'expanded' => false,
  74.                 'multiple' => false,
  75.             ],
  76.         ]);
  77.     }
  78.     /**
  79.      * @param ListMapper $listMapper
  80.      */
  81.     protected function configureListFields(ListMapper $listMapper): void
  82.     {
  83.         $listMapper->addIdentifier('id')
  84.             ->add('user_name'null,['label' => 'Имя пользователя'])
  85.             ->add('email'null,['label' => 'Email пользователя'])
  86.             ->add('date_create'null,['label' => 'Дата создания'])
  87.             ->add('state','choice', ['label' => 'Статус''editable' => true'choices' => [
  88.                 => 'Новый',
  89.                 => 'Опубликован',
  90.                 => 'Отклонен',
  91.                 => 'Комплаєнс',
  92.             ]])
  93.             ->add('_action''actions', [
  94.                 'label' => 'Действия',
  95.                 'actions' => [
  96.                     'edit' => [],
  97.                     'print' => [
  98.                         'template' => '@AdminBundle/CRUD/list__action_print_sticker.html.twig'
  99.                     ],
  100.                 ]
  101.             ])
  102.         ;
  103.     }
  104. }