mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
fix folder name
This commit is contained in:
48
src/Bundle/ChillEventBundle/Controller/AdminController.php
Normal file
48
src/Bundle/ChillEventBundle/Controller/AdminController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 Champs Libres <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
/**
|
||||
* Class AdminController
|
||||
* Controller for the event configuration section (in admin section)
|
||||
*
|
||||
* @package Chill\EventBundle\Controller
|
||||
*/
|
||||
class AdminController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
return $this->render('ChillEventBundle:Admin:layout.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function redirectToAdminIndexAction()
|
||||
{
|
||||
return $this->redirectToRoute('chill_main_admin_central');
|
||||
}
|
||||
}
|
678
src/Bundle/ChillEventBundle/Controller/EventController.php
Normal file
678
src/Bundle/ChillEventBundle/Controller/EventController.php
Normal file
@@ -0,0 +1,678 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Chill\EventBundle\Entity\Participation;
|
||||
use Chill\EventBundle\Form\Type\PickEventType;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Ods;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
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;
|
||||
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;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
|
||||
/**
|
||||
* Class EventController
|
||||
*
|
||||
* @package Chill\EventBundle\Controller
|
||||
*/
|
||||
class EventController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var FormFactoryInterface
|
||||
*/
|
||||
protected $formFactoryInterface;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var PaginatorFactory
|
||||
*/
|
||||
protected $paginator;
|
||||
|
||||
/**
|
||||
* EventController constructor.
|
||||
*
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param AuthorizationHelper $authorizationHelper
|
||||
* @param FormFactoryInterface $formFactoryInterface
|
||||
* @param TranslatorInterface $translator
|
||||
* @param PaginatorFactory $paginator
|
||||
*/
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
FormFactoryInterface $formFactoryInterface,
|
||||
TranslatorInterface $translator,
|
||||
PaginatorFactory $paginator
|
||||
)
|
||||
{
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->formFactoryInterface = $formFactoryInterface;
|
||||
$this->translator = $translator;
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
|
||||
public function mostRecentIndexAction()
|
||||
{
|
||||
return $this->redirectToRoute('chill_main_search', array(
|
||||
'q' => '@event'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
if (count($centers) === 1)
|
||||
{
|
||||
return $this->redirectToRoute('chill_event__event_new', array(
|
||||
'center_id' => $centers[0]->getId()
|
||||
));
|
||||
}
|
||||
|
||||
$form = $this->formFactoryInterface
|
||||
->createNamedBuilder(null, FormType::class, null, array(
|
||||
'csrf_protection' => false
|
||||
))
|
||||
->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();
|
||||
|
||||
return $this->render('ChillEventBundle:Event:newPickCenter.html.twig', array(
|
||||
'form' => $form->createView()
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to create a Event entity.
|
||||
*
|
||||
* @param Event $entity The entity
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createCreateForm(Event $entity)
|
||||
{
|
||||
$form = $this->createForm(EventType::class, $entity, array(
|
||||
'method' => 'POST',
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => new Role('CHILL_EVENT_CREATE')
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Create'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to create a new Event entity.
|
||||
* @param Center $center
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
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);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid())
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans('The event was created'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event__event_show', array('event_id' => $entity->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Event:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a Event entity.
|
||||
*
|
||||
* @ParamConverter("event", options={"id" = "event_id"})
|
||||
* @param Event $event
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
*/
|
||||
public function showAction(Event $event, Request $request)
|
||||
{
|
||||
if (!$event) {
|
||||
throw $this->createNotFoundException('Unable to find Event entity.');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE_DETAILS', $event,
|
||||
"You are not allowed to see details on this event");
|
||||
|
||||
$addParticipationByPersonForm = $this->createAddParticipationByPersonForm($event);
|
||||
|
||||
$exportParticipationsList = $this->exportParticipationsList($event, $request);
|
||||
|
||||
if ($exportParticipationsList['response']) {
|
||||
return $exportParticipationsList['response'];
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Event:show.html.twig', array(
|
||||
'event' => $event,
|
||||
'form_add_participation_by_person' => $addParticipationByPersonForm->createView(),
|
||||
'form_export' => $exportParticipationsList['form']->createView()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* create a form to add a participation with a person
|
||||
*
|
||||
* @param Event $event
|
||||
* @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('event_id', HiddenType::class, array(
|
||||
'data' => $event->getId()
|
||||
));
|
||||
|
||||
$builder->add('submit', SubmitType::class,
|
||||
array(
|
||||
'label' => 'Add a participation'
|
||||
));
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing Event entity.
|
||||
*
|
||||
* @param $event_id
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function editAction($event_id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Event')->find($event_id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Event entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entity);
|
||||
|
||||
return $this->render('ChillEventBundle:Event:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to edit a Event entity.
|
||||
*
|
||||
* @param Event $entity
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createEditForm(Event $entity)
|
||||
{
|
||||
$form = $this->createForm(EventType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_event__event_update', array('event_id' => $entity->getId())),
|
||||
'method' => 'PUT',
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => new Role('CHILL_EVENT_CREATE')
|
||||
));
|
||||
|
||||
$form->remove('center');
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Update'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits an existing Event entity.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $event_id
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function updateAction(Request $request, $event_id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Event')->find($event_id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Event entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isValid()) {
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans('The event was updated'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event__event_edit', array('event_id' => $event_id)));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Event:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* List events subscriptions for a person
|
||||
*
|
||||
* @param $person_id
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function listByPersonAction($person_id)
|
||||
{
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
|
||||
if ($person === NULL) {
|
||||
throw $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$reachablesCircles = $this->authorizationHelper->getReachableCircles(
|
||||
$this->getUser(),
|
||||
new Role(EventVoter::SEE),
|
||||
$person->getCenter()
|
||||
);
|
||||
|
||||
$total = $em->getRepository('ChillEventBundle:Participation')->countByPerson($person_id);
|
||||
|
||||
$paginator = $this->paginator->create($total);
|
||||
|
||||
$participations = $em->getRepository('ChillEventBundle:Participation')->findByPersonInCircle(
|
||||
$person_id,
|
||||
$reachablesCircles,
|
||||
$paginator->getCurrentPage()->getFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
);
|
||||
|
||||
$privacyEvent = new PrivacyEvent($person, array(
|
||||
'element_class' => Participation::class,
|
||||
'action' => 'list'
|
||||
));
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $privacyEvent);
|
||||
|
||||
$addEventParticipationByPersonForm = $this->createAddEventParticipationByPersonForm($person);
|
||||
|
||||
return $this->render('ChillEventBundle:Event:listByPerson.html.twig', array(
|
||||
'participations' => $participations,
|
||||
'person' => $person,
|
||||
'paginator' => $paginator,
|
||||
'form_add_event_participation_by_person' => $addEventParticipationByPersonForm->createView()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* create a form to add a participation with an event
|
||||
*
|
||||
* @param Person $person
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function createAddEventParticipationByPersonForm(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', PickEventType::class, array(
|
||||
'role' => new Role('CHILL_EVENT_CREATE'),
|
||||
'centers' => $person->getCenter()
|
||||
));
|
||||
|
||||
$builder->add('person_id', HiddenType::class, array(
|
||||
'data' => $person->getId()
|
||||
));
|
||||
|
||||
$builder->add('return_path', HiddenType::class, array(
|
||||
'data' => $this->generateUrl('chill_event__list_by_person', array(
|
||||
'person_id' => $person->getId()
|
||||
))
|
||||
));
|
||||
|
||||
|
||||
$builder->add('submit', SubmitType::class,
|
||||
array(
|
||||
'label' => 'Subscribe an event'
|
||||
));
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Event $event
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
*/
|
||||
protected function exportParticipationsList(Event $event, Request $request)
|
||||
{
|
||||
$form = $this->createExportByFormatForm();
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid())
|
||||
{
|
||||
$data = $form->getData();
|
||||
$format = $data['format'];
|
||||
$filename = 'export_event'. $event->getId() .'_participations.' .$format;
|
||||
|
||||
$spreadsheet = $this->createExportSpreadsheet($event);
|
||||
|
||||
switch ($format) {
|
||||
case 'ods':
|
||||
$contentType = 'application/vnd.oasis.opendocument.spreadsheet';
|
||||
$writer = new Ods($spreadsheet);
|
||||
break;
|
||||
case 'xlsx':
|
||||
$contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
break;
|
||||
case 'csv':
|
||||
$contentType = 'text/csv';
|
||||
$writer = new Csv($spreadsheet);
|
||||
break;
|
||||
default:
|
||||
return [ 'form' => $form, 'response' => null ];
|
||||
}
|
||||
|
||||
$response = new StreamedResponse();
|
||||
$response->headers->set('Content-Type', $contentType);
|
||||
$response->headers->set('Content-Disposition', 'attachment;filename="'.$filename.'"');
|
||||
$response->setPrivate();
|
||||
$response->headers->addCacheControlDirective('no-cache', true);
|
||||
$response->headers->addCacheControlDirective('must-revalidate', true);
|
||||
$response->setCallback(function() use ($writer) {
|
||||
$writer->save('php://output');
|
||||
});
|
||||
|
||||
return [ 'form' => $form, 'response' => $response ];
|
||||
}
|
||||
|
||||
return [ 'form' => $form, 'response' => null ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function createExportByFormatForm()
|
||||
{
|
||||
$builder = $this->createFormBuilder()
|
||||
->add('format', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'xlsx' => 'xlsx',
|
||||
'ods' => 'ods',
|
||||
'csv' => 'csv'
|
||||
],
|
||||
'label' => false,
|
||||
'placeholder' => 'Select a format'
|
||||
])
|
||||
->add('submit', SubmitType::class, [
|
||||
'label' => 'Export'
|
||||
]);
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event $event
|
||||
* @return Spreadsheet
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
*/
|
||||
protected function createExportSpreadsheet(Event $event)
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$trans = $this->translator->getLocale();
|
||||
|
||||
$headerValues = [
|
||||
'A1' => 'Event',
|
||||
'B1' => $event->getId(),
|
||||
'A2' => 'Date',
|
||||
'B2' => $event->getDate()->format('d-m-Y H:i'),
|
||||
'A3' => 'Name',
|
||||
'B3' => $event->getName(),
|
||||
'A4' => 'Type',
|
||||
'B4' => $event->getType()->getName()[$trans],
|
||||
'A5' => 'Circle',
|
||||
'B5' => $event->getCircle()->getName()[$trans],
|
||||
'A6' => 'Moderator',
|
||||
'B6' => $event->getModerator() ? $event->getModerator()->getUsernameCanonical() : null,
|
||||
];
|
||||
foreach ($headerValues as $k => $value) {
|
||||
$sheet->setCellValue($k, $value);
|
||||
}
|
||||
|
||||
$columnNames = [ 'id', 'firstname', 'lastname', 'role', 'status', 'email', 'phone', 'mobile' ];
|
||||
$columnLetter = 'A';
|
||||
foreach ($columnNames as $columnName) {
|
||||
$sheet->setCellValue($columnLetter.'8', $columnName);
|
||||
$columnLetter++;
|
||||
}
|
||||
|
||||
$columnValues = [];
|
||||
foreach ($event->getParticipations() as $participation)
|
||||
{
|
||||
/** @var Participation $participation */
|
||||
$columnValues[] = [
|
||||
$participation->getPerson()->getId(),
|
||||
$participation->getPerson()->getFirstname(),
|
||||
$participation->getPerson()->getLastname(),
|
||||
$participation->getRole()->getName()[$trans],
|
||||
$participation->getStatus()->getName()[$trans],
|
||||
$participation->getPerson()->getEmail(),
|
||||
$participation->getPerson()->getPhoneNumber(),
|
||||
$participation->getPerson()->getMobileNumber(),
|
||||
];
|
||||
}
|
||||
|
||||
$i = 9;
|
||||
foreach ($columnValues as $columnValue) {
|
||||
$columnLetter = 'A';
|
||||
foreach ($columnValue as $value) {
|
||||
$sheet->setCellValue($columnLetter.$i, $value);
|
||||
$columnLetter++;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $spreadsheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event_id
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function deleteAction($event_id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$event = $em->getRepository('ChillEventBundle:Event')->findOneBy([
|
||||
'id' => $event_id
|
||||
]);
|
||||
|
||||
if (! $event) {
|
||||
throw $this->createNotFoundException('Unable to find this event.');
|
||||
}
|
||||
|
||||
/** @var array $participations */
|
||||
$participations = $event->getParticipations();
|
||||
|
||||
$form = $this->createDeleteForm($event_id);
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
|
||||
foreach ($participations as $participation) {
|
||||
$em->remove($participation);
|
||||
}
|
||||
|
||||
$em->remove($event);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans("The event has been sucessfully removed")
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_main_search', [
|
||||
'name' => 'event_regular',
|
||||
'q' => '@event'
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->render('ChillEventBundle:Event:confirm_delete.html.twig', [
|
||||
'event_id' => $event->getId(),
|
||||
'delete_form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event_id
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createDeleteForm($event_id)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_event__event_delete', [
|
||||
'event_id' => $event_id
|
||||
]))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
230
src/Bundle/ChillEventBundle/Controller/EventTypeController.php
Normal file
230
src/Bundle/ChillEventBundle/Controller/EventTypeController.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Chill\EventBundle\Entity\EventType;
|
||||
use Chill\EventBundle\Form\EventTypeType;
|
||||
|
||||
/**
|
||||
* Class EventTypeController
|
||||
*
|
||||
* @package Chill\EventBundle\Controller
|
||||
*/
|
||||
class EventTypeController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* Lists all EventType entities.
|
||||
*
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entities = $em->getRepository('ChillEventBundle:EventType')->findAll();
|
||||
|
||||
return $this->render('ChillEventBundle:EventType:index.html.twig', array(
|
||||
'entities' => $entities,
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Creates a new EventType entity.
|
||||
*
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
$entity = new EventType();
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_eventtype_admin',
|
||||
array('id' => $entity->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:EventType:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to create a EventType entity.
|
||||
*
|
||||
* @param EventType $entity The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createCreateForm(EventType $entity)
|
||||
{
|
||||
$form = $this->createForm(EventTypeType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_eventtype_admin_create'),
|
||||
'method' => 'POST',
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Create'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to create a new EventType entity.
|
||||
*
|
||||
*/
|
||||
public function newAction()
|
||||
{
|
||||
$entity = new EventType();
|
||||
$form = $this->createCreateForm($entity);
|
||||
|
||||
return $this->render('ChillEventBundle:EventType:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a EventType entity.
|
||||
*
|
||||
*/
|
||||
public function showAction($id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:EventType')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find EventType entity.');
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
|
||||
return $this->render('ChillEventBundle:EventType:show.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing EventType entity.
|
||||
*
|
||||
*/
|
||||
public function editAction($id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:EventType')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find EventType entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
|
||||
return $this->render('ChillEventBundle:EventType:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to edit a EventType entity.
|
||||
*
|
||||
* @param EventType $entity The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createEditForm(EventType $entity)
|
||||
{
|
||||
$form = $this->createForm(EventTypeType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_eventtype_admin_update',
|
||||
array('id' => $entity->getId())),
|
||||
'method' => 'PUT',
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Update'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
/**
|
||||
* Edits an existing EventType entity.
|
||||
*
|
||||
*/
|
||||
public function updateAction(Request $request, $id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:EventType')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find EventType entity.');
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isValid()) {
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_eventtype_admin',
|
||||
array('id' => $id)));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:EventType:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Deletes a EventType entity.
|
||||
*
|
||||
*/
|
||||
public function deleteAction(Request $request, $id)
|
||||
{
|
||||
$form = $this->createDeleteForm($id);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$entity = $em->getRepository('ChillEventBundle:EventType')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find EventType entity.');
|
||||
}
|
||||
|
||||
$em->remove($entity);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_eventtype_admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a EventType entity by id.
|
||||
*
|
||||
* @param mixed $id The entity id
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm($id)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_eventtype_admin_delete',
|
||||
array('id' => $id)))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
}
|
@@ -0,0 +1,766 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use ArrayIterator;
|
||||
use Chill\EventBundle\Entity\Event;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Chill\EventBundle\Entity\Participation;
|
||||
use Chill\EventBundle\Form\ParticipationType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Chill\EventBundle\Security\Authorization\ParticipationVoter;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
|
||||
/**
|
||||
* Class ParticipationController
|
||||
*
|
||||
* @package Chill\EventBundle\Controller
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ParticipationController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* ParticipationController constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a form to add a participation
|
||||
*
|
||||
* This function parse the person_id / persons_ids query argument
|
||||
* and decide if it should process a single or multiple participation. Depending
|
||||
* on this, the appropriate layout and form.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function newAction(Request $request)
|
||||
{
|
||||
|
||||
// test the request is correct
|
||||
try {
|
||||
$this->testRequest($request);
|
||||
} catch (\RuntimeException $ex) {
|
||||
$this->logger->warning($ex->getMessage());
|
||||
|
||||
return (new Response())
|
||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||
->setContent($ex->getMessage());
|
||||
}
|
||||
|
||||
// forward to other action
|
||||
$single = $request->query->has('person_id');
|
||||
$multiple = $request->query->has('persons_ids');
|
||||
|
||||
if ($single === true) {
|
||||
return $this->newSingle($request);
|
||||
}
|
||||
|
||||
if ($multiple === true) {
|
||||
|
||||
return $this->newMultiple($request);
|
||||
}
|
||||
|
||||
// at this point, we miss the required fields. Throw an error
|
||||
return (new Response())
|
||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||
->setContent("You must provide either 'person_id' or "
|
||||
. "'persons_ids' argument in query");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Test that the query parameters are valid :
|
||||
*
|
||||
* - an `event_id` is existing ;
|
||||
* - `person_id` and `persons_ids` are **not** both present ;
|
||||
* - `persons_id` is correct (contains only numbers and a ','.
|
||||
*
|
||||
* @param Request $request
|
||||
* @throws \RuntimeException if an error is detected
|
||||
*/
|
||||
protected function testRequest(Request $request)
|
||||
{
|
||||
$single = $request->query->has('person_id');
|
||||
$multiple = $request->query->has('persons_ids');
|
||||
|
||||
if ($single === true AND $multiple === true) {
|
||||
// we are not allowed to have both person_id and persons_ids
|
||||
throw new \RuntimeException("You are not allow to provide both 'person_id' and "
|
||||
. "'persons_ids' simulaneously");
|
||||
}
|
||||
|
||||
if ($multiple === true) {
|
||||
$persons_ids = $request->query->get('persons_ids');
|
||||
|
||||
if (!preg_match('/^([0-9]{1,},{0,1}){1,}[0-9]{0,}$/', $persons_ids)) {
|
||||
throw new \RuntimeException("The persons_ids value should "
|
||||
. "contains int separated by ','");
|
||||
}
|
||||
}
|
||||
|
||||
// check for event_id - this could be removed later
|
||||
if ($request->query->has('event_id') === FALSE) {
|
||||
throw new \RuntimeException("You must provide an event_id");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a form with single participation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
protected function newSingle(Request $request)
|
||||
{
|
||||
|
||||
$returnPath = $request->query->get('return_path') ?
|
||||
$request->query->get('return_path') : null;
|
||||
|
||||
$participation = $this->handleRequest($request, new Participation(), false);
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||
$participation, 'The user is not allowed to create this participation');
|
||||
|
||||
$form = $this->createCreateForm($participation, $returnPath);
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation,
|
||||
'ignored_participations' => array() // this is required, see self::newMultiple
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a form with multiple participation.
|
||||
*
|
||||
* If a person is already participating on the event (if a participation with
|
||||
* the same person is associated with the event), the participation is ignored.
|
||||
*
|
||||
* If all but one participation is ignored, the page show the same response
|
||||
* than the newSingle function.
|
||||
*
|
||||
* If all participations must be ignored, an error is shown and the method redirects
|
||||
* to the event 'show' view with an appropriate flash message.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
protected function newMultiple(Request $request)
|
||||
{
|
||||
$participations = $this->handleRequest($request, new Participation(), true);
|
||||
|
||||
|
||||
foreach ($participations as $i => $participation) {
|
||||
// check for authorization
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||
$participation, 'The user is not allowed to create this participation');
|
||||
|
||||
// create a collection of person's id participating to the event
|
||||
/* @var $peopleParticipating \Doctrine\Common\Collections\ArrayCollection */
|
||||
$peopleParticipating = isset($peopleParticipating) ? $peopleParticipating :
|
||||
$participation->getEvent()->getParticipations()->map(
|
||||
function(Participation $p) { return $p->getPerson()->getId(); }
|
||||
);
|
||||
// check that the user is not already in the event
|
||||
if ($peopleParticipating->contains($participation->getPerson()->getId())) {
|
||||
$ignoredParticipations[] = $participation
|
||||
->getEvent()->getParticipations()->filter(
|
||||
function (Participation $p) use ($participation) {
|
||||
return $p->getPerson()->getId() === $participation->getPerson()->getId();
|
||||
}
|
||||
)->first();
|
||||
} else {
|
||||
$newParticipations[] = $participation;
|
||||
}
|
||||
}
|
||||
|
||||
// this is where the function redirect depending on valid participation
|
||||
|
||||
if (!isset($newParticipations)) {
|
||||
// if we do not have nay participants, redirect to event view
|
||||
$this->addFlash('error', $this->get('translator')->trans(
|
||||
'None of the requested people may participate '
|
||||
. 'the event: they are maybe already participating.'));
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_show', array(
|
||||
'event_id' => $request->query->getInt('event_id', 0)
|
||||
));
|
||||
} elseif (count($newParticipations) > 1) {
|
||||
// if we have multiple participations, show a form with multiple participations
|
||||
$form = $this->createCreateFormMultiple($newParticipations);
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:new-multiple.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participations' => $newParticipations,
|
||||
'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array()
|
||||
));
|
||||
} else {
|
||||
// if we have only one participation, show the same form than for single participation
|
||||
$form = $this->createCreateForm($participation);
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation,
|
||||
'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array()
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
// test the request is correct
|
||||
try {
|
||||
$this->testRequest($request);
|
||||
} catch (\RuntimeException $ex) {
|
||||
$this->logger->warning($ex->getMessage());
|
||||
|
||||
return (new Response())
|
||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||
->setContent($ex->getMessage());
|
||||
}
|
||||
|
||||
// forward to other action
|
||||
$single = $request->query->has('person_id');
|
||||
$multiple = $request->query->has('persons_ids');
|
||||
|
||||
if ($single === true) {
|
||||
return $this->createSingle($request);
|
||||
}
|
||||
|
||||
if ($multiple === true) {
|
||||
|
||||
return $this->createMultiple($request);
|
||||
}
|
||||
|
||||
// at this point, we miss the required fields. Throw an error
|
||||
return (new Response())
|
||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||
->setContent("You must provide either 'person_id' or "
|
||||
. "'persons_ids' argument in query");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function createSingle(Request $request)
|
||||
{
|
||||
$participation = $this->handleRequest($request, new Participation(), false);
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||
$participation, 'The user is not allowed to create this participation');
|
||||
|
||||
$form = $this->createCreateForm($participation);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$em->persist($participation);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans(
|
||||
'The participation was created'
|
||||
));
|
||||
|
||||
if ($request->query->get('return_path'))
|
||||
{
|
||||
return $this->redirect($request->query->get('return_path'));
|
||||
|
||||
} else {
|
||||
return $this->redirectToRoute('chill_event__event_show', array(
|
||||
'event_id' => $participation->getEvent()->getId()
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function createMultiple(Request $request)
|
||||
{
|
||||
$participations = $this->handleRequest($request, new Participation(), true);
|
||||
|
||||
foreach($participations as $participation) {
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||
$participation, 'The user is not allowed to create this participation');
|
||||
}
|
||||
|
||||
$form = $this->createCreateFormMultiple($participations);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = $form->getData();
|
||||
|
||||
foreach($data['participations'] as $participation) {
|
||||
$em->persist($participation);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans(
|
||||
'The participations were created'
|
||||
));
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_show', array(
|
||||
'event_id' => $participations[0]->getEvent()->getId()
|
||||
));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Handle the request to adapt $participation.
|
||||
*
|
||||
* If the request is multiple, the $participation object is cloned.
|
||||
* Limitations: the $participation should not be persisted.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Participation $participation
|
||||
* @param boolean $multiple (default false)
|
||||
* @return Participation|Participations[] return one single participation if $multiple == false
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
|
||||
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
|
||||
*/
|
||||
protected function handleRequest(
|
||||
Request $request,
|
||||
Participation $participation,
|
||||
$multiple = false)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
if ($em->contains($participation)) {
|
||||
throw new \LogicException("The participation object should not be managed by "
|
||||
. "the object manager using the method ".__METHOD__);
|
||||
}
|
||||
|
||||
$event_id = $request->query->getInt('event_id', 0); // sf4 check:
|
||||
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
||||
|
||||
if ($event_id !== NULL) {
|
||||
$event = $em->getRepository('ChillEventBundle:Event')
|
||||
->find($event_id);
|
||||
|
||||
if ($event === NULL) {
|
||||
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event,
|
||||
'The user is not allowed to see the event');
|
||||
|
||||
$participation->setEvent($event);
|
||||
}
|
||||
|
||||
// this script should be able to handle multiple, so we translate
|
||||
// single person_id in an array
|
||||
$persons_ids = $request->query->has('person_id') ?
|
||||
[$request->query->getInt('person_id', 0)] // sf4 check:
|
||||
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
||||
: explode(',', $request->query->get('persons_ids'));
|
||||
$participations = array();
|
||||
|
||||
foreach($persons_ids as $person_id) {
|
||||
|
||||
// clone if we have to reuse the $participation
|
||||
$participation = count($persons_ids) > 1 ? clone $participation : $participation;
|
||||
|
||||
if ($person_id !== NULL) {
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')
|
||||
->find($person_id);
|
||||
|
||||
if ($person === NULL) {
|
||||
throw $this->createNotFoundException('The person with id '.$person_id.' is not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person,
|
||||
'The user is not allowed to see the person');
|
||||
|
||||
$participation->setPerson($person);
|
||||
}
|
||||
|
||||
$participations[] = $participation;
|
||||
}
|
||||
|
||||
return $multiple ? $participations : $participations[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Participation $participation
|
||||
* @param null $return_path
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
public function createCreateForm(Participation $participation, $return_path = null)
|
||||
{
|
||||
|
||||
$form = $this->createForm(ParticipationType::class, $participation, array(
|
||||
'event_type' => $participation->getEvent()->getType(),
|
||||
'action' => $this->generateUrl('chill_event_participation_create', array(
|
||||
'return_path' => $return_path,
|
||||
'event_id' => $participation->getEvent()->getId(),
|
||||
'person_id' => $participation->getPerson()->getId()
|
||||
))
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array(
|
||||
'label' => 'Create'
|
||||
));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $participations
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
public function createCreateFormMultiple(array $participations)
|
||||
{
|
||||
$form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class,
|
||||
array('participations' => $participations), array(
|
||||
'action' => $this->generateUrl('chill_event_participation_create', array(
|
||||
'event_id' => current($participations)->getEvent()->getId(),
|
||||
'persons_ids' => implode(',', array_map(
|
||||
function(Participation $p) { return $p->getPerson()->getId(); },
|
||||
$participations))
|
||||
)
|
||||
)));
|
||||
$form->add('participations', CollectionType::class, array(
|
||||
'entry_type' => ParticipationType::class,
|
||||
'entry_options' => array(
|
||||
'event_type' => current($participations)->getEvent()->getType()
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$form->add('submit', SubmitType::class, array(
|
||||
'label' => 'Create'
|
||||
));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* show an edit form for the participation with the given id.
|
||||
*
|
||||
* @param int $participation_id
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException if the user is not allowed to edit the participation
|
||||
*/
|
||||
public function editAction($participation_id)
|
||||
{
|
||||
/* @var $participation Participation */
|
||||
$participation = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillEventBundle:Participation')
|
||||
->find($participation_id);
|
||||
|
||||
if ($participation === NULL) {
|
||||
throw $this->createNotFoundException('The participation is not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||
'You are not allowed to edit this participation');
|
||||
|
||||
$form = $this->createEditForm($participation);
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $participation_id
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function updateAction($participation_id, Request $request)
|
||||
{
|
||||
/* @var $participation Participation */
|
||||
$participation = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillEventBundle:Participation')
|
||||
->find($participation_id);
|
||||
|
||||
if ($participation === NULL) {
|
||||
throw $this->createNotFoundException('The participation is not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||
'You are not allowed to edit this participation');
|
||||
|
||||
$form = $this->createEditForm($participation);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans(
|
||||
'The participation was updated'
|
||||
));
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_show', array(
|
||||
'event_id' => $participation->getEvent()->getId()
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Participation $participation
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
public function createEditForm(Participation $participation)
|
||||
{
|
||||
$form = $this->createForm(ParticipationType::class, $participation, array(
|
||||
'event_type' => $participation->getEvent()->getType(),
|
||||
'action' => $this->generateUrl('chill_event_participation_update', array(
|
||||
'participation_id' => $participation->getId()
|
||||
))
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array(
|
||||
'label' => 'Edit'
|
||||
));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* show a form to edit multiple participation for the same event.
|
||||
*
|
||||
* @param int $event_id
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function editMultipleAction($event_id)
|
||||
{
|
||||
$event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
|
||||
->find($event_id);
|
||||
|
||||
if ($event === null) {
|
||||
throw $this->createNotFoundException("The event with id $event_id is not found");
|
||||
}
|
||||
|
||||
// check for ACL, on Event level and on Participation Level
|
||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
|
||||
. "to see this event");
|
||||
foreach ($event->getParticipations() as $participation) {
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||
"You are not allowed to update participation with id ".$participation->getId());
|
||||
}
|
||||
|
||||
|
||||
switch ($event->getParticipations()->count()) {
|
||||
|
||||
case 0:
|
||||
// if there aren't any participation, redirect to the 'show' view with an add flash
|
||||
$this->addFlash('warning', $this->get('translator')
|
||||
->trans( "There are no participation to edit for this event"));
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_show',
|
||||
array('event_id' => $event->getId()));
|
||||
|
||||
case 1:
|
||||
// redirect to the form for a single participation
|
||||
return $this->redirectToRoute('chill_event_participation_edit', array(
|
||||
'participation_id' => $event->getParticipations()->current()->getId()
|
||||
));
|
||||
}
|
||||
|
||||
$form = $this->createEditFormMultiple($event->getParticipations(), $event);
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
|
||||
'event' => $event,
|
||||
'participations' => $event->getParticipations(),
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
public function updateMultipleAction($event_id, Request $request)
|
||||
{
|
||||
/* @var $event \Chill\EventBundle\Entity\Event */
|
||||
$event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
|
||||
->find($event_id);
|
||||
|
||||
if ($event === null) {
|
||||
throw $this->createNotFoundException("The event with id $event_id is not found");
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
|
||||
. "to see this event");
|
||||
foreach ($event->getParticipations() as $participation) {
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||
"You are not allowed to update participation with id ".$participation->getId());
|
||||
}
|
||||
|
||||
$form = $this->createEditFormMultiple($event->getParticipations(), $event);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans("The participations "
|
||||
. "have been successfully updated."));
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_show',
|
||||
array('event_id' => $event->getId()));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
|
||||
'event' => $event,
|
||||
'participations' => $event->getParticipations(),
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayIterator $participations
|
||||
* @param Event $event
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function createEditFormMultiple(ArrayIterator $participations, Event $event)
|
||||
{
|
||||
$form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class,
|
||||
array('participations' => $participations), array(
|
||||
'method' => 'POST',
|
||||
'action' => $this->generateUrl('chill_event_participation_update_multiple', array(
|
||||
'event_id' => $event->getId()
|
||||
))
|
||||
));
|
||||
|
||||
$form->add('participations', CollectionType::class, array(
|
||||
'entry_type' => ParticipationType::class,
|
||||
'entry_options' => array(
|
||||
'event_type' => $event->getType()
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$form->add('submit', SubmitType::class, array(
|
||||
'label' => 'Update'
|
||||
));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $participation_id
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function deleteAction($participation_id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$participation = $em->getRepository('ChillEventBundle:Participation')->findOneBy([
|
||||
'id' => $participation_id
|
||||
]);
|
||||
|
||||
if (! $participation) {
|
||||
throw $this->createNotFoundException('Unable to find participation.');
|
||||
}
|
||||
|
||||
/** @var Event $event */
|
||||
$event = $participation->getEvent();
|
||||
|
||||
$form = $this->createDeleteForm($participation_id);
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
|
||||
$em->remove($participation);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans("The participation has been sucessfully removed")
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_show', [
|
||||
'event_id' => $event->getId()
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->render('ChillEventBundle:Participation:confirm_delete.html.twig', [
|
||||
'event_id' => $event->getId(),
|
||||
'delete_form' => $form->createView()
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $participation_id
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createDeleteForm($participation_id)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_event_participation_delete', [
|
||||
'participation_id' => $participation_id
|
||||
]))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
228
src/Bundle/ChillEventBundle/Controller/RoleController.php
Normal file
228
src/Bundle/ChillEventBundle/Controller/RoleController.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\EventBundle\Entity\Role;
|
||||
use Chill\EventBundle\Form\RoleType;
|
||||
|
||||
/**
|
||||
* Class RoleController
|
||||
*
|
||||
* @package Chill\EventBundle\Controller
|
||||
*/
|
||||
class RoleController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* Lists all Role entities.
|
||||
*
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entities = $em->getRepository('ChillEventBundle:Role')->findAll();
|
||||
|
||||
return $this->render('ChillEventBundle:Role:index.html.twig', array(
|
||||
'entities' => $entities,
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Creates a new Role entity.
|
||||
*
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
$entity = new Role();
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event_admin_role',
|
||||
array('id' => $entity->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Role:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to create a Role entity.
|
||||
*
|
||||
* @param Role $entity The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createCreateForm(Role $entity)
|
||||
{
|
||||
$form = $this->createForm(RoleType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_event_admin_role_create'),
|
||||
'method' => 'POST',
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Create'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to create a new Role entity.
|
||||
*
|
||||
*/
|
||||
public function newAction()
|
||||
{
|
||||
$entity = new Role();
|
||||
$form = $this->createCreateForm($entity);
|
||||
|
||||
return $this->render('ChillEventBundle:Role:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a Role entity.
|
||||
*
|
||||
*/
|
||||
public function showAction($id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Role')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Role entity.');
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
|
||||
return $this->render('ChillEventBundle:Role:show.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing Role entity.
|
||||
*
|
||||
*/
|
||||
public function editAction($id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Role')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Role entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
|
||||
return $this->render('ChillEventBundle:Role:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to edit a Role entity.
|
||||
*
|
||||
* @param Role $entity The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createEditForm(Role $entity)
|
||||
{
|
||||
$form = $this->createForm(RoleType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_event_admin_role_update',
|
||||
array('id' => $entity->getId())),
|
||||
'method' => 'PUT',
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Update'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
/**
|
||||
* Edits an existing Role entity.
|
||||
*
|
||||
*/
|
||||
public function updateAction(Request $request, $id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Role')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Role entity.');
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isValid()) {
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event_admin_role',
|
||||
array('id' => $id)));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Role:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Deletes a Role entity.
|
||||
*
|
||||
*/
|
||||
public function deleteAction(Request $request, $id)
|
||||
{
|
||||
$form = $this->createDeleteForm($id);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$entity = $em->getRepository('ChillEventBundle:Role')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Role entity.');
|
||||
}
|
||||
|
||||
$em->remove($entity);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event_admin_role'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a Role entity by id.
|
||||
*
|
||||
* @param mixed $id The entity id
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm($id)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_event_admin_role_delete', array('id' => $id)))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
}
|
226
src/Bundle/ChillEventBundle/Controller/StatusController.php
Normal file
226
src/Bundle/ChillEventBundle/Controller/StatusController.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Chill\EventBundle\Entity\Status;
|
||||
use Chill\EventBundle\Form\StatusType;
|
||||
|
||||
/**
|
||||
* Class StatusController
|
||||
*
|
||||
* @package Chill\EventBundle\Controller
|
||||
*/
|
||||
class StatusController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* Lists all Status entities.
|
||||
*
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entities = $em->getRepository('ChillEventBundle:Status')->findAll();
|
||||
|
||||
return $this->render('ChillEventBundle:Status:index.html.twig', array(
|
||||
'entities' => $entities,
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Creates a new Status entity.
|
||||
*
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
$entity = new Status();
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event_admin_status', array('id' => $entity->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Status:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to create a Status entity.
|
||||
*
|
||||
* @param Status $entity The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createCreateForm(Status $entity)
|
||||
{
|
||||
$form = $this->createForm(StatusType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_event_admin_status_create'),
|
||||
'method' => 'POST',
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Create'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to create a new Status entity.
|
||||
*
|
||||
*/
|
||||
public function newAction()
|
||||
{
|
||||
$entity = new Status();
|
||||
$form = $this->createCreateForm($entity);
|
||||
|
||||
return $this->render('ChillEventBundle:Status:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a Status entity.
|
||||
*
|
||||
*/
|
||||
public function showAction($id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Status')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Status entity.');
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
|
||||
return $this->render('ChillEventBundle:Status:show.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing Status entity.
|
||||
*
|
||||
*/
|
||||
public function editAction($id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Status')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Status entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
|
||||
return $this->render('ChillEventBundle:Status:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to edit a Status entity.
|
||||
*
|
||||
* @param Status $entity The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createEditForm(Status $entity)
|
||||
{
|
||||
$form = $this->createForm(StatusType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_event_admin_status_update', array('id' => $entity->getId())),
|
||||
'method' => 'PUT',
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Update'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
/**
|
||||
* Edits an existing Status entity.
|
||||
*
|
||||
*/
|
||||
public function updateAction(Request $request, $id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Status')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Status entity.');
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isValid()) {
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event_admin_status', array('id' => $id)));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Status:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Deletes a Status entity.
|
||||
*
|
||||
*/
|
||||
public function deleteAction(Request $request, $id)
|
||||
{
|
||||
$form = $this->createDeleteForm($id);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$entity = $em->getRepository('ChillEventBundle:Status')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Status entity.');
|
||||
}
|
||||
|
||||
$em->remove($entity);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event_admin_status'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a Status entity by id.
|
||||
*
|
||||
* @param mixed $id The entity id
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm($id)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_event_admin_status_delete', array('id' => $id)))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user