mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-26 17:43:54 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
<?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\DocStoreBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
/**
|
||||
* Class AdminController
|
||||
*
|
||||
* @package Chill\DocStoreBundle\Controller
|
||||
* Class AdminController.
|
||||
*/
|
||||
class AdminController extends AbstractController
|
||||
{
|
||||
@@ -18,7 +23,7 @@ class AdminController extends AbstractController
|
||||
{
|
||||
return $this->render('ChillDocStoreBundle:Admin:layout.html.twig');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
@@ -26,5 +31,4 @@ class AdminController extends AbstractController
|
||||
{
|
||||
return $this->redirectToRoute('chill_main_admin_central');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?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\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||
@@ -7,26 +14,23 @@ use Chill\DocStoreBundle\Form\AccompanyingCourseDocumentType;
|
||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use DateTime;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/parcours/{course}/document")
|
||||
*/
|
||||
class DocumentAccompanyingCourseController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $translator;
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
@@ -34,16 +38,12 @@ class DocumentAccompanyingCourseController extends AbstractController
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* DocumentAccompanyingCourseController constructor.
|
||||
|
||||
* @param TranslatorInterface $translator
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param AuthorizationHelper $authorizationHelper
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
@@ -55,6 +55,66 @@ class DocumentAccompanyingCourseController extends AbstractController
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}", name="accompanying_course_document_delete", methods="DELETE")
|
||||
*/
|
||||
public function delete(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::DELETE, $document);
|
||||
|
||||
if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($document);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'accompanying_course_document_index',
|
||||
['accompanyingCourse' => $course->getId()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}/edit", name="accompanying_course_document_edit", methods="GET|POST")
|
||||
*/
|
||||
public function edit(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::UPDATE, $document);
|
||||
|
||||
$document->setUser($this->getUser());
|
||||
$document->setDate(new DateTime('Now'));
|
||||
|
||||
$form = $this->createForm(
|
||||
AccompanyingCourseDocumentType::class,
|
||||
$document
|
||||
);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans('The document is successfully updated'));
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'accompanying_course_document_edit',
|
||||
['id' => $document->getId(), 'course' => $course->getId()]
|
||||
);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans('This form contains errors'));
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:AccompanyingCourseDocument:edit.html.twig',
|
||||
[
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
'accompanyingCourse' => $course,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", name="accompanying_course_document_index", methods="GET")
|
||||
*/
|
||||
@@ -62,14 +122,14 @@ class DocumentAccompanyingCourseController extends AbstractController
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
if ($course === NULL) {
|
||||
if (null === $course) {
|
||||
throw $this->createNotFoundException('Accompanying period not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::SEE, $course);
|
||||
|
||||
$documents = $em
|
||||
->getRepository("ChillDocStoreBundle:AccompanyingCourseDocument")
|
||||
->getRepository('ChillDocStoreBundle:AccompanyingCourseDocument')
|
||||
->findBy(
|
||||
['course' => $course],
|
||||
['date' => 'DESC']
|
||||
@@ -79,8 +139,9 @@ class DocumentAccompanyingCourseController extends AbstractController
|
||||
'ChillDocStoreBundle:AccompanyingCourseDocument:index.html.twig',
|
||||
[
|
||||
'documents' => $documents,
|
||||
'accompanyingCourse' => $course
|
||||
]);
|
||||
'accompanyingCourse' => $course,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,14 +149,14 @@ class DocumentAccompanyingCourseController extends AbstractController
|
||||
*/
|
||||
public function new(Request $request, AccompanyingPeriod $course): Response
|
||||
{
|
||||
if ($course === NULL) {
|
||||
if (null === $course) {
|
||||
throw $this->createNotFoundException('Accompanying period not found');
|
||||
}
|
||||
|
||||
$document = new AccompanyingCourseDocument();
|
||||
$document->setUser($this->getUser());
|
||||
$document->setCourse($course);
|
||||
$document->setDate(new \DateTime('Now'));
|
||||
$document->setDate(new DateTime('Now'));
|
||||
|
||||
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::CREATE, $document);
|
||||
|
||||
@@ -104,18 +165,22 @@ class DocumentAccompanyingCourseController extends AbstractController
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE', $document,
|
||||
'creation of this activity not allowed');
|
||||
'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE',
|
||||
$document,
|
||||
'creation of this activity not allowed'
|
||||
);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($document);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans("The document is successfully registered"));
|
||||
$this->addFlash('success', $this->translator->trans('The document is successfully registered'));
|
||||
|
||||
return $this->redirectToRoute('accompanying_course_document_index', ['course' => $course->getId()]);
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans("This form contains errors"));
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans('This form contains errors'));
|
||||
}
|
||||
|
||||
return $this->render('ChillDocStoreBundle:AccompanyingCourseDocument:new.html.twig', [
|
||||
@@ -134,59 +199,7 @@ class DocumentAccompanyingCourseController extends AbstractController
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:AccompanyingCourseDocument:show.html.twig',
|
||||
['document' => $document, 'accompanyingCourse' => $course]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}/edit", name="accompanying_course_document_edit", methods="GET|POST")
|
||||
*/
|
||||
public function edit(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::UPDATE, $document);
|
||||
|
||||
$document->setUser($this->getUser());
|
||||
$document->setDate(new \DateTime('Now'));
|
||||
|
||||
$form = $this->createForm(
|
||||
AccompanyingCourseDocumentType::class, $document);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans("The document is successfully updated"));
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'accompanying_course_document_edit',
|
||||
['id' => $document->getId(), 'course' => $course->getId()]);
|
||||
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans("This form contains errors"));
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:AccompanyingCourseDocument:edit.html.twig',
|
||||
[
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
'accompanyingCourse' => $course,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}", name="accompanying_course_document_delete", methods="DELETE")
|
||||
*/
|
||||
public function delete(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::DELETE, $document);
|
||||
|
||||
if ($this->isCsrfTokenValid('delete'.$document->getId(), $request->request->get('_token'))) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($document);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'accompanying_course_document_index', ['accompanyingCourse' => $course->getId()]);
|
||||
['document' => $document, 'accompanyingCourse' => $course]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,17 @@
|
||||
<?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\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\ChillDocStoreBundle;
|
||||
use Chill\DocStoreBundle\Entity\DocumentCategory;
|
||||
use Chill\DocStoreBundle\Entity\PersonDocument;
|
||||
use Chill\DocStoreBundle\Form\DocumentCategoryType;
|
||||
@@ -11,19 +19,73 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Chill\DocStoreBundle\ChillDocStoreBundle;
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/admin/document/category")
|
||||
*/
|
||||
class DocumentCategoryController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/{bundleId}/{idInsideBundle}", name="document_category_delete", methods="DELETE")
|
||||
*
|
||||
* @param mixed $bundleId
|
||||
* @param mixed $idInsideBundle
|
||||
*/
|
||||
public function delete(Request $request, $bundleId, $idInsideBundle): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$documentCategory = $em
|
||||
->getRepository('ChillDocStoreBundle:DocumentCategory')
|
||||
->findOneBy(
|
||||
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]
|
||||
);
|
||||
|
||||
if ($this->isCsrfTokenValid('delete' . $bundleId . $idInsideBundle, $request->request->get('_token'))) {
|
||||
$em->remove($documentCategory);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('document_category_index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{bundleId}/{idInsideBundle}/edit", name="document_category_edit", methods="GET|POST")
|
||||
*
|
||||
* @param mixed $bundleId
|
||||
* @param mixed $idInsideBundle
|
||||
*/
|
||||
public function edit(Request $request, $bundleId, $idInsideBundle): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$documentCategory = $em
|
||||
->getRepository('ChillDocStoreBundle:DocumentCategory')
|
||||
->findOneBy(
|
||||
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]
|
||||
);
|
||||
|
||||
$form = $this->createForm(DocumentCategoryType::class, $documentCategory);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute('document_category_index', [
|
||||
'bundleId' => $documentCategory->getBundleId(),
|
||||
'idInsideBundle' => $documentCategory->getIdInsideBundle(), ]);
|
||||
}
|
||||
|
||||
return $this->render('ChillDocStoreBundle:DocumentCategory:edit.html.twig', [
|
||||
'document_category' => $documentCategory,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", name="document_category_index", methods="GET")
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$categories = $em->getRepository(DocumentCategory::class)->findAll();
|
||||
|
||||
return $this->render(
|
||||
@@ -68,64 +130,22 @@ class DocumentCategoryController extends AbstractController
|
||||
|
||||
/**
|
||||
* @Route("/{bundleId}/{idInsideBundle}", name="document_category_show", methods="GET")
|
||||
*
|
||||
* @param mixed $bundleId
|
||||
* @param mixed $idInsideBundle
|
||||
*/
|
||||
public function show($bundleId, $idInsideBundle): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$documentCategory = $em
|
||||
->getRepository("ChillDocStoreBundle:DocumentCategory")
|
||||
->getRepository('ChillDocStoreBundle:DocumentCategory')
|
||||
->findOneBy(
|
||||
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]);
|
||||
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]
|
||||
);
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:DocumentCategory:show.html.twig',
|
||||
['document_category' => $documentCategory]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{bundleId}/{idInsideBundle}/edit", name="document_category_edit", methods="GET|POST")
|
||||
*/
|
||||
public function edit(Request $request, $bundleId, $idInsideBundle): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$documentCategory = $em
|
||||
->getRepository("ChillDocStoreBundle:DocumentCategory")
|
||||
->findOneBy(
|
||||
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]);
|
||||
|
||||
$form = $this->createForm(DocumentCategoryType::class, $documentCategory);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute('document_category_index', [
|
||||
'bundleId' => $documentCategory->getBundleId(),
|
||||
'idInsideBundle' => $documentCategory->getIdInsideBundle(),]);
|
||||
}
|
||||
|
||||
return $this->render('ChillDocStoreBundle:DocumentCategory:edit.html.twig', [
|
||||
'document_category' => $documentCategory,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{bundleId}/{idInsideBundle}", name="document_category_delete", methods="DELETE")
|
||||
*/
|
||||
public function delete(Request $request, $bundleId, $idInsideBundle): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$documentCategory = $em
|
||||
->getRepository("ChillDocStoreBundle:DocumentCategory")
|
||||
->findOneBy(
|
||||
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]);
|
||||
|
||||
if ($this->isCsrfTokenValid('delete'.$bundleId.$idInsideBundle, $request->request->get('_token'))) {
|
||||
$em->remove($documentCategory);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('document_category_index');
|
||||
['document_category' => $documentCategory]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +1,147 @@
|
||||
<?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\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\PersonDocument;
|
||||
use Chill\DocStoreBundle\Form\PersonDocumentType;
|
||||
use Chill\DocStoreBundle\Repository\DocumentRepository;
|
||||
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use DateTime;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Class DocumentPersonController
|
||||
* Class DocumentPersonController.
|
||||
*
|
||||
* @package Chill\DocStoreBundle\Controller
|
||||
* @Route("/{_locale}/person/{person}/document")
|
||||
*
|
||||
* TODO faire un controller abstrait ?
|
||||
*/
|
||||
class DocumentPersonController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* DocumentPersonController constructor.
|
||||
|
||||
* @param TranslatorInterface $translator
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param AuthorizationHelper $authorizationHelper
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
TranslatorInterface $translator,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
AuthorizationHelper $authorizationHelper
|
||||
) {
|
||||
$this->translator = $translator;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/{id}", name="person_document_delete", methods="DELETE")
|
||||
*/
|
||||
public function delete(Request $request, Person $person, PersonDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document);
|
||||
|
||||
if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($document);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'person_document_index',
|
||||
['person' => $person->getId()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}/edit", name="person_document_edit", methods="GET|POST")
|
||||
*/
|
||||
public function edit(Request $request, Person $person, PersonDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_UPDATE', $document);
|
||||
|
||||
$document->setUser($this->getUser());
|
||||
$document->setDate(new DateTime('Now'));
|
||||
|
||||
$form = $this->createForm(
|
||||
PersonDocumentType::class,
|
||||
$document,
|
||||
[
|
||||
'center' => $document->getCenter(),
|
||||
'role' => new Role('CHILL_PERSON_DOCUMENT_UPDATE'),
|
||||
]
|
||||
);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans('The document is successfully updated'));
|
||||
|
||||
$event = new PrivacyEvent($person, [
|
||||
'element_class' => PersonDocument::class,
|
||||
'element_id' => $document->getId(),
|
||||
'action' => 'update',
|
||||
]);
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'person_document_edit',
|
||||
['id' => $document->getId(), 'person' => $person->getId()]
|
||||
);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans('This form contains errors'));
|
||||
}
|
||||
|
||||
$event = new PrivacyEvent($person, [
|
||||
'element_class' => PersonDocument::class,
|
||||
'element_id' => $document->getId(),
|
||||
'action' => 'edit',
|
||||
]);
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:PersonDocument:edit.html.twig',
|
||||
[
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
'person' => $person,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", name="person_document_index", methods="GET")
|
||||
*/
|
||||
@@ -69,7 +149,7 @@ class DocumentPersonController extends AbstractController
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
if ($person === NULL) {
|
||||
if (null === $person) {
|
||||
throw $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
@@ -77,28 +157,31 @@ class DocumentPersonController extends AbstractController
|
||||
|
||||
$reachableScopes = $this->authorizationHelper
|
||||
->getReachableScopes(
|
||||
$this->getUser(), new Role(PersonDocumentVoter::SEE),
|
||||
$person->getCenter());
|
||||
|
||||
$documents = $em
|
||||
->getRepository("ChillDocStoreBundle:PersonDocument")
|
||||
->findBy(
|
||||
array('person' => $person, 'scope' => $reachableScopes),
|
||||
array('date' => 'DESC')
|
||||
$this->getUser(),
|
||||
new Role(PersonDocumentVoter::SEE),
|
||||
$person->getCenter()
|
||||
);
|
||||
|
||||
$event = new PrivacyEvent($person, array(
|
||||
$documents = $em
|
||||
->getRepository('ChillDocStoreBundle:PersonDocument')
|
||||
->findBy(
|
||||
['person' => $person, 'scope' => $reachableScopes],
|
||||
['date' => 'DESC']
|
||||
);
|
||||
|
||||
$event = new PrivacyEvent($person, [
|
||||
'element_class' => PersonDocument::class,
|
||||
'action' => 'index'
|
||||
));
|
||||
'action' => 'index',
|
||||
]);
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:PersonDocument:index.html.twig',
|
||||
[
|
||||
'documents' => $documents,
|
||||
'person' => $person
|
||||
]);
|
||||
'person' => $person,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +189,7 @@ class DocumentPersonController extends AbstractController
|
||||
*/
|
||||
public function new(Request $request, Person $person): Response
|
||||
{
|
||||
if ($person === NULL) {
|
||||
if (null === $person) {
|
||||
throw $this->createNotFoundException('person not found');
|
||||
}
|
||||
|
||||
@@ -115,28 +198,32 @@ class DocumentPersonController extends AbstractController
|
||||
$document = new PersonDocument();
|
||||
$document->setUser($this->getUser());
|
||||
$document->setPerson($person);
|
||||
$document->setDate(new \DateTime('Now'));
|
||||
$document->setDate(new DateTime('Now'));
|
||||
|
||||
$form = $this->createForm(PersonDocumentType::class, $document, array(
|
||||
$form = $this->createForm(PersonDocumentType::class, $document, [
|
||||
'center' => $document->getCenter(),
|
||||
'role' => new Role('CHILL_PERSON_DOCUMENT_CREATE')
|
||||
));
|
||||
'role' => new Role('CHILL_PERSON_DOCUMENT_CREATE'),
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_DOCUMENT_CREATE', $document,
|
||||
'creation of this activity not allowed');
|
||||
'CHILL_PERSON_DOCUMENT_CREATE',
|
||||
$document,
|
||||
'creation of this activity not allowed'
|
||||
);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($document);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans("The document is successfully registered"));
|
||||
|
||||
$this->addFlash('success', $this->translator->trans('The document is successfully registered'));
|
||||
|
||||
return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]);
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans("This form contains errors"));
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans('This form contains errors'));
|
||||
}
|
||||
|
||||
return $this->render('ChillDocStoreBundle:PersonDocument:new.html.twig', [
|
||||
@@ -153,88 +240,17 @@ class DocumentPersonController extends AbstractController
|
||||
{
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_SEE', $document);
|
||||
|
||||
$event = new PrivacyEvent($person, array(
|
||||
|
||||
$event = new PrivacyEvent($person, [
|
||||
'element_class' => PersonDocument::class,
|
||||
'element_id' => $document->getId(),
|
||||
'action' => 'show'
|
||||
));
|
||||
'action' => 'show',
|
||||
]);
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:PersonDocument:show.html.twig',
|
||||
['document' => $document, 'person' => $person]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}/edit", name="person_document_edit", methods="GET|POST")
|
||||
*/
|
||||
public function edit(Request $request, Person $person, PersonDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_UPDATE', $document);
|
||||
|
||||
$document->setUser($this->getUser());
|
||||
$document->setDate(new \DateTime('Now'));
|
||||
|
||||
$form = $this->createForm(
|
||||
PersonDocumentType::class, $document, array(
|
||||
'center' => $document->getCenter(),
|
||||
'role' => new Role('CHILL_PERSON_DOCUMENT_UPDATE'),
|
||||
));
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans("The document is successfully updated"));
|
||||
|
||||
$event = new PrivacyEvent($person, array(
|
||||
'element_class' => PersonDocument::class,
|
||||
'element_id' => $document->getId(),
|
||||
'action' => 'update'
|
||||
));
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'person_document_edit',
|
||||
['id' => $document->getId(), 'person' => $person->getId()]);
|
||||
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans("This form contains errors"));
|
||||
}
|
||||
|
||||
$event = new PrivacyEvent($person, array(
|
||||
'element_class' => PersonDocument::class,
|
||||
'element_id' => $document->getId(),
|
||||
'action' => 'edit'
|
||||
));
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:PersonDocument:edit.html.twig',
|
||||
[
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
'person' => $person,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}", name="person_document_delete", methods="DELETE")
|
||||
*/
|
||||
public function delete(Request $request, Person $person, PersonDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document);
|
||||
|
||||
if ($this->isCsrfTokenValid('delete'.$document->getId(), $request->request->get('_token'))) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($document);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'person_document_index', ['person' => $person->getId()]);
|
||||
['document' => $document, 'person' => $person]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user