mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-03 04:29:40 +00:00
WIP: render entities
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?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\MainBundle\Audit\Exception;
|
||||
|
||||
class DisplaySubjectException extends \LogicException
|
||||
{
|
||||
public function __construct(array $subject)
|
||||
{
|
||||
parent::__construct(sprintf('Subject "%s" could not be displayed', json_encode($subject['subject'], JSON_THROW_ON_ERROR, 5)));
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,15 @@ class Subject
|
||||
return [...$this->identifiers, 't' => $this->type];
|
||||
}
|
||||
|
||||
public static function fromArray(array $subject): self
|
||||
{
|
||||
return new self($subject['t'], array_filter(
|
||||
$subject,
|
||||
static fn (string $key) => 't' !== $key,
|
||||
ARRAY_FILTER_USE_KEY
|
||||
));
|
||||
}
|
||||
|
||||
public function isEqual(Subject $subject): bool
|
||||
{
|
||||
if ($subject->type !== $this->type) {
|
||||
|
||||
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Audit;
|
||||
|
||||
use Chill\MainBundle\Audit\Exception\ConvertSubjectException;
|
||||
use Chill\MainBundle\Audit\Exception\DisplaySubjectException;
|
||||
|
||||
final readonly class SubjectConverterManager implements SubjectConverterManagerInterface
|
||||
{
|
||||
@@ -20,6 +21,11 @@ final readonly class SubjectConverterManager implements SubjectConverterManagerI
|
||||
* @var iterable<SubjectConverterInterface>
|
||||
*/
|
||||
private iterable $converters,
|
||||
|
||||
/**
|
||||
* @var iterable<SubjectDisplayerInterface>
|
||||
*/
|
||||
private iterable $displayers,
|
||||
) {}
|
||||
|
||||
public function getSubjectsForEntity(mixed $subject, bool $includeAssociated = false): SubjectBag
|
||||
@@ -36,4 +42,15 @@ final readonly class SubjectConverterManager implements SubjectConverterManagerI
|
||||
|
||||
throw new ConvertSubjectException($subject);
|
||||
}
|
||||
|
||||
public function display(Subject $subject, array $options = []): string
|
||||
{
|
||||
foreach ($this->displayers as $displayer) {
|
||||
if ($displayer->supportsDisplay($subject, $options = [])) {
|
||||
return $displayer->display($subject, $options = []);
|
||||
}
|
||||
}
|
||||
|
||||
throw new DisplaySubjectException($subject->asArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ namespace Chill\MainBundle\Audit;
|
||||
interface SubjectConverterManagerInterface
|
||||
{
|
||||
public function getSubjectsForEntity(object $subject, bool $includeAssociated = false): SubjectBag;
|
||||
|
||||
public function display(Subject $subject): string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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\MainBundle\Audit;
|
||||
|
||||
/**
|
||||
* Interface for displaying a given Subject instance as html with optional configurations.
|
||||
*/
|
||||
interface SubjectDisplayerInterface
|
||||
{
|
||||
public function supportsDisplay(Subject $subject, array $optons = []): bool;
|
||||
|
||||
/**
|
||||
* Render a Subject as an HTML string.
|
||||
*
|
||||
* @return string an html string
|
||||
*/
|
||||
public function display(Subject $subject, array $options = []): string;
|
||||
}
|
||||
@@ -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\MainBundle\Audit\Twig;
|
||||
|
||||
use Chill\MainBundle\Audit\Subject;
|
||||
use Chill\MainBundle\Audit\SubjectConverterManagerInterface;
|
||||
use Twig\Extension\RuntimeExtensionInterface;
|
||||
|
||||
final readonly class SubjectRenderRuntimeTwig implements RuntimeExtensionInterface
|
||||
{
|
||||
public function __construct(private SubjectConverterManagerInterface $subjectConverterManager) {}
|
||||
|
||||
public function renderAuditSubject(array|Subject $subject, array $options = []): string
|
||||
{
|
||||
return $this->subjectConverterManager->display(
|
||||
$subject instanceof Subject ? $subject : Subject::fromArray($subject),
|
||||
$options
|
||||
);
|
||||
}
|
||||
}
|
||||
25
src/Bundle/ChillMainBundle/Audit/Twig/SubjectRenderTwig.php
Normal file
25
src/Bundle/ChillMainBundle/Audit/Twig/SubjectRenderTwig.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\MainBundle\Audit\Twig;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
final class SubjectRenderTwig extends AbstractExtension
|
||||
{
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('chill_render_audit_subject', [SubjectRenderRuntimeTwig::class, 'renderAuditSubject'], ['is_safe' => ['html']]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle;
|
||||
|
||||
use Chill\MainBundle\Audit\SubjectConverterInterface;
|
||||
use Chill\MainBundle\Audit\SubjectDisplayerInterface;
|
||||
use Chill\MainBundle\Cron\CronJobInterface;
|
||||
use Chill\MainBundle\CRUD\CompilerPass\CRUDControllerCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\ACLFlagsCompilerPass;
|
||||
@@ -67,6 +68,8 @@ class ChillMainBundle extends Bundle
|
||||
->addTag('chill_main.notification_flag_provider');
|
||||
$container->registerForAutoconfiguration(SubjectConverterInterface::class)
|
||||
->addTag('chill_main.audit_subject_converter');
|
||||
$container->registerForAutoconfiguration(SubjectDisplayerInterface::class)
|
||||
->addTag('chill_main.audit_subject_displayer');
|
||||
|
||||
$container->addCompilerPass(new SearchableServicesCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
|
||||
$container->addCompilerPass(new ConfigConsistencyCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Repository\AuditTrailRepository;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Twig\Environment;
|
||||
|
||||
final class AuditTrailSearchController
|
||||
{
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private AuditTrailRepository $auditTrailRepository,
|
||||
private FilterOrderHelperFactoryInterface $filterOrderHelperFactory,
|
||||
private Environment $twig,
|
||||
) {}
|
||||
|
||||
#[Route('/{_locale}/main/audit-trail/list', name: 'chill_main_audit_trail_list')]
|
||||
public function list(Request $request): Response
|
||||
{
|
||||
$auditTrails = $this->auditTrailRepository->findByCriteria([]);
|
||||
|
||||
return new Response($this->twig->render('@ChillMain/AuditTrail/list.html.twig', [
|
||||
'auditTrails' => $auditTrails,
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<div class="item-bloc">
|
||||
<div class="item-row">
|
||||
<div class="item-two-col-grid">
|
||||
<div class="title">
|
||||
<div>{{ audit.mainSubject|chill_render_audit_subject }} | {{ ('audit_trail.action.'~audit.action)|trans }}{% if audit.description is not empty %} | {{ audit.description }}{% endif %}</div>
|
||||
{% if audit.user %}<div><span class="badge-user">{{ audit.user|chill_entity_render_box({'at_date': audit.occurredAt}) }}</span></div>{% endif %}
|
||||
</div>
|
||||
<div class="aside text-md-end">
|
||||
{{ audit.occurredAt|format_datetime('medium', 'medium') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if audit.subjects|length > 0 %}
|
||||
<div class="item-row">
|
||||
<span>{{ 'audit_trail.list.associated_subject'|trans }}: </span>
|
||||
{% for s in audit.subjects %}
|
||||
{{ s|chill_render_audit_subject }}{% if not loop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
{% extends '@ChillMain/layout.html.twig' %}
|
||||
|
||||
{% block title 'audit_trail.list.title'|trans %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ block('title') }}</h1>
|
||||
|
||||
<div class="audit-trail list flex-table">
|
||||
{% for audit in auditTrails %}
|
||||
{{ include('@ChillMain/AuditTrail/_list_item.html.twig') }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -10,9 +10,12 @@ services:
|
||||
- '../../Audit/AuditEvent.php'
|
||||
- '../../Audit/SubjectConverterManagerAwareInterface.php'
|
||||
- '../../Audit/SubjectConverterManagerAwareTrait.php'
|
||||
- '../../Audit/SubjectConverterInterface.php'
|
||||
- '../../Audit/SubjectDisplayerInterface.php'
|
||||
- '../../Audit/Exception/'
|
||||
- '../../Audit/Exception/*'
|
||||
|
||||
Chill\MainBundle\Audit\SubjectConverterManager:
|
||||
arguments:
|
||||
$converters: !tagged_iterator chill_main.audit_subject_converter
|
||||
$displayers: !tagged_iterator chill_main.audit_subject_displayer
|
||||
|
||||
@@ -1011,3 +1011,13 @@ editor:
|
||||
|
||||
login_page:
|
||||
logo_alt: "Logo de Chill"
|
||||
|
||||
audit_trail:
|
||||
action:
|
||||
view: Visualisation
|
||||
update: Mise à jour
|
||||
create: Création
|
||||
delete: Suppression
|
||||
list:
|
||||
title: Liste des événements
|
||||
associated_subject: Entités associées
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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 Twig\Environment;
|
||||
|
||||
final readonly class AccompanyingPeriodSubjectDisplayer implements SubjectDisplayerInterface
|
||||
{
|
||||
public function __construct(private Environment $twig) {}
|
||||
|
||||
public function supportsDisplay(Subject $subject, array $optons = []): bool
|
||||
{
|
||||
return 'accompanying_period' === $subject->type;
|
||||
}
|
||||
|
||||
public function display(Subject $subject, array $options = []): string
|
||||
{
|
||||
return $this->twig->render(
|
||||
'@ChillPerson/Audit/accompanying_period.html.twig',
|
||||
['id' => $subject->identifiers['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||
use Twig\Environment;
|
||||
|
||||
class AccompanyingPeriodWorkSubjectDisplayer implements SubjectDisplayerInterface
|
||||
{
|
||||
public function __construct(private AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, private Environment $twig) {}
|
||||
|
||||
public function supportsDisplay(Subject $subject, array $optons = []): bool
|
||||
{
|
||||
return 'accompanying_period_work' === $subject->type;
|
||||
}
|
||||
|
||||
public function display(Subject $subject, array $options = []): string
|
||||
{
|
||||
$work = $this->accompanyingPeriodWorkRepository->find($subject->identifiers['id']);
|
||||
|
||||
return $this->twig->render('@ChillPerson/Audit/accompanying_period_work.html.twig', [
|
||||
'work' => $work, 'id' => $subject->identifiers['id']]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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\PersonBundle\Repository\PersonRepository;
|
||||
use Twig\Environment;
|
||||
|
||||
final readonly class PersonSubjectDisplayer implements SubjectDisplayerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private PersonRepository $personRepository,
|
||||
private Environment $twig,
|
||||
) {}
|
||||
|
||||
public function supportsDisplay(Subject $subject, array $optons = []): bool
|
||||
{
|
||||
return 'person' === $subject->type;
|
||||
}
|
||||
|
||||
public function display(Subject $subject, array $options = []): string
|
||||
{
|
||||
$person = $this->personRepository->find($subject->identifiers['id']);
|
||||
|
||||
return $this->twig->render('@ChillPerson/Audit/person.html.twig', ['id' => $subject->identifiers['id'], 'person' => $person]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<span>{{ 'audit.accompanying_period.accompanying_period_number'|trans({'{id}': id}) }} <a href="{{ path('chill_person_accompanying_course_index', {'accompanying_period_id': id} ) }}"><i class="bi bi-link"></i></a></span>
|
||||
@@ -0,0 +1,2 @@
|
||||
<span>{{ 'audit.accompanying_period_work.accompanying_period_work_number'|trans({'id': id}) }}
|
||||
{%- if work is not null %}: {{ work.socialAction.title|localize_translatable_string }}{% endif %}</span>
|
||||
@@ -0,0 +1 @@
|
||||
<span>{% if person is not null %}{{ person|chill_entity_render_box }} <span><a href="{{ path('chill_person_view', {'person_id': id}) }}"><i class="bi bi-link"></i></a></span>{% else %}{{ 'audit.person.person_not_found_with_id'|trans({'id': id}) }}{% endif %}</span>
|
||||
@@ -1574,3 +1574,11 @@ my_parcours_filters:
|
||||
|
||||
document_duplicate:
|
||||
to_evaluation_success: "Le document a été dupliquer"
|
||||
|
||||
audit:
|
||||
person:
|
||||
person_not_found_with_id: "Personne inconnue avec l'identifiant {id}"
|
||||
accompanying_period:
|
||||
accompanying_period_number: "Parcours n°{id}"
|
||||
accompanying_period_work:
|
||||
accompanying_period_work_number: "Action d'accompagnement n°{id}"
|
||||
|
||||
Reference in New Issue
Block a user