Skip to content

Instantly share code, notes, and snippets.

@adrianalonso
Created February 6, 2019 19:23
Show Gist options
  • Save adrianalonso/74a8b4e9ee6e74b5a1b49b5f10aad7b4 to your computer and use it in GitHub Desktop.
Save adrianalonso/74a8b4e9ee6e74b5a1b49b5f10aad7b4 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\Form\Type\SearchFilters;
use AppBundle\Entity\Category;
use AppBundle\Entity\Product;
use AppBundle\Entity\Specialty;
use AppBundle\Entity\SubCategory;
use AppBundle\Entity\User;
use AppBundle\Entity\Venue;
use AppBundle\Form\Type\DateRangeType;
use AppBundle\Repository\VenueRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use AppBundle\Entity\Country;
/**
* Class EventFiltersType
* @package AppBundle\Form\Type
*/
class EventAdminFiltersType extends AbstractType
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('specialty', EntityType::class, array(
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'class' => Specialty::class,
'attr' => array(
'class' => 'form-control',
'data-widget' => 'select2'
)
))
->add('area', EntityType::class, array(
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'class' => SubCategory::class
))
->add('category', ChoiceType::class, array(
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'choices' => array(
Category::ADMISSIONS_TEST => Category::ADMISSIONS_TEST,
Category::CONFERENCES_MASTER_CLASS => Category::CONFERENCES_MASTER_CLASS,
Category::INFORMATIVE_SESSIONS => Category::INFORMATIVE_SESSIONS
)
))
->add('query', TextType::class, array(
'required' => false,
'attr' => array(
'class' => 'form-control',
)
))
->add('date', DateRangeType::class, array(
'required' => false
))
->add('country', EntityType::class, array(
'class' => Country::class,
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'multiple'=>true,
'attr' => array(
'class' => 'form-control',
)
))
->add('city', ChoiceType::class, array(
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'choices' => $this->entityManager->getRepository(Venue::class)->findCities(),
))
->add('product', ChoiceType::class, array(
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'choices' => $this->entityManager->getRepository(Product::class)->findFilterProducts(),
))
->add('status', ChoiceType::class, array(
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'choices' => array(
'Draft' => 'draft',
'Canceled' => 'canceled',
'Live' => 'live',
'Started' => 'started',
'Ended' => 'ended',
'Completed' => 'completed',
),
))
->add('user', EntityType::class, array(
'class' => User::class,
'placeholder' => 'show-all-placeholder.fem',
'required' => false,
'attr' => array(
'class' => 'form-control',
)
))
->setMethod('GET');
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
'csrf_protection' => false,
'category' => false
)
);
}
public function getBlockPrefix()
{
return 'filters';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment