src/Application/Internit/LeadBundle/Admin/ProductAdmin.php line 80

Open in your IDE?
  1. <?php
  2. namespace App\Application\Internit\LeadBundle\Admin;
  3. use Sonata\AdminBundle\Route\RouteCollection;
  4. use Sonata\AdminBundle\Admin\AbstractAdmin;
  5. use Sonata\AdminBundle\Datagrid\ListMapper;
  6. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Symfony\Component\Form\FormEvent;
  9. use Symfony\Component\Form\FormEvents;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  14. use Doctrine\ORM\EntityRepository;
  15. use App\Application\Sonata\UserBundle\Entity\User;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  18. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  19. use App\Application\Internit\LeadBundle\Form\realStatePercentCollectionType;
  20. use App\Application\Internit\LeadBundle\Entity\Product;
  21. class ProductAdmin extends AbstractAdmin
  22. {
  23.     private $group_id 9;
  24.     private $corretoresList = [];
  25.     protected function configureListFields(ListMapper $listMapper)
  26.     {
  27.       $listMapper
  28.       ->add('_action'null, [
  29.           'actions' => [
  30.               'show' => [],
  31.               'edit' => [],
  32.               'delete' => false,
  33.           ]
  34.       ])
  35.       ;
  36.     }
  37.     protected function configureDatagridFilters(DatagridMapper $datagridMapper)
  38.     {
  39.         $datagridMapper->add('name');
  40.     }
  41.     protected function configureRoutes(RouteCollection $collection)
  42.     {
  43.       $collection->add('exportFiltered');
  44.       $collection->add('saveExtraLeads');
  45.       $collection->add('exportLog');
  46.       $collection->add('exportLogSended');
  47.     }
  48.     protected function configureFormFields(FormMapper $formMapper)
  49.     {
  50.       $this->createCorretorList();
  51.       
  52.       parent::configureFormFields($formMapper, array('allow_extra_fields' => true));
  53.       $formMapper
  54.         ->add('name'TextType::class, array(
  55.           'label' => 'Nome do Projeto:',
  56.           'required' => true,
  57.           'attr' => ['class' => 'input--style-4']
  58.         ));
  59.         $formMapper
  60.             ->add('description'TextareaType::class, array(
  61.               'label' => 'Observação:',
  62.               'required' => false,
  63.               'attr' => ['class' => 'project-obs input--style-4'],
  64.             ))
  65.             ->add('productUsers',EntityType::class,[
  66.               'class'         => 'App\Application\Sonata\UserBundle\Entity\User',
  67.               'label'         => false,
  68.               'multiple'      => true,
  69.               'attr'          => ['class' => 'broker-select'],
  70.               'required'      => false,
  71.               'sortable'      => false,
  72.               'choices'       => $this->corretoresList,
  73.               'choice_label'  => function ($id$corretorName$index) {
  74.                 return $corretorName;
  75.               },
  76.               'choice_value'  => function ($id) {
  77.                 return $id;
  78.               },
  79.             ])
  80.             ->add('fidelityDays'IntegerType::class, array(
  81.                 'label' => 'Dias de fidelidade:',
  82.                 'required' => false,
  83.                 'attr' => ['class' => 'input--style-4'],
  84.             ))
  85.             ->add('vivaReal'TextType::class, array(
  86.                 'label' => 'ID Viva Real:',
  87.                 'required' => false,
  88.                 'attr' => [ 'class' => 'input--style-4' ],
  89.             ))
  90.             ->add('zap'TextType::class, array(
  91.                 'label' => 'ID Zap:',
  92.                 'required' => false,
  93.                 'attr' => [ 'class' => 'input--style-4' ],
  94.             ))
  95.             ->add('olx'TextType::class, array(
  96.                 'label' => 'ID Olx:',
  97.                 'required' => false,
  98.                 'attr' => [ 'class' => 'input--style-4' ],
  99.             ))
  100.             ->add('realStatePercents'CollectionType::class, [
  101.               'by_reference' => false// Use this because of reasons
  102.               'label' => false,
  103.               'allow_add' => true// True if you want allow adding new entries to the collection
  104.               'allow_delete' => true// True if you want to allow deleting entries
  105.               'prototype' => true// True if you want to use a custom form type
  106.               'required' => false,
  107.               'entry_type' => realStatePercentCollectionType::class,
  108.               'attr' => ['class' => 'range'],
  109.               'entry_options' => ['label' => false'attr' => ['class' => 'zk']]
  110.             ])
  111.             ->add('email'TextareaType::class, [
  112.               'label' => 'E-mail para recebimento dos leads: Separe por [ , ] virgula.',
  113.               'required' => false,
  114.               'attr' => ['class' => 'input--style-4',]
  115.             ])
  116.       //   ->add('realStatePercent', CollectionType::class, [
  117.       //     // Prevents the "Delete" option from being displayed
  118.       //     'type_options' => ['delete' => false]
  119.       // ], [
  120.       //     'edit' => 'inline',
  121.       //     'inline' => 'table',
  122.       //     'sortable' => 'position',
  123.       // ]);
  124.         // ->add('realStatePercent')
  125.         ;
  126.       
  127.     }
  128.     private function createCorretorList()
  129.     {
  130.       $corretores $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository('ApplicationSonataUserBundle:User')->listCorretor();
  131.       foreach ($corretores as $corretor) {
  132.         $this->corretoresList[$corretor['name']][$corretor['firstname']] = $corretor['imobId'].':'.$corretor['id'];
  133.       }
  134.     }
  135. }