mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
First commit
This commit is contained in:
129
Controller/DocumentCategoryController.php
Normal file
129
Controller/DocumentCategoryController.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\DocumentCategory;
|
||||
use Chill\DocStoreBundle\Entity\PersonDocument;
|
||||
use Chill\DocStoreBundle\Form\DocumentCategoryType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/admin/document/category")
|
||||
*/
|
||||
class DocumentCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/", name="document_category_index", methods="GET")
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$categories = $em->getRepository("ChillDocStoreBundle:DocumentCategory")->findAll();
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:DocumentCategory:index.html.twig',
|
||||
['document_categories' => $categories]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/new", name="document_category_new", methods="GET|POST")
|
||||
*/
|
||||
public function new(Request $request): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$documentCategory = new DocumentCategory();
|
||||
$documentCategory
|
||||
->setBundleId('Chill\DocStoreBundle\ChillDocStoreBundle');
|
||||
$documentCategory
|
||||
->setIdInsideBundle(
|
||||
$em->getRepository("ChillDocStoreBundle:DocumentCategory")
|
||||
->nextIdInsideBundle());
|
||||
$documentCategory
|
||||
->setDocumentClass(PersonDocument::class);
|
||||
|
||||
$form = $this->createForm(DocumentCategoryType::class, $documentCategory);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($documentCategory);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('document_category_index');
|
||||
} else {
|
||||
$documentCategory->setBundleId(
|
||||
'Chill\DocStoreBundle\ChillDocStoreBundle');
|
||||
}
|
||||
|
||||
return $this->render('ChillDocStoreBundle:DocumentCategory:new.html.twig', [
|
||||
'document_category' => $documentCategory,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{bundleId}/{idInsideBundle}", name="document_category_show", methods="GET")
|
||||
*/
|
||||
public function show($bundleId, $idInsideBundle): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$documentCategory = $em
|
||||
->getRepository("ChillDocStoreBundle:DocumentCategory")
|
||||
->findOneBy(
|
||||
['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_edit', [
|
||||
'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');
|
||||
}
|
||||
}
|
163
Controller/DocumentPersonController.php
Normal file
163
Controller/DocumentPersonController.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\PersonDocument;
|
||||
use Chill\DocStoreBundle\Form\PersonDocumentType;
|
||||
use Chill\DocStoreBundle\Repository\DocumentRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/{person}/document")
|
||||
*
|
||||
* TODO faire un controller abstrait ?
|
||||
*/
|
||||
class DocumentPersonController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/", name="person_document_index", methods="GET")
|
||||
*/
|
||||
public function index(Person $person): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
if ($person === NULL) {
|
||||
throw $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$reachableScopes = $this->get('chill.main.security.authorization.helper')
|
||||
->getReachableScopes(
|
||||
$this->getUser(), new Role('CHILL_PERSON_DOCUMENT_SEE'),
|
||||
$person->getCenter());
|
||||
|
||||
$documents = $em
|
||||
->getRepository("ChillDocStoreBundle:PersonDocument")
|
||||
->findBy(
|
||||
array('person' => $person, 'scope' => $reachableScopes),
|
||||
array('date' => 'DESC')
|
||||
);
|
||||
|
||||
return $this->render(
|
||||
'ChillDocStoreBundle:PersonDocument:index.html.twig',
|
||||
[
|
||||
'documents' => $documents,
|
||||
'person' => $person
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/new", name="person_document_new", methods="GET|POST")
|
||||
*/
|
||||
public function new(Request $request, Person $person): Response
|
||||
{
|
||||
if ($person === NULL) {
|
||||
throw $this->createNotFoundException('person not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$user = $this->get('security.context')->getToken()->getUser();
|
||||
$document = new PersonDocument();
|
||||
$document->setUser($user);
|
||||
$document->setPerson($person);
|
||||
$document->setDate(new \DateTime('Now'));
|
||||
|
||||
$form = $this->createForm(PersonDocumentType::class, $document, array(
|
||||
'center' => $document->getCenter(),
|
||||
'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');
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($document);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]);
|
||||
}
|
||||
|
||||
return $this->render('ChillDocStoreBundle:PersonDocument:new.html.twig', [
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
'person' => $person,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}", name="person_document_show", methods="GET")
|
||||
*/
|
||||
public function show(Person $person, PersonDocument $document): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_SEE', $document);
|
||||
|
||||
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);
|
||||
|
||||
$user = $this->get('security.context')->getToken()->getUser();
|
||||
$document->setUser($user);
|
||||
$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();
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'person_document_edit',
|
||||
['id' => $document->getId(), 'person' => $person->getId()]);
|
||||
}
|
||||
|
||||
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()]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user