mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
Different approach to creating acpw selector
This commit is contained in:
@@ -11,30 +11,38 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Form\FindAccompanyingPeriodWorkType;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
class AccompanyingPeriodWorkDuplicateController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, private readonly TranslatorInterface $translator) {}
|
||||
public function __construct(private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, private readonly TranslatorInterface $translator, private readonly SerializerInterface $serializer) {}
|
||||
|
||||
/**
|
||||
* @ParamConverter("accompanyingPeriodWork", options={"id": "acpw_id"})
|
||||
*/
|
||||
#[Route(path: '{_locale}/person/accompanying-period/work/{id}/assign-duplicate', name: 'chill_person_accompanying_period_work_assign_duplicate', methods: ['GET'])]
|
||||
public function assignDuplicate(int $id, Request $request)
|
||||
public function assignDuplicate(AccompanyingPeriodWork $acpw, Request $request)
|
||||
{
|
||||
$acpw1= $this->accompanyingPeriodWorkRepository->find($id);
|
||||
$accompanyingPeriod = $acpw1->getAccompanyingPeriod();
|
||||
$accompanyingPeriod = $acpw->getAccompanyingPeriod();
|
||||
|
||||
if (null === $acpw1) {
|
||||
throw $this->createNotFoundException("Accompanying period work with id {$id} not".' found on this server');
|
||||
}
|
||||
$acpwList = $this->accompanyingPeriodWorkRepository->findByAccompanyingPeriod($accompanyingPeriod);
|
||||
|
||||
$acpwListArray = $this->serializer->normalize($acpwList, 'json', ['groups' => ['read']]);
|
||||
$acpwListJson = json_encode($acpwListArray);
|
||||
|
||||
dump($acpwListJson);
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE',
|
||||
$acpw1,
|
||||
$acpw,
|
||||
'You are not allowed to merge this accompanying period work'
|
||||
);
|
||||
|
||||
@@ -46,23 +54,23 @@ class AccompanyingPeriodWorkDuplicateController extends AbstractController
|
||||
$acpw2 = $form->get('person')->getData();
|
||||
|
||||
// Validation: Ensure person1 is not the same as person2
|
||||
if ($acpw1->getId() === $acpw2->getId()) {
|
||||
if ($acpw->getId() === $acpw2->getId()) {
|
||||
$this->addFlash('error', $this->translator->trans('The entities you are trying to merge cannot be the same'));
|
||||
|
||||
return $this->redirectToRoute('chill_person_accompanying_period_work_show', ['id' => $acpw1->getId()]);
|
||||
return $this->redirectToRoute('chill_person_accompanying_period_work_show', ['id' => $acpw->getId()]);
|
||||
}
|
||||
|
||||
$direction = $form->get('direction')->getData();
|
||||
|
||||
if ('starting' === $direction) {
|
||||
$params = [
|
||||
'acpw1_id' => $acpw1->getId(),
|
||||
'acpw1_id' => $acpw->getId(),
|
||||
'acpw2_id' => $acpw2->getId(),
|
||||
];
|
||||
} else {
|
||||
$params = [
|
||||
'acpw1_id' => $acpw2->getId(),
|
||||
'acpw2_id' => $acpw1->getId(),
|
||||
'acpw2_id' => $acpw->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -70,8 +78,9 @@ class AccompanyingPeriodWorkDuplicateController extends AbstractController
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig', [
|
||||
'accompanyingCourse' => $acpw1->getAccompanyingPeriod(),
|
||||
'acpw' => $acpw1,
|
||||
'accompanyingCourse' => $acpw->getAccompanyingPeriod(),
|
||||
'acpwListJson' => $acpwListJson,
|
||||
'acpw' => $acpw,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user