mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,29 +1,40 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
|
||||
class AccompanyingCourseWorkController extends AbstractController
|
||||
{
|
||||
private TranslatorInterface $trans;
|
||||
private SerializerInterface $serializer;
|
||||
private AccompanyingPeriodWorkRepository $workRepository;
|
||||
private PaginatorFactory $paginator;
|
||||
private LoggerInterface $chillLogger;
|
||||
|
||||
private PaginatorFactory $paginator;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private TranslatorInterface $trans;
|
||||
|
||||
private AccompanyingPeriodWorkRepository $workRepository;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $trans,
|
||||
SerializerInterface $serializer,
|
||||
@@ -40,58 +51,107 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/person/accompanying-period/{id}/work/new",
|
||||
* name="chill_person_accompanying_period_work_new",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
* "{_locale}/person/accompanying-period/{id}/work/new",
|
||||
* name="chill_person_accompanying_period_work_new",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
*/
|
||||
public function createWork(AccompanyingPeriod $period): Response
|
||||
{
|
||||
// TODO ACL
|
||||
|
||||
if ($period->getSocialIssues()->count() === 0) {
|
||||
$this->addFlash('error', $this->trans->trans(
|
||||
"accompanying_work.You must add at least ".
|
||||
"one social issue on accompanying period")
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$this->trans->trans(
|
||||
'accompanying_work.You must add at least ' .
|
||||
'one social issue on accompanying period'
|
||||
)
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_person_accompanying_course_index', [
|
||||
'accompanying_period_id' => $period->getId()
|
||||
'accompanying_period_id' => $period->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
$json = $this->serializer->normalize($period, 'json', [ "groups" => [ "read" ]]);
|
||||
$json = $this->serializer->normalize($period, 'json', ['groups' => ['read']]);
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingCourseWork/create.html.twig', [
|
||||
'accompanyingCourse' => $period,
|
||||
'json' => $json
|
||||
'json' => $json,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/person/accompanying-period/work/{id}/edit",
|
||||
* name="chill_person_accompanying_period_work_edit",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
* "{_locale}/person/accompanying-period/work/{id}/delete",
|
||||
* name="chill_person_accompanying_period_work_delete",
|
||||
* methods={"GET", "POST", "DELETE"}
|
||||
* )
|
||||
*/
|
||||
public function deleteWork(AccompanyingPeriodWork $work, Request $request): Response
|
||||
{
|
||||
// TODO ACL
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$form = $this->createDeleteForm($work->getId());
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$this->chillLogger->notice('An accompanying period work has been removed', [
|
||||
'by_user' => $this->getUser()->getUsername(),
|
||||
'work_id' => $work->getId(),
|
||||
'accompanying_period_id' => $work->getAccompanyingPeriod()->getId(),
|
||||
]);
|
||||
|
||||
$em->remove($work);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash(
|
||||
'success',
|
||||
$this->trans->trans('The accompanying period work has been successfully removed.')
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_person_accompanying_period_work_list', [
|
||||
'id' => $work->getAccompanyingPeriod()->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingCourseWork/delete.html.twig', [
|
||||
'accompanyingCourse' => $work->getAccompanyingPeriod(),
|
||||
'work' => $work,
|
||||
'delete_form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/person/accompanying-period/work/{id}/edit",
|
||||
* name="chill_person_accompanying_period_work_edit",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
*/
|
||||
public function editWork(AccompanyingPeriodWork $work): Response
|
||||
{
|
||||
// TODO ACL
|
||||
$json = $this->serializer->normalize($work, 'json', [ "groups" => [ "read" ] ]);
|
||||
$json = $this->serializer->normalize($work, 'json', ['groups' => ['read']]);
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingCourseWork/edit.html.twig', [
|
||||
'accompanyingCourse' => $work->getAccompanyingPeriod(),
|
||||
'work' => $work,
|
||||
'json' => $json
|
||||
'json' => $json,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/person/accompanying-period/{id}/work",
|
||||
* name="chill_person_accompanying_period_work_list",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
* "{_locale}/person/accompanying-period/{id}/work",
|
||||
* name="chill_person_accompanying_period_work_list",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
*/
|
||||
public function listWorkByAccompanyingPeriod(AccompanyingPeriod $period): Response
|
||||
{
|
||||
@@ -109,54 +169,7 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
return $this->render('@ChillPerson/AccompanyingCourseWork/index.html.twig', [
|
||||
'accompanyingCourse' => $period,
|
||||
'works' => $works,
|
||||
'paginator' => $paginator
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/person/accompanying-period/work/{id}/delete",
|
||||
* name="chill_person_accompanying_period_work_delete",
|
||||
* methods={"GET", "POST", "DELETE"}
|
||||
* )
|
||||
*/
|
||||
public function deleteWork(AccompanyingPeriodWork $work, Request $request): Response
|
||||
{
|
||||
// TODO ACL
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$form = $this->createDeleteForm($work->getId());
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
|
||||
$this->chillLogger->notice("An accompanying period work has been removed", [
|
||||
'by_user' => $this->getUser()->getUsername(),
|
||||
'work_id' => $work->getId(),
|
||||
'accompanying_period_id' => $work->getAccompanyingPeriod()->getId()
|
||||
]);
|
||||
|
||||
$em->remove($work);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash(
|
||||
'success',
|
||||
$this->trans->trans("The accompanying period work has been successfully removed.")
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_person_accompanying_period_work_list', [
|
||||
'id' => $work->getAccompanyingPeriod()->getId()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingCourseWork/delete.html.twig', [
|
||||
'accompanyingCourse' => $work->getAccompanyingPeriod(),
|
||||
'work' => $work,
|
||||
'delete_form' => $form->createView()
|
||||
'paginator' => $paginator,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -169,9 +182,6 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
->setAction($this->generateUrl('chill_person_accompanying_period_work_delete', $params))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||
->getForm()
|
||||
;
|
||||
->getForm();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user