subscribe a person since listByPerson context (issue #19)

This commit is contained in:
2019-05-02 11:35:15 +02:00
parent aa9141be1d
commit ee8f303d25
11 changed files with 478 additions and 11 deletions

View File

@@ -23,8 +23,10 @@
namespace Chill\EventBundle\Controller;
use Chill\EventBundle\Entity\Participation;
use Chill\EventBundle\Form\Type\PickSubscriptionType;
use Chill\EventBundle\Security\Authorization\EventVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -343,6 +345,7 @@ class EventController extends Controller
*/
public function listByPersonAction($person_id)
{
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
@@ -393,17 +396,59 @@ class EventController extends Controller
->getResult()
;
$privacyEvent = new PrivacyEvent($person, array(
'element_class' => Participation::class,
'action' => 'list'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $privacyEvent);
$addParticipationByEventForm = $this->createAddParticipationByEventForm($person);
return $this->render('ChillEventBundle:Event:listByPerson.html.twig', array(
'participations' => $participations,
'person' => $person,
'paginator' => $paginator
'paginator' => $paginator,
'form_add_participation_by_event' => $addParticipationByEventForm->createView()
));
}
/**
* create a form to add a participation with an event
*
* @param Person $person
* @return \Symfony\Component\Form\FormInterface
*/
protected function createAddParticipationByEventForm(Person $person)
{
/* @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('event_id', PickSubscriptionType::class, array(
'role' => new Role('CHILL_EVENT_CREATE'),
'centers' => $person->getCenter()
));
$builder->add('person_id', HiddenType::class, array(
'data' => $person->getId()
));
$builder->add('submit', SubmitType::class,
array(
'label' => 'Subscribe an event'
));
return $builder->getForm();
}
}