Fix routes and use annotations.

This commit is contained in:
Pol Dellaiera 2021-05-06 17:35:28 +02:00
parent 174d873398
commit e9a7a05fb7
7 changed files with 196 additions and 160 deletions

View File

@ -1,123 +1,3 @@
chill_person_view:
path: /{_locale}/person/{person_id}/general
controller: Chill\PersonBundle\Controller\PersonController::viewAction
chill_person_general_edit:
path: /{_locale}/person/{person_id}/general/edit
controller: Chill\PersonBundle\Controller\PersonController::editAction
chill_person_general_update:
path: /{_locale}/person/{person_id}/general/update
controller: Chill\PersonBundle\Controller\PersonController::updateAction
chill_person_new:
path: /{_locale}/person/new
controller: Chill\PersonBundle\Controller\PersonController::newAction
chill_person_review:
path: /{_locale}/person/review
controller: Chill\PersonBundle\Controller\PersonController::reviewAction
chill_person_create:
path: /{_locale}/person/create
controller: Chill\PersonBundle\Controller\PersonController::createAction
chill_person_search:
path: /{_locale}/person/search
controller: Chill\PersonBundle\Controller\PersonController::searchAction
options:
menus:
main:
order: 30
label: Search within persons
chill_person_accompanying_period_list:
path: /{_locale}/person/{person_id}/accompanying-period
controller: Chill\PersonBundle\Controller\AccompanyingPeriodController::listAction
chill_person_accompanying_period_create:
path: /{_locale}/person/{person_id}/accompanying-period/create
controller: Chill\PersonBundle\Controller\AccompanyingPeriodController::createAction
chill_person_accompanying_period_update:
path: /{_locale}/person/{person_id}/accompanying-period/{period_id}/update
controller: Chill\PersonBundle\Controller\AccompanyingPeriodController::updateAction
chill_person_accompanying_period_close:
path: /{_locale}/person/{person_id}/accompanying-period/close
controller: Chill\PersonBundle\Controller\AccompanyingPeriodController::closeAction
chill_person_accompanying_period_open:
path: /{_locale}/person/{person_id}/accompanying-period/open
controller: Chill\PersonBundle\Controller\AccompanyingPeriodController::openAction
chill_person_accompanying_period_re_open:
path: /{_locale}/person/{person_id}/accompanying-period/{period_id}/re-open
controller: Chill\PersonBundle\Controller\AccompanyingPeriodController::reOpenAction
chill_person_address_list:
path: /{_locale}/person/{person_id}/address/list
controller: Chill\PersonBundle\Controller\PersonAddressController::listAction
chill_person_address_create:
path: /{_locale}/person/{person_id}/address/create
controller: Chill\PersonBundle\Controller\PersonAddressController::createAction
methods: [POST]
chill_person_address_new:
path: /{_locale}/person/{person_id}/address/new
controller: Chill\PersonBundle\Controller\PersonAddressController::newAction
chill_person_address_edit:
path: /{_locale}/person/{person_id}/address/{address_id}/edit
controller: Chill\PersonBundle\Controller\PersonAddressController::editAction
chill_person_address_update:
path: /{_locale}/person/{person_id}/address/{address_id}/update
controller: Chill\PersonBundle\Controller\PersonAddressController::updateAction
chill_person_timeline:
path: /{_locale}/person/{person_id}/timeline
controller: Chill\PersonBundle\Controller\TimelinePersonController::personAction
options:
menus:
person:
order: 60
label: Timeline
chill_person_admin:
path: "/{_locale}/admin/person"
controller: Chill\PersonBundle\Controller\AdminController::indexAction
chill_person_duplicate_view:
path: /{_locale}/person/{person_id}/duplicate/view
controller: Chill\PersonBundle\Controller\PersonDuplicateController::viewAction
chill_person_duplicate_confirm:
path: /{_locale}/person/{person1_id}/duplicate/{person2_id}/confirm
controller: Chill\PersonBundle\Controller\PersonDuplicateController::confirmAction
chill_person_duplicate_not_duplicate:
path: /{_locale}/person/{person1_id}/duplicate/{person2_id}/not-duplicate
controller: Chill\PersonBundle\Controller\PersonDuplicateController::notDuplicateAction
chill_person_remove_duplicate_not_duplicate:
path: /{_locale}/person/{person1_id}/duplicate/{person2_id}/remove-not-duplicate
controller: Chill\PersonBundle\Controller\PersonDuplicateController::removeNotDuplicateAction
chill_person_find_manually_duplicate:
path: /{_locale}/person/{person_id}/find-manually
controller: Chill\PersonBundle\Controller\PersonDuplicateController::findManuallyDuplicateAction
chill_person_admin_redirect_to_admin_index:
path: /{_locale}/admin/person_redirect_to_main
controller: Chill\PersonBundle\Controller\AdminController::redirectToAdminIndexAction
options:
menus:
admin_person:
order: 0
label: Main admin menu
chill_person_closingmotive_admin:
path: /{_locale}/admin/closing-motive
controller: cscrud_closing_motive_controller:index
@ -137,5 +17,5 @@ chill_person_maritalstatus_admin:
label: 'person_admin.marital status'
chill_person_controllers:
resource: "@ChillPersonBundle/Controller"
resource: "../src/Controller"
type: annotation

