mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
Add jobBundle and FranceTravailApiBundle
This commit is contained in:
151
src/Bundle/ChillJobBundle/src/Controller/CSPersonController.php
Normal file
151
src/Bundle/ChillJobBundle/src/Controller/CSPersonController.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\ChillJobBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\CRUD\Controller\OneToOneEntityPersonCRUDController;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\ChillJobBundle\Form\CSPersonPersonalSituationType;
|
||||
use Chill\ChillJobBundle\Form\CSPersonDispositifsType;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CSPersonController extends OneToOneEntityPersonCRUDController
|
||||
{
|
||||
public function personalSituationEdit(Request $request, $id)
|
||||
{
|
||||
return $this->formEditAction(
|
||||
'ps_situation_edit',
|
||||
$request,
|
||||
$id,
|
||||
CSPersonPersonalSituationType::class
|
||||
);
|
||||
}
|
||||
|
||||
public function dispositifsEdit(Request $request, $id)
|
||||
{
|
||||
return $this->formEditAction(
|
||||
'dispositifs_edit',
|
||||
$request,
|
||||
$id,
|
||||
CSPersonDispositifsType::class
|
||||
);
|
||||
}
|
||||
|
||||
public function personalSituationView(Request $request, $id): Response
|
||||
{
|
||||
return $this->viewAction('ps_situation_view', $request, $id);
|
||||
}
|
||||
|
||||
public function dispositifsView(Request $request, $id): Response
|
||||
{
|
||||
return $this->viewAction('dispositifs_view', $request, $id);
|
||||
}
|
||||
|
||||
protected function generateRedirectOnCreateRoute($action, Request $request, $entity)
|
||||
{
|
||||
switch($action) {
|
||||
case 'ps_situation_view':
|
||||
$route = 'chill_crud_csperson_personal_situation_edit';
|
||||
break;
|
||||
case 'dispositifs_view':
|
||||
$route = 'chill_crud_csperson_dispositifs_edit';
|
||||
break;
|
||||
default:
|
||||
parent::generateRedirectOnCreateRoute($action, $request, $entity);
|
||||
}
|
||||
|
||||
return $this->generateUrl($route, ['id' => $entity->getPerson()->getId()]);
|
||||
}
|
||||
|
||||
protected function checkACL($action, $entity)
|
||||
{
|
||||
switch($action) {
|
||||
case 'ps_situation_edit':
|
||||
case 'dispositifs_edit':
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE,
|
||||
$entity->getPerson());
|
||||
break;
|
||||
case 'ps_situation_view':
|
||||
case 'dispositifs_view':
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE,
|
||||
$entity->getPerson());
|
||||
break;
|
||||
default:
|
||||
parent::checkACL($action, $entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected function onBeforeRedirectAfterSubmission(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
switch($action) {
|
||||
case 'ps_situation_edit':
|
||||
return $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_personal_situation_view',
|
||||
['id' => $entity->getId()]);
|
||||
|
||||
case 'dispositifs_edit':
|
||||
return $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_dispositifs_view',
|
||||
['id' => $entity->getId()]);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getTemplateFor($action, $entity, Request $request)
|
||||
{
|
||||
switch ($action) {
|
||||
case 'ps_situation_edit':
|
||||
return '@CSConnectesSP/CSPerson/personal_situation_edit.html.twig';
|
||||
case 'dispositifs_edit':
|
||||
return '@CSConnectesSP/CSPerson/dispositifs_edit.html.twig';
|
||||
case 'ps_situation_view':
|
||||
return '@CSConnectesSP/CSPerson/personal_situation_view.html.twig';
|
||||
case 'dispositifs_view':
|
||||
return '@CSConnectesSP/CSPerson/dispositifs_view.html.twig';
|
||||
default:
|
||||
parent::getTemplateFor($action, $entity, $request);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createFormFor(string $action, $entity, string $formClass = null, array $formOptions = []): FormInterface
|
||||
{
|
||||
switch ($action) {
|
||||
case 'dispositifs_edit':
|
||||
$form = $this->createForm($formClass, $entity, \array_merge(
|
||||
$formOptions, [ 'center' => $entity->getPerson()->getCenter() ]));
|
||||
$this->customizeForm($action, $form);
|
||||
|
||||
return $form;
|
||||
|
||||
case 'ps_situation_edit':
|
||||
$form = $this->createForm($formClass, $entity, \array_merge(
|
||||
$formOptions, [ 'center' => $entity->getPerson()->getCenter() ]));
|
||||
$this->customizeForm($action, $form);
|
||||
|
||||
return $form;
|
||||
|
||||
default:
|
||||
return parent::createFormFor($action, $entity, $formClass, $formOptions);
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateLabelForButton($action, $formName, $form)
|
||||
{
|
||||
switch($action):
|
||||
case 'ps_situation_edit':
|
||||
case 'dispositifs_edit':
|
||||
if ($formName === 'submit') {
|
||||
return 'Enregistrer';
|
||||
} else {
|
||||
throw new \LogicException("this formName is not supported: $formName");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return parent::generateLabelForButton($action, $formName, $form);
|
||||
endswitch;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user