src/Form/AbscenceSheetType.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\AbscenceSheet;
  4. use App\Entity\ClassRoom;
  5. use App\Entity\Sequence;
  6. use App\Repository\SequenceRepository;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\Extension\Core\Type\DateType;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. class AbscenceSheetType extends AbstractType
  14. {
  15.     private $repo;
  16.     public function __construct(SequenceRepository $scRepo)
  17.     {
  18.         $this->repo $scRepo;
  19.     }
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void
  21.     {
  22.         $builder
  23.             ->add('sequence'EntityType::class, array('class' => Sequence::class, 'data' => $options['activated_sequence'], 'placeholder' => 'Choisir la séquence''required' => true'query_builder' => function (SequenceRepository $repository) {
  24.                 return $repository->createQueryBuilder('s')->leftJoin('s.quater''q')->leftJoin('q.schoolYear''sc')->where('sc.activated = :rep')->setParameter('rep'true)->add('orderBy''s.id');
  25.             }))
  26.             ->add('classRoom'EntityType::class, array('placeholder' => 'Choisir une classe''class' => ClassRoom::class, 'required' => true))
  27.             ->add('startDate'DateType::class, [
  28.                 'label' => 'Date de début',
  29.                 'widget' => 'single_text',
  30.                 'required' => true,
  31.                 'input' => 'datetime',
  32.                 'html5' => true,
  33.                 'attr' => ['class' => 'js-datepicker'],
  34.                 'format' => 'yyyy-MM-dd',
  35.                 'constraints' => new Assert\Date(),
  36.                 'constraints' => new Assert\NotBlank(),
  37.                 'trim' => true
  38.             ])
  39.             ->add('endDate'DateType::class, [
  40.                 'label' => 'Date de fin',
  41.                 'widget' => 'single_text',
  42.                 'required' => true,
  43.                 'input' => 'datetime',
  44.                 'html5' => true,
  45.                 'attr' => ['class' => 'js-datepicker'],
  46.                 'format' => 'yyyy-MM-dd',
  47.                 'constraints' => new Assert\Date(),
  48.                 'constraints' => new Assert\NotBlank(),
  49.                 'trim' => true
  50.             ]);
  51.     }
  52.     public function configureOptions(OptionsResolver $resolver): void
  53.     {
  54.         $resolver->setDefaults([
  55.             'data_class' => AbscenceSheet::class,
  56.             'activated_sequence' => $this->repo->findOneBy(array("activated" => true)),
  57.         ]);
  58.     }
  59. }