<?php
namespace App\Form\Comun;
use App\Entity\Comun\Fichaje;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
class FichajeProyectoTareaType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options): void {
$builder
->add('tarea', EntityType::class, [
'class' => \App\Entity\Comun\Tarea::class,
'query_builder' => function (EntityRepository $er) use ($options) {
return $er->createQueryBuilder('t')
->innerJoin('t.tareaEmpleadas', 'te', \Doctrine\ORM\Query\Expr\Join::ON)
->andWhere('te.empleada =:empleada')
->andWhere('t.tareas IS EMPTY')
->andWhere('t.proyecto =:proyecto')
->setParameter('empleada', $options['empleada'])
->setParameter('proyecto', $options['proyecto']);
},
'label' => 'fichaje.tarea',
'required' => true,
'attr' => ['class' => 'form-control select2-blank',
'data-toggle' => '',
'placeholder' => 'fichaje.placeholderTarea'
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void {
$resolver->setDefaults([
'data_class' => Fichaje::class,
'proyecto' => null,
'empleada' => null,
]);
}
}