src/AdminBundle/Admin/DCAutoSite/BoatEngineAdmin.php line 24

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\DCAutoSite;
  3. use AdminBundle\Admin\BaseAdmin;
  4. use DcSiteBundle\Model\BoatEngine;
  5. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  6. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Sonata\AdminBundle\Datagrid\ListMapper;
  9. use Sonata\AdminBundle\Form\Type\ModelListType;
  10. use Sonata\AdminBundle\Form\Type\ModelType;
  11. use Sonata\AdminBundle\Route\RouteCollection;
  12. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  13. use Sonata\Form\Validator\ErrorElement;
  14. use Sonata\MediaBundle\Form\Type\MediaType;
  15. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  16. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  18. use Symfony\Component\Form\FormError;
  19. class BoatEngineAdmin extends BaseAdmin
  20. {
  21.     /**
  22.      * @param RouteCollectionInterface $collection
  23.      */
  24.     protected function configureRoutes(RouteCollectionInterface $collection): void
  25.     {
  26.         $collection->remove('view');
  27.         $collection->remove('delete');
  28.     }
  29.     public function validate(ErrorElement $errorElement$object)
  30.     {
  31.         $hasEngine $this->em->getRepository(\DcSiteBundle\Entity\BoatEngine::class)->createQueryBuilder('be')
  32.             ->where('be.url = :url')
  33.             ->setParameter('url'$object->getUrl())
  34.             ->andWhere('be.id != :id')
  35.             ->setParameter('id'$object->getId())
  36.             ->getQuery()->getResult()
  37.         ;
  38.         if ($hasEngine) {
  39.             $this->getForm()->addError(new FormError('Мотор з таким URL уже существует'));
  40.         }
  41.     }
  42.     /**
  43.      * @param ListMapper $listMapper
  44.      */
  45.     public function configureListFields(ListMapper $listMapper): void
  46.     {
  47.         $listMapper
  48.             ->addIdentifier('title_ru'null, ['label' => 'Название'])
  49.             ->add('state','choice', ['label' => 'Показывать на сайте''editable' => true'choices' => [
  50.                 => 'Да',
  51.                 => 'Нет',
  52.                 null => 'Нет',
  53.             ]])
  54.             ->add('_action','actions',[
  55.                 'label' => 'Действия',
  56.                 'actions' => [
  57.                     'edit' => [],
  58.                 ]
  59.             ])
  60.         ;
  61.     }
  62.     /**
  63.      * @param $object
  64.      */
  65.     public function prePersist($object): void
  66.     {
  67.         $dealer $this->security->getUser()->getDealer();
  68.         $object->setDealer($dealer);
  69.     }
  70.     /**
  71.      * @param FormMapper $formMapper
  72.      */
  73.     public function configureFormFields(FormMapper $formMapper): void
  74.     {
  75.         $dealer $this->security->getUser()->getDealer();
  76.         $formMapper
  77.             ->tab('Характеристики')
  78.                 ->with('Русский', ['class' => 'col-md-6'])
  79.                     ->add('title_ru'null, ['label' => 'Название RU'])
  80.                     ->add('description_ru'TextareaType::class, ['label' => 'Краткое описание RU''required' => false,])
  81.                     ->add('content_ru'CKEditorType::class, ['label' => 'Описание RU''required' => false])
  82.             ->end()
  83.                 ->with('Украинский', ['class' => 'col-md-6'])
  84.                     ->add('title_ua'null, ['label' => 'Название UA'])
  85.                     ->add('description_ua'TextareaType::class, ['label' => 'Краткое описание UA''required' => false,])
  86.                     ->add('content_ua'CKEditorType::class, ['label' => 'Описание UA''required' => false])
  87.                 ->end()
  88.                 ->with('Общие')
  89.                     ->add('price'null, ['label' => 'Цена в валюте'])
  90.                     ->add('alt_price'null, ['label' => 'Акционная цена'])
  91.                     ->add('alt_rate'null, ['label' => 'Акционный курс'])
  92.                     ->add('state',ChoiceType::class, ['label' => 'Показывать на сайте''choices' => array_flip([
  93.                         => 'Да',
  94.                         => 'Нет',
  95.                         null => 'Нет',
  96.                     ])])
  97.                     ->add('position',null, ['label' => 'Порядковый номер на сайте'])
  98.                     ->add('group'ModelType::class, [
  99.                         'label' => 'Группа',
  100.                         'btn_add' => false,
  101.                         'required' => true,
  102.                     ])
  103.                     ->add('url'null, ['label' => 'URL''required' => true])
  104.                 ->end()
  105.                 ->with('Характеристики двигателя', ['class' => 'col-md-6'])
  106.                     ->add('engine_type'ChoiceType::class, [
  107.                         'label' => 'Тип двигателя',
  108.                         'required' => false,
  109.                         'choices' => array_flip(BoatEngine::getEngineType()),
  110.                     ])
  111.                     ->add('engine_volume'null, [
  112.                         'label' => 'Рабочий объем, куб. см',
  113.                         'required' => false,
  114.                     ])
  115.                     ->add('cylinder_count'IntegerType::class, [
  116.                         'label' => 'Количество цилиндров',
  117.                         'required' => false,
  118.                     ])
  119.                     ->add('cylinder_diameter'IntegerType::class, [
  120.                         'label' => 'Диаметр цилиндра, мм',
  121.                         'required' => false,
  122.                     ])
  123.                     ->add('engine_configuration'ChoiceType::class, [
  124.                         'label' => 'Конфигурация двигателя',
  125.                         'required' => false,
  126.                         'choices' => array_flip(BoatEngine::getEngineConfigType()),
  127.                     ])
  128.                     ->add('piston_stroke'IntegerType::class, [
  129.                         'label' => 'Ход поршня, мм',
  130.                         'required' => false,
  131.                     ])
  132.                     ->add('engine_power'null, [
  133.                         'label' => 'Мощность,  кВт / об/мин',
  134.                         'required' => false,
  135.                     ])
  136.                     ->add('gear_ratio'null, [
  137.                         'label' => 'Передаточное соотношение',
  138.                         'required' => false,
  139.                     ])
  140.                     ->add('engine_rpm'null, [
  141.                         'label' => 'Диапазон оборотов при полном газе, об/мин',
  142.                         'required' => false,
  143.                     ])
  144.                     ->add('engine_lubrication'ChoiceType::class, [
  145.                         'label' => 'Система смазки',
  146.                         'required' => false,
  147.                         'choices' => array_flip(BoatEngine::getLubricationType()),
  148.                     ])
  149.                     ->add('oil_tank_volume'null, [
  150.                         'label' => 'Объем емкости масляного картера, л',
  151.                         'required' => false,
  152.                     ])
  153.                     ->add('fuel_injection_system'ChoiceType::class, [
  154.                         'label' => 'Система впрыска топлива',
  155.                         'required' => false,
  156.                         'choices' => array_flip(BoatEngine::getFuelInjectionType()),
  157.                     ])
  158.                     ->add('ignition_coil_generator'null, [
  159.                         'label' => 'Катушка зажигания/генератор',
  160.                         'required' => false,
  161.                     ])
  162.                     ->add('fastening'ChoiceType::class, [
  163.                         'label' => 'Крепление',
  164.                         'required' => false,
  165.                         'choices' => array_flip(BoatEngine::getFasteningType()),
  166.                     ])
  167.                 ->end()
  168.                 ->with('Характеристики электродвигателя', ['class' => 'col-md-6'])
  169.                     ->add('max_amperage'null, [
  170.                         'label' => 'Максимальный ток, А',
  171.                         'required' => false,
  172.                     ])
  173.                     ->add('voltage'null, [
  174.                         'label' => 'Напряжение, В',
  175.                         'required' => false,
  176.                     ])
  177.                     ->add('traction_force'null, [
  178.                         'label' => 'Тяговое усилие, кг',
  179.                         'required' => false,
  180.                     ])
  181.                     ->add('speed_back_forth'ChoiceType::class, [
  182.                         'label' => 'Скорости вперед/назад',
  183.                         'required' => false,
  184.                         'choices' => array_flip(BoatEngine::getSpeedBackForthType()),
  185.                     ])
  186.                     ->add('digital_extension_cord'ChoiceType::class, [
  187.                         'label' => 'Цифровой удлинитель хода',
  188.                         'required' => false,
  189.                         'choices' => array_flip(BoatEngine::getAvailability()),
  190.                     ])
  191.                     ->add('leg_length'null, [
  192.                         'label' => 'Длина ноги, мм',
  193.                         'required' => false,
  194.                     ])
  195.                     ->add('battery_discharge_indicator'ChoiceType::class, [
  196.                         'label' => 'Индикатор разряда батареи',
  197.                         'required' => false,
  198.                         'choices' => array_flip(BoatEngine::getAvailability()),
  199.                     ])
  200.                 ->end()
  201.                 ->with('Управление', ['class' => 'col-md-6'])
  202.                     ->add('start_system_type'ChoiceType::class, [
  203.                         'label' => 'Система запуска',
  204.                         'required' => false,
  205.                         'choices' => array_flip(BoatEngine::getStartType()),
  206.                         //'multiple' => true,
  207.                     ])
  208.                     ->add('steering_type'ChoiceType::class, [
  209.                         'label' => 'Рулевое управление',
  210.                         'required' => false,
  211.                         'choices' => array_flip(BoatEngine::getSteeringTypeType()),
  212.                         //'multiple' => true,
  213.                     ])
  214.                 ->end()
  215.                 ->with('Физические характеристики', ['class' => 'col-md-6'])
  216.                     ->add('recommended_boat_height'null, [
  217.                         'label' => 'Рекомендуемая высота транца, мм',
  218.                         'required' => false,
  219.                     ])
  220.                     ->add('weight'null, [
  221.                         'label' => 'Вес, кг',
  222.                         'required' => false,
  223.                     ])
  224.                 ->end()
  225.             ->end()
  226.             ->tab('Медиа контент')
  227.                 ->with('Изображения', ['class' => 'col-lg-6'])
  228.                     ->add('image'MediaType::class, [
  229.                         'label' => 'Основное изображение',
  230.                         'required' => false,
  231.                         'provider' => 'sonata.media.provider.image',
  232.                         'context'  => 'dc_site'
  233.                     ])
  234.                     ->add('preview'MediaType::class, [
  235.                         'label' => 'Превью',
  236.                         'provider' => 'sonata.media.provider.image',
  237.                         'context'  => 'dc_site'
  238.                     ])
  239.                 ->end()
  240.                 ->with('Галереи', ['class' => 'col-lg-6'])
  241.                     ->add('gallery'ModelListType::class, [
  242.                         'label' => 'Галерея изображений',
  243.                         'btn_list' => false,
  244.                         'required' => false,
  245.                     ], [
  246.                             'edit' => 'inline',
  247.                             'inline' => 'table',
  248.                             'sortable' => 'position',
  249.                             'link_parameters' => [
  250.                                 'context' => 'dc_car_gallery',
  251.                                 'provider' => 'sonata.media.provider.image'
  252.                             ],
  253.                             'admin_code' => 'sonata.media.admin.gallery',
  254.                         ]
  255.                     )
  256.                     ->add('video'ModelListType::class, [
  257.                         'label' => 'Галерея видео',
  258.                         'btn_list' => false,
  259.                         'required' => false,
  260.                     ], [
  261.                         'edit' => 'inline',
  262.                         'inline' => 'table',
  263.                         'sortable' => 'position',
  264.                         'link_parameters' => [
  265.                             'context' => 'dc_car_video',
  266.                             'provider' => 'sonata.media.provider.youtube'
  267.                         ],
  268.                         'admin_code' => 'sonata.media.admin.gallery',
  269.                     ])
  270.                 ->end()
  271.             ->end()
  272.             ->tab('SEO')
  273.                 ->with('RU', ['class' => 'col-md-6'])
  274.                     ->add('seo_title_ru'null, ['label' => 'Seo-title (RU)''required' => false])
  275.                     ->add('seo_description_ru'TextareaType::class, ['label' => 'Seo-description (RU)''required' => false])
  276.                 ->end()
  277.                 ->with('UA', ['class' => 'col-md-6'])
  278.                     ->add('seo_title_ua'null, ['label' => 'Seo-title (UA)''required' => false])
  279.                     ->add('seo_description_ua'TextareaType::class, ['label' => 'Seo-description (UA)''required' => false])
  280.                 ->end()
  281.             ->end()
  282.         ;
  283.     }
  284.     /**
  285.      * @param DatagridMapper $datagridMapper
  286.      */
  287.     public function configureDatagridFilters(DatagridMapper $datagridMapper): void
  288.     {
  289.         $datagridMapper
  290.             ->add('title_ru')
  291.         ;
  292.     }
  293. }