mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
180 lines
4.7 KiB
PHP
180 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Chill\MainBundle\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Chill\MainBundle\Entity\Center;
|
|
use Chill\MainBundle\Form\CenterType;
|
|
|
|
|
|
/**
|
|
* Class CenterController
|
|
*
|
|
* @package Chill\MainBundle\Controller
|
|
*/
|
|
class CenterController extends AbstractController
|
|
{
|
|
|
|
/**
|
|
* Lists all Center entities.
|
|
*
|
|
*/
|
|
public function indexAction()
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entities = $em->getRepository('ChillMainBundle:Center')->findAll();
|
|
|
|
return $this->render('@ChillMain/Center/index.html.twig', array(
|
|
'entities' => $entities,
|
|
));
|
|
}
|
|
/**
|
|
* Creates a new Center entity.
|
|
*
|
|
*/
|
|
public function createAction(Request $request)
|
|
{
|
|
$center = new Center();
|
|
$form = $this->createCreateForm($center);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isValid()) {
|
|
$em = $this->getDoctrine()->getManager();
|
|
$em->persist($center);
|
|
$em->flush();
|
|
|
|
return $this->redirect($this->generateUrl('admin_center_show', array('id' => $center->getId())));
|
|
}
|
|
|
|
return $this->render('@ChillMain/Center/new.html.twig', array(
|
|
'entity' => $center,
|
|
'form' => $form->createView(),
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Creates a form to create a Center entity.
|
|
*
|
|
* @param Center $center The entity
|
|
*
|
|
* @return \Symfony\Component\Form\Form The form
|
|
*/
|
|
private function createCreateForm(Center $center)
|
|
{
|
|
$form = $this->createForm(CenterType::class, $center, array(
|
|
'action' => $this->generateUrl('admin_center_create'),
|
|
'method' => 'POST',
|
|
));
|
|
|
|
$form->add('submit', SubmitType::class, array('label' => 'Create'));
|
|
|
|
return $form;
|
|
}
|
|
|
|
/**
|
|
* Displays a form to create a new Center entity.
|
|
*
|
|
*/
|
|
public function newAction()
|
|
{
|
|
$center = new Center();
|
|
$form = $this->createCreateForm($center);
|
|
|
|
return $this->render('@ChillMain/Center/new.html.twig', array(
|
|
'entity' => $center,
|
|
'form' => $form->createView(),
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Finds and displays a Center entity.
|
|
*
|
|
*/
|
|
public function showAction($id)
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$center = $em->getRepository('ChillMainBundle:Center')->find($id);
|
|
|
|
if (!$center) {
|
|
throw $this->createNotFoundException('Unable to find Center entity.');
|
|
}
|
|
|
|
return $this->render('@ChillMain/Center/show.html.twig', array(
|
|
'entity' => $center
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Displays a form to edit an existing Center entity.
|
|
*
|
|
*/
|
|
public function editAction($id)
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$center = $em->getRepository('ChillMainBundle:Center')->find($id);
|
|
|
|
if (!$center) {
|
|
throw $this->createNotFoundException('Unable to find Center entity.');
|
|
}
|
|
|
|
$editForm = $this->createEditForm($center);
|
|
return $this->render('@ChillMain/Center/edit.html.twig', array(
|
|
'entity' => $center,
|
|
'edit_form' => $editForm->createView()
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Creates a form to edit a Center entity.
|
|
*
|
|
* @param Center $center The entity
|
|
*
|
|
* @return \Symfony\Component\Form\Form The form
|
|
*/
|
|
private function createEditForm(Center $center)
|
|
{
|
|
$form = $this->createForm(CenterType::class, $center, array(
|
|
'action' => $this->generateUrl('admin_center_update', array('id' => $center->getId())),
|
|
'method' => 'PUT',
|
|
));
|
|
|
|
$form->add('submit', SubmitType::class, array('label' => 'Update'));
|
|
|
|
return $form;
|
|
}
|
|
/**
|
|
* Edits an existing Center entity.
|
|
*
|
|
*/
|
|
public function updateAction(Request $request, $id)
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$center = $em->getRepository('ChillMainBundle:Center')->find($id);
|
|
|
|
if (!$center) {
|
|
throw $this->createNotFoundException('Unable to find Center entity.');
|
|
}
|
|
|
|
$editForm = $this->createEditForm($center);
|
|
$editForm->handleRequest($request);
|
|
|
|
if ($editForm->isValid()) {
|
|
$em->flush();
|
|
|
|
return $this->redirect($this->generateUrl('admin_center_edit', array('id' => $id)));
|
|
}
|
|
|
|
return $this->render('@ChillMain/Center/edit.html.twig', array(
|
|
'entity' => $center,
|
|
'edit_form' => $editForm->createView()
|
|
));
|
|
}
|
|
}
|