Add audit functionality for Activity actions

- Introduced `ActivityDisplayer` and `ActivitySubjectConverter` for handling audit display and conversion logic.
- Integrated `TriggerAuditInterface` in `ActivityController` and added audit triggers for create, list, update, delete, and view actions with translatable descriptions.
- Updated `services.yaml` to register new audit-related services.
- Enhanced French translations with audit-related labels for `Activity`.
This commit is contained in:
2026-02-27 16:13:37 +01:00
parent 546d5bf1f7
commit e28dc355e8
6 changed files with 134 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
<?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\ActivityBundle\Audit\Displayer;
use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\MainBundle\Audit\Subject;
use Chill\MainBundle\Audit\SubjectDisplayerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
final class ActivityDisplayer implements SubjectDisplayerInterface
{
public function __construct(
private readonly TranslatorInterface $translator,
private readonly ActivityRepository $activityRepository,
private readonly TranslatableStringHelperInterface $translatableStringHelper,
) {}
public function supportsDisplay(Subject $subject, array $options = []): bool
{
return 'activity' === $subject->type;
}
public function display(Subject $subject, string $format = 'html', array $options = []): string
{
$activity = $this->activityRepository->find($subject->identifiers['id']);
if (null === $activity) {
$label = $this->translator->trans('audit.activity.subject', ['id' => $subject->identifiers['id']], 'messages');
} else {
$label = $this->translator->trans('audit.activity.subject_with_details', [
'id' => $subject->identifiers['id'],
'date' => $activity->getDate(),
'type' => $this->translatableStringHelper->localize($activity->getActivityType()->getName()),
], 'messages');
}
return 'html' === $format ? '<span>'.$label.'</span>' : $label;
}
}