* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ 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 * @param array $options * @return string */ 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'] ?? [], ]; 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 * @param array $options * @return string */ 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; } }