Files
chill-bundles/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php
2021-11-30 13:54:58 +01:00

88 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\ThirdPartyBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Templating\EngineInterface;
class ThirdPartyRender extends AbstractChillEntityRender
{
protected EngineInterface $engine;
protected TranslatableStringHelper $translatableStringHelper;
public function __construct(
EngineInterface $engine,
TranslatableStringHelper $translatableStringHelper
) {
$this->engine = $engine;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @param ThirdParty $entity
*/
public function renderBox($entity, array $options): string
{
$params = [
'with_valid_from' => $options['with_valid_from'] ?? true,
'addLink' => $options['addLink'] ?? false,
'addEntity' => $options['addEntity'] ?? false,
'addId' => $options['addId'] ?? false,
'addInfo' => $options['addInfo'] ?? false,
'hLevel' => $options['hLevel'] ?? 3,
'customButtons' => $options['customButtons'] ?? [],
'customArea' => $options['customArea'] ?? [],
'showContacts' => $options['showContacts'] ?? false,
'showParent' => $options['showParent'] ?? true,
'isConfidential' => $options['isConfidential'] ?? false,
];
return
$this->getDefaultOpeningBox('thirdparty') .
$this->engine->render('@ChillThirdParty/Entity/thirdparty.html.twig', [
'thirdparty' => $entity,
'render' => $options['render'] ?? 'raw',
'options' => $params,
]) .
$this->getDefaultClosingBox();
}
/**
* @param ThirdParty $entity
*/
public function renderString($entity, array $options): string
{
if ($entity->getCivility() !== null) {
$civility = $this->translatableStringHelper
->localize($entity->getCivility()->getAbbreviation()) . ' ';
} else {
$civility = '';
}
if (!empty($entity->getAcronym())) {
$acronym = ' (' . $entity->getAcronym() . ')';
} else {
$acronym = '';
}
return $civility . $entity->getName() . $acronym;
}
public function supports($entity, array $options): bool
{
return $entity instanceof ThirdParty;
}
}