add a first step to pick center in new event form

This commit is contained in:
2019-01-28 17:51:51 +01:00
parent 6d2ea8caab
commit fda14a52e0
5 changed files with 105 additions and 6 deletions

View File

@@ -16,6 +16,10 @@ 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;
use Chill\EventBundle\Form\Type\PickCenterType;
use Chill\MainBundle\Entity\Center;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormFactoryInterface;
/**
@@ -34,15 +38,25 @@ class EventController extends Controller
*/
protected $authorizationHelper;
/**
* @var FormFactoryInterface
*/
protected $formFactoryInterface;
/**
* EventController constructor.
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(EventDispatcherInterface $eventDispatcher, AuthorizationHelper $authorizationHelper)
public function __construct(
EventDispatcherInterface $eventDispatcher,
AuthorizationHelper $authorizationHelper,
FormFactoryInterface $formFactoryInterface
)
{
$this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper;
$this->formFactoryInterface = $formFactoryInterface;
}
@@ -98,14 +112,63 @@ class EventController extends Controller
return $form;
}
/**
* First step of new Event form
*/
public function newPickCenterAction()
{
$role = new Role('CHILL_EVENT_CREATE');
/** @var Center $centers */
$centers = $this->authorizationHelper->getReachableCenters($this->getUser(), $role);
$form = $this->formFactoryInterface
->createNamedBuilder(null)
->setMethod('GET')
->setAction(
$this->generateUrl('chill_event__event_new'))
->add('center_id', EntityType::class, array(
'class' => Center::class,
'choices' => $centers,
'placeholder' => '',
'label' => 'To which centre should the event be associated ?'
))
->add('submit', SubmitType::class, array(
'label' => 'Next step'
))
->getForm();
if (count($centers) === 1)
{
return $this->redirectToRoute('chill_event__event_new', array(
'center_id' => $centers[0]->getId()
));
}
return $this->render('ChillEventBundle:Event:newPickCenter.html.twig', array(
'form' => $form->createView()
));
}
/**
* Displays a form to create a new Event entity.
*
* @param Center $center
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function newAction()
public function newAction(Center $center = null, Request $request)
{
if ($center === null)
{
$center_id = $request->query->get('center_id');
$center = $this->getDoctrine()->getRepository(Center::class)->find($center_id);
}
$entity = new Event();
$entity->setCenter($center);
$form = $this->createCreateForm($entity);
return $this->render('ChillEventBundle:Event:new.html.twig', array(