<?php
namespace App\Application\Internit\LeadBundle\Admin;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use App\Application\Sonata\UserBundle\Entity\User;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use App\Application\Internit\LeadBundle\Form\realStatePercentCollectionType;
use App\Application\Internit\LeadBundle\Entity\Product;
class ProductAdmin extends AbstractAdmin
{
private $group_id = 9;
private $corretoresList = [];
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('_action', null, [
'actions' => [
'show' => [],
'edit' => [],
'delete' => false,
]
])
;
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('name');
}
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('exportFiltered');
$collection->add('saveExtraLeads');
}
protected function configureFormFields(FormMapper $formMapper)
{
$this->createCorretorList();
parent::configureFormFields($formMapper, array('allow_extra_fields' => true));
$formMapper
->add('name', TextType::class, array(
'label' => 'Nome do Projeto:',
'required' => true,
'attr' => ['class' => 'input--style-4']
));
$formMapper
->add('description', TextareaType::class, array(
'label' => 'Observação:',
'required' => false,
'attr' => ['class' => 'project-obs input--style-4'],
))
->add('productUsers',EntityType::class,[
'class' => 'App\Application\Sonata\UserBundle\Entity\User',
'label' => false,
'multiple' => true,
'attr' => ['class' => 'broker-select'],
'required' => false,
'sortable' => false,
'choices' => $this->corretoresList,
'choice_label' => function ($id, $corretorName, $index) {
return $corretorName;
},
'choice_value' => function ($id) {
return $id;
},
])
->add('vivaReal', TextType::class, array(
'label' => 'ID Viva Real:',
'required' => false,
'attr' => [ 'class' => 'input--style-4' ],
))
->add('zap', TextType::class, array(
'label' => 'ID Zap:',
'required' => false,
'attr' => [ 'class' => 'input--style-4' ],
))
->add('olx', TextType::class, array(
'label' => 'ID Olx:',
'required' => false,
'attr' => [ 'class' => 'input--style-4' ],
))
->add('realStatePercents', CollectionType::class, [
'by_reference' => false, // Use this because of reasons
'label' => false,
'allow_add' => true, // True if you want allow adding new entries to the collection
'allow_delete' => true, // True if you want to allow deleting entries
'prototype' => true, // True if you want to use a custom form type
'required' => false,
'entry_type' => realStatePercentCollectionType::class,
'attr' => ['class' => 'range'],
'entry_options' => ['label' => false, 'attr' => ['class' => 'zk']]
])
->add('email', TextareaType::class, [
'label' => 'E-mail para recebimento dos leads: Separe por [ , ] virgula.',
'required' => false,
'attr' => ['class' => 'input--style-4',]
])
// ->add('realStatePercent', CollectionType::class, [
// // Prevents the "Delete" option from being displayed
// 'type_options' => ['delete' => false]
// ], [
// 'edit' => 'inline',
// 'inline' => 'table',
// 'sortable' => 'position',
// ]);
// ->add('realStatePercent')
;
}
private function createCorretorList()
{
$corretores = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository('ApplicationSonataUserBundle:User')->listCorretor();
foreach ($corretores as $corretor) {
$this->corretoresList[$corretor['name']][$corretor['firstname']] = $corretor['imobId'].':'.$corretor['id'];
}
}
}