mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-18 08:14:24 +00:00
72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Templating\Entity;
|
|
|
|
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
|
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|
use Symfony\Component\Templating\EngineInterface;
|
|
|
|
class SocialIssueRender implements ChillEntityRenderInterface
|
|
{
|
|
private TranslatableStringHelper $translatableStringHelper;
|
|
private EngineInterface $engine;
|
|
|
|
public const SEPARATOR_KEY = 'default.separator';
|
|
|
|
public const DEFAULT_ARGS = [
|
|
self::SEPARATOR_KEY => ' > ',
|
|
];
|
|
|
|
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
|
|
{
|
|
$this->translatableStringHelper = $translatableStringHelper;
|
|
$this->engine = $engine;
|
|
}
|
|
|
|
public function supports($entity, array $options): bool
|
|
{
|
|
return $entity instanceof SocialIssue;
|
|
}
|
|
|
|
public function renderString($socialIssue, array $options): string
|
|
{
|
|
/** @var $socialIssue SocialIssue */
|
|
$options = \array_merge(self::DEFAULT_ARGS, $options);
|
|
|
|
$str = $this->translatableStringHelper->localize($socialIssue->getTitle());
|
|
|
|
while ($socialIssue->hasParent()) {
|
|
$socialIssue = $socialIssue->getParent();
|
|
$str .= $options[self::SEPARATOR_KEY].$this->translatableStringHelper->localize(
|
|
$socialIssue->getTitle()
|
|
);
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
protected function buildParents($socialIssue): array
|
|
{
|
|
$parents = [];
|
|
while ($socialIssue->hasParent()) {
|
|
$socialIssue = $parents[] = $socialIssue->getParent();
|
|
}
|
|
|
|
return $parents;
|
|
}
|
|
|
|
public function renderBox($socialIssue, array $options): string
|
|
{
|
|
$options = \array_merge(self::DEFAULT_ARGS, $options);
|
|
// give some help to twig: an array of parents
|
|
$parents = $this->buildParents($socialIssue);
|
|
|
|
return $this->engine->render('@ChillPerson/Entity/social_issue.html.twig', [
|
|
'socialIssue' => $socialIssue,
|
|
'parents' => $parents,
|
|
'options' => $options
|
|
]);
|
|
}
|
|
}
|