Add PersonResource audit functionality

- Implemented `PersonResourceSubjectDisplayer` to provide display logic for `PersonResource` audits.
- Added `PersonResourceSubjectConverter` to handle conversion to `Subject` format.
- Created Twig template `person_resource.html.twig` for rendering `PersonResource` audit display.
This commit is contained in:
2026-02-26 14:14:51 +01:00
parent 1d4d90e48a
commit 88235c0fa2
4 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?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\Audit\Displayer;
use Chill\MainBundle\Audit\Subject;
use Chill\MainBundle\Audit\SubjectDisplayerInterface;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderManagerInterface;
use Chill\PersonBundle\Repository\PersonResourceRepository;
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
final readonly class PersonResourceSubjectDisplayer implements SubjectDisplayerInterface
{
public function __construct(
private Environment $twig,
private TranslatorInterface $translator,
private PersonResourceRepository $personResourceRepository,
private PersonRenderInterface $personRender,
private ChillEntityRenderManagerInterface $chillEntityRenderManager,
) {}
public function supportsDisplay(Subject $subject, array $optons = []): bool
{
return 'person_resource' === $subject->type;
}
public function display(Subject $subject, string $format = 'html', array $options = []): string
{
$resource = $this->personResourceRepository->find($subject->identifiers['id']);
if ('string' === $format) {
return $this->translator->trans('audit.person_resource.person_resource_number', [
'{id}' => $subject->identifiers['id'],
'{name}' => null === $resource ? '' : $this->chillEntityRenderManager->renderString($resource->getAssociated(), []),
]);
}
return $this->twig->render('@ChillPerson/Audit/person_resource.html.twig', [
'id' => $subject->identifiers['id'], 'resource' => $resource]);
}
}

View File

@@ -0,0 +1,46 @@
<?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\Audit\SubjectConverter;
use Chill\MainBundle\Audit\Subject;
use Chill\MainBundle\Audit\SubjectBag;
use Chill\MainBundle\Audit\SubjectConverterInterface;
use Chill\MainBundle\Audit\SubjectConverterManagerAwareInterface;
use Chill\MainBundle\Audit\SubjectConverterManagerAwareTrait;
use Chill\PersonBundle\Entity\Person\PersonResource;
final class PersonResourceSubjectConverter implements SubjectConverterInterface, SubjectConverterManagerAwareInterface
{
use SubjectConverterManagerAwareTrait;
public function convert(mixed $subject, bool $includeAssociated = false): SubjectBag
{
/** @var PersonResource $subject */
$bag = new SubjectBag(new Subject('person_resource', ['id' => $subject->getId()]));
if ($includeAssociated) {
// $bag->append($this->subjectConverterManager->getSubjectsForEntity($subject->getPerson(), false));
}
return $bag;
}
public function supportsConvert(mixed $subject): bool
{
return $subject instanceof PersonResource;
}
public static function getDefaultPriority(): int
{
return 0;
}
}

View File

@@ -0,0 +1 @@
<span>{{ 'audit.person_resource.person_resource_number'|trans({'{id}': id, '{name}': resource is same as null ? 'unknown' : resource.associated|chill_entity_render_string}) }}</span>

View File

@@ -1582,3 +1582,6 @@ audit:
accompanying_period_number: "Parcours n°{id}"
accompanying_period_work:
accompanying_period_work_number: "Action d'accompagnement n°{id}"
person_resource:
list: Liste des personnes ressources
person_resource_number: "Personne ressource n°{id}: {name}"