WIP fusion accompanyingperiodwork: controller, form, templates

This commit is contained in:
Julie Lenaerts 2025-02-17 09:21:29 +01:00
parent 0d0f3528e2
commit 49d1f78001
5 changed files with 215 additions and 0 deletions

View File

@ -0,0 +1,77 @@
<?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\PersonBundle\Controller;
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\Contracts\Translation\TranslatorInterface;
class AccompanyingPeriodWorkDuplicateController extends AbstractController
{
public function __construct(private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, private readonly TranslatorInterface $translator) {}
#[Route(path: '{_locale}/person/accompanying-period/work/{id}/assign-duplicate', name: 'chill_person_accompanying_period_work_assign_duplicate', methods: ['GET'])]
public function assignDuplicate(mixed $id, Request $request)
{
$acpw1= $this->accompanyingPeriodWorkRepository->find($id);
if (null === $acpw1) {
throw $this->createNotFoundException("Accompanying period work with id {$id} not".' found on this server');
}
$this->denyAccessUnlessGranted(
'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE',
$acpw1,
'You are not allowed to merge this accompanying period work'
);
$form = $this->createForm(FindAccompanyingPeriodWorkType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$acpw2 = $form->get('person')->getData();
// Validation: Ensure person1 is not the same as person2
if ($acpw1->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()]);
}
$direction = $form->get('direction')->getData();
if ('starting' === $direction) {
$params = [
'acpw1_id' => $acpw1->getId(),
'acpw2_id' => $acpw2->getId(),
];
} else {
$params = [
'acpw1_id' => $acpw2->getId(),
'acpw2_id' => $acpw1->getId(),
];
}
// return $this->redirectToRoute('chill_person_acpw_duplicate_confirm', $params);
}
return $this->render('@ChillPerson/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig', [
'accompanyingCourse' => $acpw1->getAccompanyingPeriod(),
'acpw' => $acpw1,
'form' => $form->createView(),
]);
}
}

View File

@ -0,0 +1,29 @@
<?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\PersonBundle\Form;
use Chill\PersonBundle\Form\Type\PickAccompanyingPeriodWorkDynamicType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class FindAccompanyingPeriodWorkType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('acpw', PickAccompanyingPeriodWorkDynamicType::class)
->add('direction', HiddenType::class, [
'data' => 'starting',
]);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Chill\PersonBundle\Form\Type;
use Chill\MainBundle\Form\Type\DataTransformer\EntityToJsonTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;
class PickAccompanyingPeriodWorkDynamicType extends AbstractType
{
public function __construct(private readonly DenormalizerInterface $denormalizer, private readonly SerializerInterface $serializer) {}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'accompanyingPeriodWork'));
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['types'] = ['accompanyingPeriodWork'];
$view->vars['uniqid'] = uniqid('pick_acpw_dyn');
$view->vars['as_id'] = true === $options['as_id'] ? '1' : '0';
$view->vars['submit_on_adding_new_entity'] = true === $options['submit_on_adding_new_entity'] ? '1' : '0';
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('multiple', false)
->setAllowedTypes('multiple', ['bool'])
->setDefault('compound', false)
->setDefault('suggested', [])
->setDefault('as_id', false)
->setAllowedTypes('as_id', ['bool'])
->setDefault('submit_on_adding_new_entity', false)
->setAllowedTypes('submit_on_adding_new_entity', ['bool']);
}
public function getBlockPrefix()
{
return 'pick_entity_dynamic';
}
}

View File

@ -0,0 +1,22 @@
<template>
<div class="item-row">
<div class="item-col">
<h4 class="badge-title">
<span class="title_action">
{{ accompanyingPeriodWork.socialAction.title.fr }}
</span>
</h4>
</div>
</div>
</template>
<script setup lang="ts">
import TypeAccompanyingPeriodWork from "ChillPersonAssets/vuejs/_components/AddPersons/TypeAccompanyingPeriodWork.vue";
const props = defineProps({
accompanyingPeriodWork: TypeAccompanyingPeriodWork
})
</script>

View File

@ -0,0 +1,38 @@
{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %}
{% set activeRouteKey = 'chill_person_accompanying_period_work_assign_duplicate' %}
{% block title %}{{ 'Assign an accompanying period work duplicate' }}{% endblock %}
{% block content %}
<div class="person-duplicate">
<h1>{{ 'Assign an accompanying period work duplicate'|trans }}</h1>
{{ form_start(form) }}
{{ form_rest(form) }}
<ul class="record_actions sticky-form-buttons">
<li class="cancel">
<a href="{{ path('chill_person_accompanying_period_work_show', {'id' : acpw.id}) }}" class="btn btn-cancel">
{{ 'Return'|trans }}
</a>
</li>
<li>
<button class="btn btn-save" type="submit">{{ 'Next'|trans }}</button>
</li>
</ul>
{{ form_end(form) }}
</div>
{% endblock %}
{% block js %}
{{ encore_entry_script_tags('mod_pickentity_type') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_pickentity_type') }}
{% endblock %}