mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
100 lines
2.7 KiB
PHP
100 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\FamilyMembersBundle\Templating;
|
|
|
|
use Chill\FamilyMembersBundle\Config\ConfigRepository;
|
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|
use Twig\Extension\AbstractExtension;
|
|
use Twig\TwigFilter;
|
|
use Twig\TwigFunction;
|
|
|
|
class Twig extends AbstractExtension
|
|
{
|
|
/**
|
|
* @var ConfigRepository
|
|
*/
|
|
protected $configRepository;
|
|
|
|
/**
|
|
* @var TranslatableStringHelper
|
|
*/
|
|
protected $translatableStringHelper;
|
|
|
|
public function __construct(
|
|
ConfigRepository $configRepository,
|
|
TranslatableStringHelper $translatableStringHelper
|
|
) {
|
|
$this->configRepository = $configRepository;
|
|
$this->translatableStringHelper = $translatableStringHelper;
|
|
}
|
|
|
|
public function displayFamilialSituation($situation)
|
|
{
|
|
if (null === $situation) {
|
|
return null;
|
|
}
|
|
|
|
return $this->translatableStringHelper->localize(
|
|
$this->configRepository->getFamilialSituationsLabels()[$situation]
|
|
);
|
|
}
|
|
|
|
public function displayLink($link)
|
|
{
|
|
if (null === $link) {
|
|
return null;
|
|
}
|
|
|
|
return $this->translatableStringHelper->localize(
|
|
$this->configRepository->getLinksLabels()[$link]
|
|
);
|
|
}
|
|
|
|
public function displayProfessionalSituation($situation)
|
|
{
|
|
if (null === $situation) {
|
|
return null;
|
|
}
|
|
|
|
return $this->translatableStringHelper->localize(
|
|
$this->configRepository->getProfessionalSituationsLabels()[$situation]
|
|
);
|
|
}
|
|
|
|
public function getFilters()
|
|
{
|
|
return [
|
|
new TwigFilter('chill_family_member_link_display', [$this, 'displayLink'], ['is_safe' => ['html']]),
|
|
new TwigFilter('chill_family_member_professional_situation_display', [$this, 'displayProfessionalSituation'], ['is_safe' => ['html']]),
|
|
new TwigFilter('chill_family_member_familial_situation_display', [$this, 'displayFamilialSituation'], ['is_safe' => ['html']]),
|
|
];
|
|
}
|
|
|
|
public function getFunctions()
|
|
{
|
|
return [
|
|
new TwigFunction('chill_family_members_has_professionnal_situation', [$this, 'hasProfessionnalSituation']),
|
|
new TwigFunction('chill_family_members_has_familial_situation', [$this, 'hasFamilialSituation']),
|
|
];
|
|
}
|
|
|
|
public function hasFamilialSituation()
|
|
{
|
|
return $this->configRepository->hasFamilialSituation();
|
|
}
|
|
|
|
public function hasProfessionnalSituation()
|
|
{
|
|
return $this->configRepository->hasProfessionalSituation();
|
|
}
|
|
}
|