mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
<?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\Templating\Entity;
|
|
|
|
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
|
use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait;
|
|
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
|
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
/**
|
|
* Render closing motive.
|
|
*
|
|
* @implements ChillEntityRenderInterface<ClosingMotive>
|
|
*/
|
|
class ClosingMotiveRender implements ChillEntityRenderInterface
|
|
{
|
|
use BoxUtilsChillEntityRenderTrait;
|
|
private const SEPARATOR = ' > ';
|
|
|
|
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper) {}
|
|
|
|
public function renderBox($entity, array $options): string
|
|
{
|
|
return
|
|
$this->getDefaultOpeningBox('closing-motive') .
|
|
$this->renderString($entity, $options) .
|
|
$this->getDefaultClosingBox();
|
|
}
|
|
|
|
public function renderString($entity, array $options): string
|
|
{
|
|
return $this->renderStringRecursive(
|
|
$entity,
|
|
'', //$this->translatableStringHelper->localize($entity->getName()),
|
|
$options
|
|
);
|
|
}
|
|
|
|
public function supports($entity, array $options): bool
|
|
{
|
|
return $entity instanceof ClosingMotive;
|
|
}
|
|
|
|
private function renderStringRecursive(ClosingMotive $motive, string $existing, array $options)
|
|
{
|
|
$newExisting = $this->translatableStringHelper->localize($motive->getName());
|
|
$isCancled = $motive->getIsCanceledAccompanyingPeriod() ? $this->translator->trans('( Canceled period )') : '';
|
|
|
|
if ($motive->hasParent()) {
|
|
if ('' !== $existing) {
|
|
$newExisting = $newExisting . self::SEPARATOR . $existing;
|
|
}
|
|
|
|
return $this->renderStringRecursive(
|
|
$motive->getParent(),
|
|
$newExisting . ' ' . $isCancled,
|
|
$options
|
|
);
|
|
}
|
|
|
|
if ('' !== $existing) {
|
|
return $newExisting . self::SEPARATOR . $existing;
|
|
}
|
|
|
|
return $newExisting . ' ' . $isCancled;
|
|
}
|
|
}
|