diff --git a/Controller/EventController.php b/Controller/EventController.php index 0cccb2f83..6fd94d173 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -4,9 +4,13 @@ namespace Chill\EventBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - +use Chill\PersonBundle\Form\Type\PickPersonType; use Chill\EventBundle\Entity\Event; use Chill\EventBundle\Form\EventType; +use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; /** * Event controller. @@ -103,11 +107,52 @@ class EventController extends Controller $this->denyAccessUnlessGranted('CHILL_EVENT_SEE_DETAILS', $entity, "You are not allowed to see details on this event"); + + $addParticipationByPersonForm = $this->createAddParticipationByPersonForm($entity); return $this->render('ChillEventBundle:Event:show.html.twig', array( - 'event' => $entity + 'event' => $entity, + 'form_add_participation_by_person' => $addParticipationByPersonForm->createView() )); } + + /** + * create a form to add a participation with a person + * + * @return \Symfony\Component\Form\FormInterface + */ + protected function createAddParticipationByPersonForm(Event $event) + { + /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ + $builder = $this + ->get('form.factory') + ->createNamedBuilder( + null, + FormType::class, + null, + array( + 'method' => 'GET', + 'action' => $this->generateUrl('chill_event_participation_new'), + 'csrf_protection' => false + )) + ; + + $builder->add('person_id', PickPersonType::class, array( + 'role' => new Role('CHILL_EVENT_CREATE'), + 'centers' => $event->getCenter() + )); + + $builder->add('center_id', HiddenType::class, array( + 'data' => $event->getCenter()->getId() + )); + + $builder->add('submit', SubmitType::class, + array( + 'label' => 'Add a participation' + )); + + return $builder->getForm(); + } /** * Displays a form to edit an existing Event entity. diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 0f58caa77..c8be2882e 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -13,3 +13,7 @@ chill_event_admin_role: chill_event_admin_event_type: resource: "@ChillEventBundle/Resources/config/routing/eventtype.yml" prefix: /{_locale}/admin/event/event_type + +chill_event_participation: + resource: "@ChillEventBundle/Resources/config/routing/participation.yml" + prefix: /{_locale}/event/participation diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml new file mode 100644 index 000000000..d89dd3b9c --- /dev/null +++ b/Resources/config/routing/participation.yml @@ -0,0 +1,3 @@ +chill_event_participation_new: + path: /new + defaults: { _controller: ChillEventBundle:Participation:new } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 90a759f7c..7c558341a 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -14,6 +14,7 @@ Last update: Dernière mise à jour Details of an event: Détails d'un événement Edit all the participations: Modifier toutes les participations +Add a participation: Ajouter un participant #search Event search: Recherche d'événements diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 1a500381a..d5e02aa96 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -36,7 +36,7 @@ -
{% transchoice count %}%count% participations to this event{% endtranschoice %}
@@ -74,6 +74,12 @@