src/AdminBundle/Admin/Insurance/CaseAdmin.php line 24

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Insurance;
  3. use AdminBundle\Form\Type\CaseDocumentType;
  4. use AdminBundle\Form\Type\InsuranceSmsType;
  5. use CoreBundle\Entity\User;
  6. use InsuranceBundle\Model\InsuranceCase;
  7. use Sonata\AdminBundle\Admin\AbstractAdmin;
  8. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  9. use Sonata\AdminBundle\Datagrid\ListMapper;
  10. use Sonata\AdminBundle\Form\FormMapper;
  11. use Sonata\AdminBundle\Route\RouteCollection;
  12. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  13. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  14. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  15. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  16. use Symfony\Component\Form\Extension\Core\Type\DateType;
  17. use Symfony\Component\Form\Extension\Core\Type\FileType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextType;
  19. use Symfony\Component\HttpFoundation\File\UploadedFile;
  20. class CaseAdmin extends AbstractAdmin
  21. {
  22.     protected ParameterBagInterface $parameterBag;
  23.     public function setContainerServices(ParameterBagInterface $parameterBag): void
  24.     {
  25.         $this->parameterBag $parameterBag;
  26.     }
  27.     protected $datagridValues = [
  28.         '_page' => 1,
  29.         '_sort_order' => 'ASC',
  30.         '_sort_by' => 'position',
  31.     ];
  32.     /**
  33.      * @param RouteCollection $collection
  34.      */
  35.     protected function configureRoutes(RouteCollectionInterface $collection): void
  36.     {
  37.         $collection->remove('create');
  38.         $collection->remove('delete');
  39.     }
  40.     public function toString($object): string
  41.     {
  42.         return 'Страховое дела № '.$object->getCaseNumber();
  43.     }
  44.     /**
  45.      * @param \InsuranceBundle\Entity\InsuranceCase $object
  46.      */
  47.     public function preUpdate($object): void
  48.     {
  49.         $cPhone $object->getContactPhone();
  50.         if($cPhone) {
  51.             $object->setContactPhone('0'.(int) $cPhone);
  52.         }
  53.         /** @var UploadedFile $file */
  54.         $file $object->getWMail();
  55.         if($file instanceof UploadedFile) {
  56.             $fileName md5(uniqid()).'.'.$file->guessExtension();
  57.             $filesDir $this->parameterBag->get('kernel.project_dir').'/public/uploads/insurance';
  58.             $file->move(
  59.                 $filesDir,
  60.                 $fileName
  61.             );
  62.             $object->setWMail($fileName);
  63.         }
  64.         parent::preUpdate($object);
  65.     }
  66.     protected function configureFormFields(FormMapper $formMapper): void
  67.     {
  68.         $em $this->getModelManager()->getEntityManager(User::class);
  69.         $query $em->createQueryBuilder('u')
  70.             ->select('u')
  71.             ->from('CoreBundle:User''u')
  72.             ->where('u.roles LIKE :roles')
  73.             ->setParameter('roles''%"ROLE_INSURANCE_AVARKOM"%');
  74.             ;
  75.         $formMapper
  76.             ->with('Информация о страховом деле', ['class' => 'col-lg-6'])
  77.                 ->add('state'ChoiceType::class, ['label' => 'Статус''choices' => array_flip(InsuranceCase::getStatus())])
  78.                 ->add('contact_phone'TextType::class, ['label' => 'Контактный телефон (ОБЯЗАТЕЛЬНО в формате 0671234567)''attr' => ['max' => 999999999], 'required' => false])
  79.                 ->add('date_case'DateType::class, ['label' => 'Дата наступления случая''widget' => 'single_text''attr' => ['readonly' => true]])
  80.                 ->add('user.fullName'TextType::class, ['label' => 'Клиент''attr' => ['readonly' => true]])
  81.                 ->add('user.phone'TextType::class, ['label' => 'Номер телефона пользователя''attr' => ['readonly' => true]])
  82.             ->end()
  83.             ->with(' ', ['class' => 'col-lg-6'])
  84.                 ->add('manager'EntityType::class , ['class' => User::class,  'query_builder' => $query'label' => 'Аварийный комиссар'], [
  85.                     'admin_code' => 'admin.user'
  86.                 ])
  87.                 ->add('contract_number'TextType::class, ['label' => 'Номер договора''attr' => ['readonly' => true]])
  88.                 ->add('car.brand'TextType::class, ['label' => 'Марка автомобиля''attr' => ['readonly' => true]])
  89.                 ->add('car.model'TextType::class, ['label' => 'Модель автомобиля''attr' => ['readonly' => true]])
  90.                 ->add('car.number'TextType::class, ['label' => 'Гос. номер автомобиля''attr' => ['readonly' => true]])
  91.             ->end();
  92.         $formMapper->with('Дополнительная информация', ['class' => 'col-lg-12'])
  93.             ->add('pay_date'DateType::class , ['widget' => 'single_text''label' => 'Дата выплаты''required' => false'attr' => ['style' => 'width: 300px']]);
  94.         if($this->getSubject()->getState() == InsuranceCase::STATE_QUARANTEE) {
  95.             if($this->getSubject()->getWMail()) {
  96.                 $formMapper->add('fff'TextType::class, ['label' => 'Гарантийное письмо заргужено''attr' => ['style' => 'display:none'] , 'required' => false'mapped' => false]);
  97.             }
  98.             $formMapper->add('w_mail'FileType::class, ['label' => false'required' => false'data_class' => null]);
  99.         }
  100.         $formMapper->end();
  101.         $formMapper->with('СМС уведомления', ['class' => 'col-lg-12'])
  102.             ->add('sms'InsuranceSmsType::class, ['label' => false'mapped' => false])
  103.         ->end();
  104.         $formMapper->with('Список документов', ['class' => 'col-lg-12'])
  105.                 ->add('documents'CaseDocumentType::class, ['label' => false'required' => false])
  106.             ->end()
  107.         ;
  108.     }
  109.     /**
  110.      * @param ListMapper $listMapper
  111.      */
  112.     protected function configureListFields(ListMapper $listMapper): void
  113.     {
  114.         $listMapper->addIdentifier('id')
  115.             ->add('case_number',null, ['label' => '№ страхового дела''format' => 'd.m.Y'])
  116.             ->add('contract_number',null, ['label' => '№ договора''format' => 'd.m.Y'])
  117.             ->add('user.fullName',null, ['label' => 'Ф.И.О. Клиента'])
  118.             ->add('car.number',null, ['label' => 'Гос. номер автомобиля'])
  119.             ->add('phone',null, ['label' => 'Контактный телефон'])
  120.             ->add('date_case',null, ['label' => 'Дата наступления случая''format' => 'd.m.Y'])
  121.             ->add('_action''actions', [
  122.                 'label' => 'Действия',
  123.                 'actions' => [
  124.                     'edit' => [],
  125.                     'print' => [
  126.                         'template' => '@AdminBundle/CRUD/list__action_print_sticker.html.twig'
  127.                     ],
  128.                 ]
  129.             ])
  130.         ;
  131.     }
  132.     /**
  133.      * @param DatagridMapper $datagridMapper]
  134.      */
  135.     protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
  136.     {
  137.         $datagridMapper
  138.             ->add('user.phone',null, ['label' => 'Номер телефона'])
  139.             ->add('contact_phone',null, ['label' => 'Альтернативный номер телефона'])
  140.             ->add('contract_number',null, ['label' => '№ договора'])
  141.             ->add('case_number',null, ['label' => '№ страхового дела'])
  142.             ->add('user.last_name',null, ['label' => 'Фамилия клиента'])
  143.             ->add('car.number',null, ['label' => 'Гос. номер автомобиля'])
  144.             ->add('date_case',null, ['label' => 'Дата наступления случая'])
  145.         ;
  146.     }
  147.     protected function configure(): void
  148.     {
  149.         parent::configure(); // TODO: Change the autogenerated stub
  150.         $this->setTemplate('edit''@Admin/admin/CRUD/edit-insurance-case.html.twig');
  151.     }
  152. }