mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
187 lines
4.9 KiB
PHP
187 lines
4.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\MainBundle\Controller;
|
|
|
|
use Chill\MainBundle\Entity\Center;
|
|
use Chill\MainBundle\Form\CenterType;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
/**
|
|
* Class CenterController.
|
|
*/
|
|
class CenterController extends AbstractController
|
|
{
|
|
/**
|
|
* 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', ['id' => $center->getId()]));
|
|
}
|
|
|
|
return $this->render('@ChillMain/Center/new.html.twig', [
|
|
'entity' => $center,
|
|
'form' => $form->createView(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Displays a form to edit an existing Center entity.
|
|
*
|
|
* @param mixed $id
|
|
*/
|
|
public function editAction($id)
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$center = $em->getRepository(\Chill\MainBundle\Entity\Center::class)->find($id);
|
|
|
|
if (!$center) {
|
|
throw $this->createNotFoundException('Unable to find Center entity.');
|
|
}
|
|
|
|
$editForm = $this->createEditForm($center);
|
|
|
|
return $this->render('@ChillMain/Center/edit.html.twig', [
|
|
'entity' => $center,
|
|
'edit_form' => $editForm->createView(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Lists all Center entities.
|
|
*/
|
|
public function indexAction()
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entities = $em->getRepository(\Chill\MainBundle\Entity\Center::class)->findAll();
|
|
|
|
return $this->render('@ChillMain/Center/index.html.twig', [
|
|
'entities' => $entities,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 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', [
|
|
'entity' => $center,
|
|
'form' => $form->createView(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Finds and displays a Center entity.
|
|
*
|
|
* @param mixed $id
|
|
*/
|
|
public function showAction($id)
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$center = $em->getRepository(\Chill\MainBundle\Entity\Center::class)->find($id);
|
|
|
|
if (!$center) {
|
|
throw $this->createNotFoundException('Unable to find Center entity.');
|
|
}
|
|
|
|
return $this->render('@ChillMain/Center/show.html.twig', [
|
|
'entity' => $center,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Edits an existing Center entity.
|
|
*
|
|
* @param mixed $id
|
|
*/
|
|
public function updateAction(Request $request, $id)
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$center = $em->getRepository(\Chill\MainBundle\Entity\Center::class)->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', ['id' => $id]));
|
|
}
|
|
|
|
return $this->render('@ChillMain/Center/edit.html.twig', [
|
|
'entity' => $center,
|
|
'edit_form' => $editForm->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, [
|
|
'action' => $this->generateUrl('admin_center_create'),
|
|
'method' => 'POST',
|
|
]);
|
|
|
|
$form->add('submit', SubmitType::class, ['label' => 'Create']);
|
|
|
|
return $form;
|
|
}
|
|
|
|
/**
|
|
* 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, [
|
|
'action' => $this->generateUrl('admin_center_update', ['id' => $center->getId()]),
|
|
'method' => 'PUT',
|
|
]);
|
|
|
|
$form->add('submit', SubmitType::class, ['label' => 'Update']);
|
|
|
|
return $form;
|
|
}
|
|
}
|