Skip to content

Commit

Permalink
Rename EventKindController to AdminEventKindController. Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Aug 25, 2023
1 parent 40ad512 commit 951244f
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 9 deletions.
130 changes: 130 additions & 0 deletions src/AppBundle/Controller/AdminEventKindController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace AppBundle\Controller;

use AppBundle\Entity\EventKind;
use AppBundle\Form\EventKindType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;


/**
* AdminEventKind controller
*
* @Route("admin/event/kinds")
*/
class AdminEventKindController extends Controller
{
/**
* Lists all event kinds
*
* @Route("/", name="admin_event_kind_list", methods={"GET"})
* @Security("has_role('ROLE_PROCESS_MANAGER')")
*/
public function listAction()
{
$em = $this->getDoctrine()->getManager();

$eventKinds = $em->getRepository('AppBundle:EventKind')->findAll();

return $this->render('admin/event/kind/list.html.twig', array(
'eventKinds' => $eventKinds,
));
}

/**
* Add new event kind
*
* @Route("/new", name="admin_event_kind_new", methods={"GET","POST"})
* @Security("has_role('ROLE_PROCESS_MANAGER')")
*/
public function newAction(Request $request)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();

$eventKind = new EventKind();
$form = $this->createForm(EventKindType::class, $eventKind);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em->persist($eventKind);
$em->flush();

$session->getFlashBag()->add('success', 'Le type d\'événement a bien été créé !');
return $this->redirectToRoute('admin_event_kind_list');
}

return $this->render('admin/event/kind/new.html.twig', array(
'form' => $form->createView(),
));
}

/**
* Edit event kind
*
* @Route("/{id}/edit", name="admin_event_kind_edit", methods={"GET","POST"})
* @Security("has_role('ROLE_PROCESS_MANAGER')")
*/
public function editAction(Request $request, EventKind $eventKind)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();

$form = $this->createForm(EventKindType::class, $eventKind);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em->persist($eventKind);
$em->flush();

$session->getFlashBag()->add('success', 'Le type d\'événement a bien été édité !');
return $this->redirectToRoute('admin_event_kind_list');
}

return $this->render('admin/event/kind/edit.html.twig', array(
'form' => $form->createView(),
'eventKind' => $eventKind,
'delete_form' => $this->getDeleteForm($eventKind)->createView(),
));
}

/**
* Delete event kind
*
* @Route("/{id}", name="admin_event_kind_delete", methods={"DELETE"})
* @Security("has_role('ROLE_ADMIN')")
*/
public function deleteAction(Request $request, EventKind $eventKind)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();

$form = $this->getDeleteForm($eventKind);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em->remove($eventKind);
$em->flush();

$session->getFlashBag()->add('success', 'Le type d\'événement a bien été supprimé !');
}

return $this->redirectToRoute('admin_event_kind_list');
}

/**
* @param EventKind $eventKind
* @return \Symfony\Component\Form\FormInterface
*/
protected function getDeleteForm(EventKind $eventKind)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('admin_event_kind_delete', array('id' => $eventKind->getId())))
->setMethod('DELETE')
->getForm();
}
}
4 changes: 2 additions & 2 deletions src/AppBundle/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ class Event
private $createdBy;

/**
* @ORM\Column(type="datetime")
*
* @var \DateTime
*
* @ORM\Column(type="datetime")
*/
private $updatedAt;

Expand Down
12 changes: 5 additions & 7 deletions src/AppBundle/Entity/EventKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class EventKind
private $createdAt;

/**
* Define toString.
*
* @return string
*/
public function __toString()
Expand All @@ -62,7 +60,7 @@ public function setCreatedAtValue()
}

/**
* Get id.
* Get id
*
* @return int
*/
Expand All @@ -72,7 +70,7 @@ public function getId()
}

/**
* Set name.
* Set name
*
* @param string $name
*
Expand All @@ -86,7 +84,7 @@ public function setName($name)
}

/**
* Get name.
* Get name
*
* @return string
*/
Expand All @@ -96,7 +94,7 @@ public function getName()
}

/**
* Get events.
* Get events
*
* @return \Doctrine\Common\Collections\Collection
*/
Expand All @@ -106,7 +104,7 @@ public function getEvents()
}

/**
* Get createdAt.
* Get createdAt
*
* @return \DateTime
*/
Expand Down

0 comments on commit 951244f

Please sign in to comment.