mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
factorize PickRoleType, PickStatusType and rename TranslatableEventType
This commit is contained in:
@@ -26,8 +26,9 @@ use Chill\EventBundle\Entity\EventType;
|
||||
use Chill\EventBundle\Entity\Status;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Chill\EventBundle\Entity\Role;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\EventBundle\Form\Type\PickRoleType;
|
||||
use Chill\EventBundle\Form\Type\PickStatusType;
|
||||
|
||||
/**
|
||||
* A type to create a participation
|
||||
@@ -55,55 +56,13 @@ class ParticipationType extends AbstractType
|
||||
$translatableStringHelper = $this->translatableStringHelper;
|
||||
|
||||
// add role
|
||||
$builder->add('role', EntityType::class, array(
|
||||
'class' => Role::class,
|
||||
'query_builder' => function (EntityRepository $er) use ($options) {
|
||||
$qb = $er->createQueryBuilder('r');
|
||||
|
||||
if ($options['event_type'] instanceof EventType) {
|
||||
$qb->where($qb->expr()->eq('r.type', ':event_type'))
|
||||
->setParameter('event_type', $options['event_type']);
|
||||
}
|
||||
|
||||
$qb->andWhere($qb->expr()->eq('r.active', ':active'))
|
||||
->setParameter('active', true);
|
||||
|
||||
return $qb;
|
||||
},
|
||||
'choice_attr' => function(Role $r) {
|
||||
return array(
|
||||
'data-event-type' => $r->getType()->getId()
|
||||
);
|
||||
},
|
||||
'choice_label' => function(Role $r) use ($translatableStringHelper) {
|
||||
return $translatableStringHelper->localize($r->getName());
|
||||
}
|
||||
));
|
||||
$builder->add('role', PickRoleType::class, array(
|
||||
'event_type' => $options['event_type']
|
||||
));
|
||||
|
||||
// add a status
|
||||
$builder->add('status', EntityType::class, array(
|
||||
'class' => Status::class,
|
||||
'choice_attr' => function(Status $s) {
|
||||
return array(
|
||||
'data-event-type' => $s->getType()->getId()
|
||||
);
|
||||
},
|
||||
'query_builder' => function (EntityRepository $er) use ($options) {
|
||||
$qb = $er->createQueryBuilder('s');
|
||||
|
||||
if ($options['event_type'] instanceof EventType) {
|
||||
$qb->where($qb->expr()->eq('s.type', ':event_type'))
|
||||
->setParameter('event_type', $options['event_type']);
|
||||
}
|
||||
|
||||
$qb->andWhere($qb->expr()->eq('s.active', ':active'))
|
||||
->setParameter('active', true);
|
||||
|
||||
return $qb;
|
||||
},
|
||||
'choice_label' => function(Status $s) use ($translatableStringHelper) {
|
||||
return $translatableStringHelper->localize($s->getName());
|
||||
}
|
||||
$builder->add('status', PickStatusType::class, array(
|
||||
'event_type' => $options['event_type']
|
||||
));
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user