src/Form/ProjectSearchType.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  9. use Doctrine\ORM\EntityRepository;
  10. use App\Entity\Project;
  11. use App\Entity\College;
  12. use App\Entity\Category;
  13. /**
  14.  *
  15.  * @author wendell.zheng <wxzheng@ustc.edu.cn>
  16.  */
  17. class ProjectSearchType extends AbstractType
  18. {
  19.     public function buildForm(FormBuilderInterface $builder, array $options)
  20.     {
  21.         $builder->add('college'EntityType::class, [
  22.             'label' => '学院',
  23.             'class' => College::class,
  24.             'choice_label' => 'name',
  25.             'choice_value' => 'name',
  26.             'required' => false
  27.         ])
  28.             ->add('category'EntityType::class, [
  29.             'label' => '类别',
  30.             'class' => Category::class,
  31.             'choice_label' => 'name',
  32.             'choice_value' => 'name',
  33.             'query_builder' => function (EntityRepository $er) use ($options) {
  34.                 return $er->queryByBatch($options['batch']);
  35.             },
  36.             'required' => false
  37.         ])
  38.             ->add('status'ChoiceType::class, [
  39.             'label' => '状态',
  40.             'choices' => array_combine(Project::STATUSESProject::STATUSES),
  41.             'required' => false
  42.         ])
  43.             ->add('export'SubmitType::class, [
  44.             'label' => '导出汇总表'
  45.         ])
  46.             ->add('search'SubmitType::class, [
  47.             'label' => '搜索'
  48.         ]);
  49.     }
  50.     public function configureOptions(OptionsResolver $resolver)
  51.     {
  52.         $resolver->setDefaults([
  53.             'batch' => null,
  54.             'csrf_protection' => false
  55.         ]);
  56.     }
  57. }