mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-03 12:39:42 +00:00
Add audit display functionality for Household and HouseholdMember
- Added `HouseholdSubjectDisplayer` and `HouseholdMemberSubjectDisplayer` classes to handle audit display logic. - Created Twig templates `household.html.twig` and `household_member.html.twig` for rendering audit information. - Integrated support for HTML and text formats when displaying audit entries.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?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\Household\HouseholdMembersRepository;
|
||||
use Twig\Environment;
|
||||
|
||||
final readonly class HouseholdMemberSubjectDisplayer implements SubjectDisplayerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private HouseholdMembersRepository $householdMembersRepository,
|
||||
private Environment $twig,
|
||||
) {}
|
||||
|
||||
public function supportsDisplay(Subject $subject, array $options = []): bool
|
||||
{
|
||||
return 'household_member' === $subject->type;
|
||||
}
|
||||
|
||||
public function display(Subject $subject, string $format = 'html', array $options = []): string
|
||||
{
|
||||
$householdMember = $this->householdMembersRepository->find($subject->identifiers['id']);
|
||||
|
||||
if ('html' === $format) {
|
||||
return $this->twig->render('@ChillPerson/Audit/household_member.html.twig', [
|
||||
'id' => $subject->identifiers['id'],
|
||||
'householdMember' => $householdMember,
|
||||
]);
|
||||
}
|
||||
|
||||
if (null !== $householdMember) {
|
||||
return sprintf(
|
||||
'%s in household #%d',
|
||||
(string) $householdMember->getPerson(),
|
||||
$householdMember->getHousehold()->getId()
|
||||
);
|
||||
}
|
||||
|
||||
return sprintf('HouseholdMember #%d', $subject->identifiers['id']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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\Household\HouseholdRepository;
|
||||
use Twig\Environment;
|
||||
|
||||
final readonly class HouseholdSubjectDisplayer implements SubjectDisplayerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private HouseholdRepository $householdRepository,
|
||||
private Environment $twig,
|
||||
) {}
|
||||
|
||||
public function supportsDisplay(Subject $subject, array $options = []): bool
|
||||
{
|
||||
return 'household' === $subject->type;
|
||||
}
|
||||
|
||||
public function display(Subject $subject, string $format = 'html', array $options = []): string
|
||||
{
|
||||
$household = $this->householdRepository->find($subject->identifiers['id']);
|
||||
|
||||
if ('html' === $format) {
|
||||
return $this->twig->render('@ChillPerson/Audit/household.html.twig', [
|
||||
'id' => $subject->identifiers['id'],
|
||||
'household' => $household,
|
||||
]);
|
||||
}
|
||||
|
||||
return sprintf('Household #%d', $subject->identifiers['id']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<span>
|
||||
{% if household is not null %}
|
||||
<i class="bi bi-house"></i>
|
||||
{{ 'household'|trans }} #{{ id }}
|
||||
<span><a href="{{ path('chill_person_household_summary', {'household_id': id}) }}"><i class="bi bi-link"></i></a></span>
|
||||
{% else %}
|
||||
{{ 'audit.household.household_not_found_with_id'|trans({'id': id}) }}
|
||||
{% endif %}
|
||||
</span>
|
||||
@@ -0,0 +1,11 @@
|
||||
<span>
|
||||
{% if householdMember is not null %}
|
||||
{{ householdMember.person|chill_entity_render_string }}
|
||||
{{ 'audit.household_member.member_in_household'|trans }}
|
||||
<i class="bi bi-house"></i>
|
||||
{{ 'Household'|trans }} #{{ householdMember.household.id }}
|
||||
<span><a href="{{ path('chill_person_household_summary', {'household_id': householdMember.household.id}) }}"><i class="bi bi-link"></i></a></span>
|
||||
{% else %}
|
||||
{{ 'audit.household_member.not_found_with_id'|trans({'id': id}) }}
|
||||
{% endif %}
|
||||
</span>
|
||||
Reference in New Issue
Block a user