src/Admin/SuporteAdmin.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Admin;
  4. use App\Entity\Suporte;
  5. use App\Enums\ModulosSistemaEnum;
  6. use App\Enums\StatusSuporteEnum;
  7. use App\Enums\TipoSuporteEnum;
  8. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  9. use Sonata\AdminBundle\Datagrid\ListMapper;
  10. use Sonata\AdminBundle\Form\FormMapper;
  11. use Sonata\AdminBundle\Show\ShowMapper;
  12. use Sonata\Form\Type\DateTimePickerType;
  13. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  14. use Sonata\Form\Type\DatePickerType;
  15. use Symfony\Component\Form\Extension\Core\Type\DateType;
  16. use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;
  17. final class SuporteAdmin extends BaseAdmin
  18. {
  19.     protected $datagridValues = [
  20.         '_page'         => 1,
  21.         '_sort_order'   => 'ASC',
  22.         '_sort_by'      => 'dataEntrega'
  23.     ];
  24.     public function prePersist($object)
  25.     {
  26.         /** @var Suporte $object */
  27.         $object->setUsuario($this->getUserLogado());
  28.         $object->setStatus(StatusSuporteEnum::ABERTO);
  29.         return $object;
  30.     }
  31.     public function createQuery($context 'list')
  32.     {
  33.         $query parent::createQuery($context); // TODO: Change the autogenerated stub
  34.         
  35.         $query->andWhere(
  36.             $query->expr()->eq($query->getRootAlias().'.isPago'':isPago')
  37.         );
  38.         
  39.         $query->setParameters([
  40.             'isPago'  => false
  41.         ]);
  42.         return $query;
  43.     }
  44.     protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
  45.     {
  46.         $datagridMapper
  47.             ->add('id')
  48.             ->add('modulo''doctrine_orm_choice', [
  49.                 'field_options' => [
  50.                     'choices' => ModulosSistemaEnum::getAssociatedValues(),
  51.                     'expanded' => false// Se quiser como select
  52.                     'multiple' => false// Se quiser permitir múltipla seleção, mude para true
  53.                 ],
  54.                 'field_type' => ChoiceType::class,
  55.             ])
  56.             ->add('descricao')
  57.             ->add('titulo')
  58.             ->add('status''doctrine_orm_choice', [
  59.                 'field_options' => [
  60.                     'choices' => StatusSuporteEnum::getAssociatedValues(),
  61.                     'expanded' => false,
  62.                     'multiple' => false,
  63.                 ],
  64.                 'field_type' => ChoiceType::class,
  65.             ])
  66.             ->add('createdAt')
  67.             ->add('dataEntrega')
  68.             ->add('horas')
  69.             ->add('resolvidoEm')
  70.             ->add('obsResolucao')
  71.             ->add('tipo''doctrine_orm_choice', [
  72.                 'field_options' => [
  73.                     'choices' => TipoSuporteEnum::getAssociatedValues(),
  74.                     'expanded' => false,
  75.                     'multiple' => false,
  76.                 ],
  77.                 'field_type' => ChoiceType::class,
  78.             ])
  79.             ->add('isPago')
  80.         ;
  81.     }
  82.     protected function configureListFields(ListMapper $listMapper): void
  83.     {
  84.         $this->setTemplate('list''Suporte/list.html.twig');
  85.         
  86.         if ($this->isGranted('ROLE_SUPER_ADMIN')) {
  87.             $listMapper->add('id');
  88.             $listMapper->add('isPago',null, ['label'=>'PAGO','template'=>'Suporte/isPago.html.twig']);
  89.         }
  90.             
  91.         if ($this->isGranted('ROLE_SUPER_ADMIN')) {
  92.             
  93.             $listMapper
  94.                 ->add('titulo')
  95.                 ->add('tipo')
  96.                 ->add('modulo')
  97.                 ->add('status',null, ['label'=>'Status','template'=>'Suporte/status_list.html.twig'])
  98.                 ->add('dataEntrega''date', [
  99.                     'label' => 'Previsão de entrega',
  100.                     'format' => 'd/m/Y',
  101.                 ])
  102.                 ->add('_action'null, [
  103.                     'actions' => [
  104.                         'show' => [],
  105.                         'edit' => [],
  106.                         'delete' => [],
  107.                     ],
  108.                 ]);
  109.                 
  110.         } else {
  111.             
  112.             $listMapper
  113.                 ->add('titulo')
  114.                 ->add('tipo')
  115.                 ->add('modulo')
  116.                 ->add('status',null, ['label'=>'Status','template'=>'Suporte/status_list.html.twig'])
  117.                 ->add('dataEntrega''date', [
  118.                     'label' => 'Previsão de entrega',
  119.                     'format' => 'd/m/Y',
  120.                 ])
  121.                 ->add('_action'null, [
  122.                     'actions' => [
  123.                         'show' => [],
  124.                     ],
  125.                 ]);
  126.         }
  127.     }
  128.     protected function configureFormFields(FormMapper $formMapper): void
  129.     {
  130.         $formMapper->add('isPago'null, ['label'=>'Pago']);
  131.         
  132.         if ($this->isGranted('ROLE_SUPER_ADMIN')) {
  133.             $formMapper
  134.                 ->add('tipo'ChoiceType::class, [
  135.                 'label' => 'Tipo',
  136.                 'placeholder' => '-- Selecione --',
  137.                 'choices' => TipoSuporteEnum::getAssociatedValues(),
  138.             ])
  139.             ;
  140.         }
  141.         $formMapper
  142.             ->add('modulo'ChoiceType::class, [
  143.                 'label' => 'Módulo',
  144.                 'placeholder' => '-- Selecione --',
  145.                 'choices' => ModulosSistemaEnum::getAssociatedValues(),
  146.             ])
  147.             ->add('titulo')
  148.             ->add('descricao'null, ['label'=>"Descrição"'required'=>true'attr'=>['class'=>'editorHtml']])
  149.             //->add('descricao', null, ['attr'=>['style'=>"height:400px;"]])
  150.             ->add('dataEntrega'DatePickerType::class,['label'=>'Previsão de entrega''required'=>false])
  151.             ->add('horas')
  152.             ->add('obsResolucao');
  153.             if ($this->isGranted('ROLE_SUPER_ADMIN')) {
  154.                 $formMapper->add('status'ChoiceType::class, [
  155.                     'label' => 'Status',
  156.                     'placeholder' => '-- Selecione --',
  157.                     'choices' => StatusSuporteEnum::getAssociatedValues(),
  158.                 ])
  159.                 ;
  160.             }
  161.     }
  162.     protected function configureShowFields(ShowMapper $showMapper): void
  163.     {
  164.         $showMapper
  165.             ->add('id')
  166.             ->add('modulo')
  167.             ->add('titulo')
  168.             ->add('descricao')
  169.             ->add('status')
  170.             ->add('createdAt')
  171.             ->add('dataEntrega')
  172.             ->add('horas')
  173.             ->add('resolvidoEm')
  174.             ->add('obsResolucao')
  175.             ;
  176.     }
  177. }