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