View File

@ -47,12 +47,12 @@ class AccompanyingPeriodController extends AbstractController
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var ValidatorInterface
*/
protected $validator;
/**
* AccompanyingPeriodController constructor.
*
@ -64,11 +64,17 @@ class AccompanyingPeriodController extends AbstractController
$this->eventDispatcher = $eventDispatcher;
$this->validator = $validator;
}
/**
* @Route(
* name="chill_person_accompanying_period_list",
* path="/{_locale}/person/{person_id}/accompanying-period"
* )
*/
public function listAction(int $person_id): Response
{
$person = $this->_getPerson($person_id);
$event = new PrivacyEvent($person, [
'element_class' => AccompanyingPeriod::class,
'action' => 'list'
@ -80,7 +86,13 @@ class AccompanyingPeriodController extends AbstractController
'person' => $person
]);
}
/**
* @Route(
* name="chill_person_accompanying_period_create",
* path="/{_locale}/person/{person_id}/accompanying-period/create"
* )
*/
public function createAction(int $person_id, Request $request): Response
{
$person = $this->_getPerson($person_id);
@ -90,17 +102,17 @@ class AccompanyingPeriodController extends AbstractController
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime('now'));
$accompanyingPeriod->setClosingDate(new \DateTime('now'));
$accompanyingPeriod->addPerson($person);
//or $person->addAccompanyingPeriod($accompanyingPeriod);
$form = $this->createForm(
AccompanyingPeriodType::class,
$accompanyingPeriod, [
'period_action' => 'create',
'center' => $person->getCenter()
]);
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
$errors = $this->_validatePerson($person);
@ -120,7 +132,7 @@ class AccompanyingPeriodController extends AbstractController
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]));
} else {
$flashBag->add('error', $this->get('translator')
->trans('Error! Period not created!'));
@ -137,9 +149,12 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $accompanyingPeriod
]);
}
/**
* @throws Exception
* @Route(
* name="chill_person_accompanying_period_update",
* path="/{_locale}/person/{person_id}/accompanying-period/{period_id}/update"
* )
*/
public function updateAction(int $person_id, int $period_id, Request $request): Response
{
@ -154,7 +169,7 @@ class AccompanyingPeriodController extends AbstractController
/** @var Person $person */
$person = $this->_getPerson($person_id);
// CHECK
if (! $accompanyingPeriod->containsPerson($person)) {
throw new Exception("Accompanying period " . $period_id . " does not contain person " . $person_id);
@ -176,7 +191,7 @@ class AccompanyingPeriodController extends AbstractController
if ($form->isValid(['Default', 'closed'])
&& count($errors) === 0) {
$em->flush();
$flashBag->add('success',
@ -186,9 +201,9 @@ class AccompanyingPeriodController extends AbstractController
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]));
} else {
$flashBag->add('error', $this->get('translator')
->trans('Error when updating the period'));
@ -204,19 +219,22 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $accompanyingPeriod
]);
}
/**
* @throws \Exception
* @Route(
* name="chill_person_accompanying_period_close",
* path="/{_locale}/person/{person_id}/accompanying-period/close"
* )
*/
public function closeAction(int $person_id, Request $request): Response
{
$person = $this->_getPerson($person_id);
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person');
if ($person->isOpen() === false) {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Beware period is closed', ['%name%' => $person->__toString()]
@ -229,7 +247,7 @@ class AccompanyingPeriodController extends AbstractController
}
$current = $person->getCurrentAccompanyingPeriod();
$form = $this->createForm(AccompanyingPeriodType::class, $current, [
'period_action' => 'close',
'center' => $person->getCenter()
@ -256,7 +274,7 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId()
])
);
} else {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
@ -267,7 +285,7 @@ class AccompanyingPeriodController extends AbstractController
->add('info', $error->getMessage());
}
}
} else { //if form is not valid
$this->get('session')->getFlashBag()
->add('error',
@ -288,7 +306,7 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $current
]);
}
private function _validatePerson(Person $person): ConstraintViolationListInterface
{
$errors = $this->validator->validate($person, null,
@ -296,10 +314,10 @@ class AccompanyingPeriodController extends AbstractController
// Can be disabled with config
if (false === $this->container->getParameter('chill_person.allow_multiple_simultaneous_accompanying_periods')) {
$errors_accompanying_period = $this->validator->validate($person, null,
['accompanying_period_consistent']);
foreach($errors_accompanying_period as $error ) {
$errors->add($error);
}
@ -307,7 +325,13 @@ class AccompanyingPeriodController extends AbstractController
return $errors;
}
/**
* @Route(
* name="chill_person_accompanying_period_open",
* path="/{_locale}/person/{person_id}/accompanying-period/open"
* )
*/
public function openAction(int $person_id, Request $request): Response
{
$person = $this->_getPerson($person_id);
@ -384,7 +408,13 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $accompanyingPeriod
]);
}
/**
* @Route(
* name="chill_person_accompanying_period_re_open",
* path="/{_locale}/person/{person_id}/accompanying-period/re-open"
* )
*/
public function reOpenAction(int $person_id, int $period_id, Request $request): Response
{
/** @var Person $person */
@ -417,13 +447,13 @@ class AccompanyingPeriodController extends AbstractController
return $this->redirectToRoute('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]);
} elseif ($confirm === false && $period->canBeReOpened($person)) {
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', [
'period' => $period,
'person' => $person
]);
} else {
return (new Response())
->setStatusCode(Response::HTTP_BAD_REQUEST)

View File

@ -13,16 +13,29 @@ use Symfony\Component\Routing\Annotation\Route;
class AdminController extends AbstractController
{
/**
* @param $_locale
* @return \Symfony\Component\HttpFoundation\Response
* @Route(
* name="chill_person_admin",
* path="/{_locale}/admin/person"
* )
*/
public function indexAction($_locale)
{
return $this->render('ChillPersonBundle:Admin:layout.html.twig', []);
}
/**
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @Route(
* name="chill_person_admin_redirect_to_admin_index",
* path="/{_locale}/admin/person_redirect_to_main",
* options={
* menus={
* admin_person={
* order="0",
* label="Main admin menu"
* }
* }
* }
* )
*/
public function redirectToAdminIndexAction()
{

View File

@ -30,6 +30,7 @@ use Chill\MainBundle\Entity\Address;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class PersonAddressController
@ -45,7 +46,7 @@ class PersonAddressController extends AbstractController
* @var ValidatorInterface
*/
protected $validator;
/**
* PersonAddressController constructor.
*
@ -55,7 +56,13 @@ class PersonAddressController extends AbstractController
{
$this->validator = $validator;
}
/**
* @Route(
* name="chill_person_address_list",
* path="/{_locale}/person/{person_id}/address/list"
* )
*/
public function listAction($person_id)
{
$person = $this->getDoctrine()->getManager()
@ -78,6 +85,13 @@ class PersonAddressController extends AbstractController
));
}
/**
* @Route(
* name="chill_person_address_create",
* path="/{_locale}/person/{person_id}/address/create",
* methods={"POST"}
* )
*/
public function newAction($person_id)
{
$person = $this->getDoctrine()->getManager()
@ -105,6 +119,12 @@ class PersonAddressController extends AbstractController
));
}
/**
* @Route(
* name="chill_person_address_new",
* path="/{_locale}/person/{person_id}/address/new"
* )
*/
public function createAction($person_id, Request $request)
{
$person = $this->getDoctrine()->getManager()
@ -161,6 +181,12 @@ class PersonAddressController extends AbstractController
));
}
/**
* @Route(
* name="chill_person_address_edit",
* path="/{_locale}/person/{person_id}/address/{address_id}/edit"
* )
*/
public function editAction($person_id, $address_id)
{
$person = $this->getDoctrine()->getManager()
@ -189,6 +215,12 @@ class PersonAddressController extends AbstractController
));
}
/**
* @Route(
* name="chill_person_address_update",
* path="/{_locale}/person/{person_id}/address/{address_id}/update"
* )
*/
public function updateAction($person_id, $address_id, Request $request)
{
$person = $this->getDoctrine()->getManager()

View File

@ -41,6 +41,7 @@ use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
final class PersonController extends AbstractController
{
@ -118,6 +119,12 @@ final class PersonController extends AbstractController
return $cFGroup;
}
/**
* @Route(
* name="chill_person_view",
* path="/{_locale}/person/{person_id}/general"
* )
*/
public function viewAction($person_id)
{
$person = $this->_getPerson($person_id);
@ -141,6 +148,12 @@ final class PersonController extends AbstractController
));
}
/**
* @Route(
* name="chill_person_general_edit",
* path="/{_locale}/person/{person_id}/general/edit"
* )
*/
public function editAction($person_id)
{
$person = $this->_getPerson($person_id);
@ -164,6 +177,12 @@ final class PersonController extends AbstractController
array('person' => $person, 'form' => $form->createView()));
}
/**
* @Route(
* name="chill_person_general_update",
* path="/{_locale}/person/{person_id}/general/update"
* )
*/
public function updateAction($person_id, Request $request)
{
$person = $this->_getPerson($person_id);
@ -207,6 +226,12 @@ final class PersonController extends AbstractController
}
}
/**
* @Route(
* name="chill_person_new",
* path="/{_locale}/person/new"
* )
*/
public function newAction()
{
// this is a dummy default center.
@ -291,6 +316,12 @@ final class PersonController extends AbstractController
return $errors;
}
/**
* @Route(
* name="chill_person_review",
* path="/{_locale}/person/review"
* )
*/
public function reviewAction(Request $request, PersonNotDuplicateRepository $personNotDuplicateRepository)
{
if ($request->getMethod() !== 'POST') {
@ -367,6 +398,12 @@ final class PersonController extends AbstractController
'form' => $form->createView()));
}
/**
* @Route(
* name="chill_person_create",
* path="/{_locale}/person/create"
* )
*/
public function createAction(Request $request)
{

View File

@ -12,7 +12,6 @@ use Chill\PersonBundle\Privacy\PrivacyEvent;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Search\SimilarPersonMatcher;
use http\Exception\InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\TranslatorInterface;
@ -21,8 +20,9 @@ use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\EventBundle\Entity\Participation;
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
use Chill\TaskBundle\Entity\SingleTask;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PersonDuplicateController extends Controller
class PersonDuplicateController extends AbstractController
{
/**
* @var \Chill\PersonBundle\Search\SimilarPersonMatcher
@ -63,6 +63,12 @@ class PersonDuplicateController extends Controller
$this->eventDispatcher = $eventDispatcher;
}
/**
* @Route(
* name="chill_person_duplicate_view",
* path="/{_locale}/person/{person_id}/duplicate/view"
* )
*/
public function viewAction($person_id, PersonNotDuplicateRepository $personNotDuplicateRepository)
{
$person = $this->_getPerson($person_id);
@ -86,6 +92,12 @@ class PersonDuplicateController extends Controller
]);
}
/**
* @Route(
* name="chill_person_duplicate_confirm",
* path="/{_locale}/person/{person1_id}/duplicate/{person2_id}/confirm"
* )
*/
public function confirmAction($person1_id, $person2_id, Request $request)
{
if ($person1_id === $person2_id) {
@ -143,6 +155,12 @@ class PersonDuplicateController extends Controller
]);
}
/**
* @Route(
* name="chill_person_duplicate_not_duplicate",
* path="/{_locale}/person/{person1_id}/duplicate/{person2_id}/not-duplicate"
* )
*/
public function notDuplicateAction($person1_id, $person2_id)
{
[$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id);
@ -166,6 +184,12 @@ class PersonDuplicateController extends Controller
return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]);
}
/**
* @Route(
* name="chill_person_remove_duplicate_not_duplicate",
* path="/{_locale}/person/{person1_id}/duplicate/{person2_id}/remove-not-duplicate"
* )
*/
public function removeNotDuplicateAction($person1_id, $person2_id)
{
[$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id);
@ -184,6 +208,12 @@ class PersonDuplicateController extends Controller
return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]);
}
/**
* @Route(
* name="chill_person_find_manually_duplicate",
* path="/{_locale}/person/{person_id}/find-manually"
* )
*/
public function findManuallyDuplicateAction($person_id, Request $request)
{
$person = $this->_getPerson($person_id);

View File

@ -27,6 +27,7 @@ use Symfony\Component\HttpFoundation\Request;
use Chill\MainBundle\Timeline\TimelineBuilder;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class TimelinePersonController
@ -68,8 +69,21 @@ class TimelinePersonController extends AbstractController
$this->timelineBuilder = $timelineBuilder;
$this->paginatorFactory = $paginatorFactory;
}
/**
* @Route(
* name="chill_person_timeline",
* path="/{_locale}/person/{person_id}/timeline",
* options={
* menus={
* person={
* order="60",
* label="Timeline"
* }
* }
* }
* )
*/
public function personAction(Request $request, $person_id)
{
$person = $this->getDoctrine()