src/AdminBundle/Admin/DealerAdmin.php line 21

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  5. use CoreBundle\Model\DealerModel;
  6. use DcSiteBundle\Form\Transformer\ArrayToStringTransformer;
  7. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  8. use Sonata\AdminBundle\Admin\AbstractAdmin;
  9. use Sonata\AdminBundle\Datagrid\ListMapper;
  10. use Sonata\AdminBundle\Form\FormMapper;
  11. use Sonata\AdminBundle\Form\Type\ModelListType;
  12. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  13. use Sonata\MediaBundle\Form\Type\MediaType;
  14. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  15. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  16. use Symfony\Component\Security\Core\Security;
  17. class DealerAdmin extends AbstractAdmin
  18. {
  19.     protected Security $security;
  20.     public function setContainerServices(Security $security)
  21.     {
  22.         $this->security $security;
  23.     }
  24.     /**
  25.      * @param RouteCollectionInterface $collection
  26.      */
  27.     protected function configureRoutes(RouteCollectionInterface $collection): void
  28.     {
  29.         $collection->remove('view');
  30.         $collection->remove('delete');
  31.         $collection->remove('create');
  32.     }
  33.     public function toString($dealer): string
  34.     {
  35.         return $dealer->getNameRu().' ('.$dealer->getDomain().')';
  36.     }
  37.     /**
  38.      * @param FormMapper $formMapper
  39.      */
  40.     protected function configureFormFields(FormMapper $formMapper): void
  41.     {
  42.         $formMapper
  43.             ->with('Контент', ['class' => 'col-lg-4'])
  44.                 ->add('name_ru',null, ['label' => 'Название RU'])
  45.                 ->add('name',null, ['label' => 'Название UA'])
  46.                 ->add('official_name_ru',null, ['label' => 'Офіційна назва підприємстува RU'])
  47.                 ->add('official_name_ua',null, ['label' => 'Офіційна назва підприємстува UA'])
  48.                 ->add('domain',null, ['label' => 'Домен'])
  49.                 ->add('seo_url',null, ['label' => 'SEO Url'])
  50.                 ->add('output_order',null, ['label' => 'Порядок вывода (VIDI.UA)'])
  51.                 ->add('brand',null, ['label' => 'Бренд'])
  52.                 ->add('city'null, ['label' => 'Город'])
  53.                 ->add('city_name_ru',null, ['label' => 'Город RU'])
  54.                 ->add('city_name_ua',null, ['label' => 'Город UA'])
  55.                 ->add('address_ru',null, ['label' => 'Адресс RU'])
  56.                 ->add('address_ua',null, ['label' => 'Адресс UA'])
  57.                 ->add('phone',null, ['label' => 'Телефон'])
  58.                 ->add('phone_service',null, ['label' => 'Телефон сервиса'])
  59.                 ->add('address_service_ru',null, ['label' => 'Адресс сервиса RU'])
  60.                 ->add('address_service_ua',null, ['label' => 'Адресс сервиса UA'])
  61.                 ->add('email_sale',null, ['label' => 'Email Отдела продаж'])
  62.                 ->add('email_service',null, ['label' => 'Email Отдела Сервиса'])
  63.                 ->add('open_time',null, ['label' => 'Время открытия'])
  64.                 ->add('close_time',null, ['label' => 'Время закрытия'])
  65.                 ->add('lng',null, ['label' => 'Долгота'])
  66.                 ->add('lat',null, ['label' => 'Широта'])
  67.                 ->add('lng_service',null, ['label' => 'Долгота сервиса'])
  68.                 ->add('lat_service',null, ['label' => 'Широта сервиса'])
  69.                 ->add('link_service_video'null, ['label' => 'Ссылка на видео "Запис на сервіс"'])
  70.                 ->add('image_service_center'MediaType::class, [
  71.                     'provider' => 'sonata.media.provider.image',
  72.                     'context'  => 'dc_site',
  73.                     'label' => 'Изображение "Сервис центра"'
  74.                 ])
  75.                 ->add('gallery'ModelListType::class, [
  76.                     'label' => 'Галерея изображений',
  77.                     'btn_list' => false,
  78.                     'required' => false,
  79.                 ], [
  80.                         'edit' => 'inline',
  81.                         'inline' => 'table',
  82.                         'sortable' => 'position',
  83.                         'link_parameters' => [
  84.                             'context' => 'insurance',
  85.                             'provider' => 'sonata.media.provider.image'
  86.                         ],
  87.                         'admin_code' => 'sonata.media.admin.gallery',
  88.                     ]
  89.                 )
  90.             ->end()
  91. //            Закоментовано до моменту перероблення структури часів роботи
  92. //            ->with('Часы работы | Пустое поле = выходной', ['class' => 'col-lg-3'])
  93. //            ->add('dealerWorkHours',DealerWorkHoursType::class, ['label' => false])
  94. //            ->end()
  95.             ->with('Описание', ['class' => 'col-lg-4'])
  96.                 ->add('description_ua',CKEditorType::class, ['label' => 'Описание UA'])
  97.                 ->add('description_ru',CKEditorType::class, ['label' => 'Описание RU'])
  98.             ->end()
  99.             ->with('Параметры', ['class' => 'col-lg-4'])
  100.                 ->add('facilities',ChoiceType::class, [
  101.                     'choices' => array_flip(DealerModel::getFacilitiesType()),
  102.                     'label' => 'Услуги',
  103.                     'expanded' => true,
  104.                     'multiple' => true,
  105.                 ])
  106.             ->end()
  107.             ->with('Другое', ['class' => 'col-lg-4'])
  108.                 ->add('facebook_pixel_code',null, ['label' => 'Facebook Pixel Code'])
  109.                 ->add('tik_tok_pixel_code',null, ['label' => 'Tik Tok Pixel Code'])
  110.                 ->add('gtm_code',null, ['label' => 'GTM Code'])
  111.                 ->add('nova_poshta_api_key'null, ['label' => 'API Ключ Нова пошта'])
  112.                 ->add('iban',null, ['label' => 'IBAN'])
  113.                 ->add('merchant_id'null, ['label' => 'Идентификатор продавца (merchant_id)'])
  114.                 ->add('edrpou',null, ['label' => 'ЕДРПО'])
  115.                 ->add('link_facebook'null, ['label' => 'Ссылка на facebook'])
  116.                 ->add('link_youtube'null, ['label' => 'Ссылка на youtube'])
  117.                 ->add('link_instagram'null, ['label' => 'Ссылка на instagram'])
  118.             ->end()
  119.         ;
  120.         $formMapper->get('facilities')->addModelTransformer(new ArrayToStringTransformer());
  121.     }
  122.     /**
  123.      * @param string $context
  124.      * @return ProxyQueryInterface
  125.      */
  126.     public function configureQuery($context 'list'): ProxyQueryInterface
  127.     {
  128.         $user $this->security->getUser();
  129.         $query parent::configureQuery($context);
  130.         if($user->hasRole('ROLE_SUPER_ADMIN') || $user->hasRole('ROLE_CONTENT_MANAGER') ) {
  131.             return $query;
  132.         }
  133.         $dealer $user->getDealer();
  134.         if(!$dealer) {
  135.             throw new AccessDeniedException();
  136.         }
  137.         $query->andWhere(
  138.             $query->expr()->eq($query->getRootAliases()[0].'.id'':id')
  139.         );
  140.         $query->setParameter('id'$dealer->getId());
  141.         return $query;
  142.     }
  143.     /**
  144.      * @param ListMapper $listMapper
  145.      */
  146.     protected function configureListFields(ListMapper $listMapper): void
  147.     {
  148.         $listMapper->addIdentifier('id')
  149.             ->add('name',null, ['label' => 'Название'])
  150.             ->add('domain',null, ['label' => 'Домен'])
  151.             ->add('adress',null, ['label' => 'Адрес'])
  152.             ->add('_action''actions', [
  153.                 'label' => 'Действия',
  154.                 'actions' => [
  155.                     'edit' => [],
  156.                 ]
  157.             ])
  158.         ;
  159.     }
  160. }