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

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