mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Split crud controllers for each report entity
This commit is contained in:
parent
454ab73303
commit
6f55ba15d6
@ -79,6 +79,7 @@ class CSCrudReportController extends EntityPersonCRUDController
|
||||
|
||||
protected function createFormFor(string $action, $entity, ?string $formClass = null, array $formOptions = []): FormInterface
|
||||
{
|
||||
dump($entity);
|
||||
if ($entity instanceof Immersion) {
|
||||
if ('edit' === $action || 'new' === $action) {
|
||||
return parent::createFormFor($action, $entity, $formClass, [
|
||||
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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\JobBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\CRUD\Controller\EntityPersonCRUDController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\JobBundle\Entity\Immersion;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* CRUD Controller for reports (Frein, ...).
|
||||
*/
|
||||
class CVCrudController extends EntityPersonCRUDController
|
||||
{
|
||||
protected function onBeforeRedirectAfterSubmission(string $action, $entity, FormInterface $form, Request $request): ?Response
|
||||
{
|
||||
$next = $request->request->get('submit', 'save-and-close');
|
||||
|
||||
return match ($next) {
|
||||
'save-and-close', 'delete-and-close' => $this->redirectToRoute('chill_job_report_index', [
|
||||
'person' => $entity->getPerson()->getId(),
|
||||
]),
|
||||
default => parent::onBeforeRedirectAfterSubmission($action, $entity, $form, $request),
|
||||
};
|
||||
}
|
||||
|
||||
protected function duplicateEntity(string $action, Request $request)
|
||||
{
|
||||
if ('cv' === $this->getCrudName()) {
|
||||
$id = $request->query->get('duplicate_id', 0);
|
||||
/** @var \Chill\JobBundle\Entity\CV $cv */
|
||||
$cv = $this->getEntity($action, $id, $request);
|
||||
$em = $this->managerRegistry->getManager();
|
||||
|
||||
$em->detach($cv);
|
||||
|
||||
foreach ($cv->getExperiences() as $experience) {
|
||||
$cv->removeExperience($experience);
|
||||
$em->detach($experience);
|
||||
$cv->addExperience($experience);
|
||||
}
|
||||
foreach ($cv->getFormations() as $formation) {
|
||||
$cv->removeFormation($formation);
|
||||
$em->detach($formation);
|
||||
$cv->addFormation($formation);
|
||||
}
|
||||
|
||||
return $cv;
|
||||
}
|
||||
|
||||
return parent::duplicateEntity($action, $request);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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\JobBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\CRUD\Controller\EntityPersonCRUDController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\JobBundle\Entity\Immersion;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* CRUD Controller for reports (Frein, ...).
|
||||
*/
|
||||
class FreinCrudController extends EntityPersonCRUDController
|
||||
{
|
||||
protected function onBeforeRedirectAfterSubmission(string $action, $entity, FormInterface $form, Request $request): ?Response
|
||||
{
|
||||
$next = $request->request->get('submit', 'save-and-close');
|
||||
|
||||
return match ($next) {
|
||||
'save-and-close', 'delete-and-close' => $this->redirectToRoute('chill_job_report_index', [
|
||||
'person' => $entity->getPerson()->getId(),
|
||||
]),
|
||||
default => parent::onBeforeRedirectAfterSubmission($action, $entity, $form, $request),
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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\JobBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\CRUD\Controller\EntityPersonCRUDController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\JobBundle\Entity\Immersion;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* CRUD Controller for reports (Frein, ...).
|
||||
*/
|
||||
class ImmersionCrudController extends EntityPersonCRUDController
|
||||
{
|
||||
protected function onBeforeRedirectAfterSubmission(string $action, $entity, FormInterface $form, Request $request): ?Response
|
||||
{
|
||||
$next = $request->request->get('submit', 'save-and-close');
|
||||
|
||||
return match ($next) {
|
||||
'save-and-close', 'delete-and-close' => $this->redirectToRoute('chill_job_report_index', [
|
||||
'person' => $entity->getPerson()->getId(),
|
||||
]),
|
||||
default => parent::onBeforeRedirectAfterSubmission($action, $entity, $form, $request),
|
||||
};
|
||||
}
|
||||
|
||||
protected function createFormFor(string $action, $entity, ?string $formClass = null, array $formOptions = []): FormInterface
|
||||
{
|
||||
if ($entity instanceof Immersion) {
|
||||
if ('edit' === $action || 'new' === $action) {
|
||||
return parent::createFormFor($action, $entity, $formClass, [
|
||||
'center' => $entity->getPerson()->getCenter(),
|
||||
]);
|
||||
}
|
||||
if ('bilan' === $action) {
|
||||
return parent::createFormFor($action, $entity, $formClass, [
|
||||
'center' => $entity->getPerson()->getCenter(),
|
||||
'step' => 'bilan',
|
||||
]);
|
||||
}
|
||||
if ('delete' === $action) {
|
||||
return parent::createFormFor($action, $entity, $formClass, $formOptions);
|
||||
}
|
||||
throw new \LogicException("this step {$action} is not supported");
|
||||
}
|
||||
|
||||
return parent::createFormFor($action, $entity, $formClass, $formOptions);
|
||||
}
|
||||
|
||||
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
// for immersion / edit-bilan action
|
||||
if ('bilan' === $action) {
|
||||
/* @var $entity Immersion */
|
||||
$entity->setIsBilanFullfilled(true);
|
||||
}
|
||||
|
||||
parent::onPreFlush($action, $entity, $form, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit immersion bilan.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function editBilan(Request $request, $id): Response
|
||||
{
|
||||
return $this->formEditAction('bilan', $request, $id);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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\JobBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\CRUD\Controller\EntityPersonCRUDController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\JobBundle\Entity\Immersion;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* CRUD Controller for reports (Frein, ...).
|
||||
*/
|
||||
class ProjetProfessionnelCrudController extends EntityPersonCRUDController
|
||||
{
|
||||
protected function onBeforeRedirectAfterSubmission(string $action, $entity, FormInterface $form, Request $request): ?Response
|
||||
{
|
||||
$next = $request->request->get('submit', 'save-and-close');
|
||||
|
||||
return match ($next) {
|
||||
'save-and-close', 'delete-and-close' => $this->redirectToRoute('chill_job_report_index', [
|
||||
'person' => $entity->getPerson()->getId(),
|
||||
]),
|
||||
default => parent::onBeforeRedirectAfterSubmission($action, $entity, $form, $request),
|
||||
};
|
||||
}
|
||||
|
||||
protected function duplicateEntity(string $action, Request $request)
|
||||
{
|
||||
if ('projet_prof' === $this->getCrudName()) {
|
||||
$id = $request->query->get('duplicate_id', 0);
|
||||
/** @var \Chill\JobBundle\Entity\ProjetProfessionnel $original */
|
||||
$original = $this->getEntity($action, $id, $request);
|
||||
|
||||
$new = parent::duplicateEntity($action, $request);
|
||||
|
||||
foreach ($original->getSouhait() as $s) {
|
||||
$new->addSouhait($s);
|
||||
}
|
||||
foreach ($original->getValide() as $s) {
|
||||
$new->addValide($s);
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
return parent::duplicateEntity($action, $request);
|
||||
}
|
||||
}
|
@ -13,6 +13,10 @@ namespace Chill\JobBundle\DependencyInjection;
|
||||
|
||||
use Chill\JobBundle\Controller\CSCrudReportController;
|
||||
use Chill\JobBundle\Controller\CSPersonController;
|
||||
use Chill\JobBundle\Controller\CVCrudController;
|
||||
use Chill\JobBundle\Controller\FreinCrudController;
|
||||
use Chill\JobBundle\Controller\ImmersionCrudController;
|
||||
use Chill\JobBundle\Controller\ProjetProfessionnelCrudController;
|
||||
use Chill\JobBundle\Entity\CSPerson;
|
||||
use Chill\JobBundle\Entity\CV;
|
||||
use Chill\JobBundle\Entity\Frein;
|
||||
@ -72,7 +76,7 @@ class ChillJobExtension extends Extension implements PrependExtensionInterface
|
||||
],
|
||||
[
|
||||
'class' => CV::class,
|
||||
'controller' => CSCrudReportController::class,
|
||||
'controller' => CVCrudController::class,
|
||||
'name' => 'cscv',
|
||||
'base_role' => 'ROLE_USER',
|
||||
'base_path' => '/person/report/cv',
|
||||
@ -94,7 +98,7 @@ class ChillJobExtension extends Extension implements PrependExtensionInterface
|
||||
],
|
||||
[
|
||||
'class' => ProjetProfessionnel::class,
|
||||
'controller' => CSCrudReportController::class,
|
||||
'controller' => ProjetProfessionnelCrudController::class,
|
||||
'name' => 'projet_prof',
|
||||
'base_role' => 'ROLE_USER',
|
||||
'base_path' => '/person/report/projet-professionnel',
|
||||
@ -116,7 +120,7 @@ class ChillJobExtension extends Extension implements PrependExtensionInterface
|
||||
],
|
||||
[
|
||||
'class' => Frein::class,
|
||||
'controller' => CSCrudReportController::class,
|
||||
'controller' => FreinCrudController::class,
|
||||
'name' => 'csfrein',
|
||||
'base_role' => 'ROLE_USER',
|
||||
'base_path' => '/person/report/frein',
|
||||
@ -138,7 +142,7 @@ class ChillJobExtension extends Extension implements PrependExtensionInterface
|
||||
],
|
||||
[
|
||||
'class' => Immersion::class,
|
||||
'controller' => CSCrudReportController::class,
|
||||
'controller' => ImmersionCrudController::class,
|
||||
'name' => 'immersion',
|
||||
'base_role' => 'ROLE_USER',
|
||||
'base_path' => '/person/report/immersion',
|
||||
|
@ -1,13 +1,8 @@
|
||||
services:
|
||||
Chill\JobBundle\Controller\CSReportController:
|
||||
autoconfigure: true
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
Chill\JobBundle\Controller\:
|
||||
resource: '../../../Controller'
|
||||
tags: ['controller.service_arguments']
|
||||
Chill\JobBundle\Controller\CSPersonController:
|
||||
autoconfigure: true
|
||||
autowire: true
|
||||
tags: ['controller.service_arguments']
|
||||
Chill\JobBundle\Controller\CSCrudReportController:
|
||||
autoconfigure: true
|
||||
autowire: true
|
||||
tags: [ 'controller.service_arguments' ]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user