mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
118 lines
3.5 KiB
PHP
118 lines
3.5 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\PersonBundle\Templating\Entity;
|
|
|
|
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
|
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Symfony\Component\Templating\EngineInterface;
|
|
use function array_key_exists;
|
|
|
|
/**
|
|
* Render a Person.
|
|
*/
|
|
class PersonRender extends AbstractChillEntityRender
|
|
{
|
|
private ConfigPersonAltNamesHelper $configAltNamesHelper;
|
|
|
|
private EngineInterface $engine;
|
|
|
|
public function __construct(
|
|
ConfigPersonAltNamesHelper $configAltNamesHelper,
|
|
EngineInterface $engine
|
|
) {
|
|
$this->configAltNamesHelper = $configAltNamesHelper;
|
|
$this->engine = $engine;
|
|
}
|
|
|
|
/**
|
|
* @param Person $person
|
|
*/
|
|
public function renderBox($person, array $options): string
|
|
{
|
|
$params = [
|
|
'addAltNames' => $options['addAltNames'] ?? $this->configAltNamesHelper->hasAltNames(),
|
|
'addLink' => $options['addLink'] ?? false,
|
|
'addEntity' => $options['addEntity'] ?? false,
|
|
'addId' => $options['addId'] ?? false,
|
|
'addInfo' => $options['addInfo'] ?? false,
|
|
'addAge' => $options['addAge'] ?? false,
|
|
'addCenter' => $options['addCenter'] ?? false,
|
|
'address_multiline' => $options['address_multiline'] ?? false,
|
|
'hLevel' => $options['hLevel'] ?? 3,
|
|
'customButtons' => $options['customButtons'] ?? [],
|
|
'customArea' => $options['customArea'] ?? [],
|
|
'addDeath' => $options['addDeath'] ?? true,
|
|
];
|
|
|
|
return
|
|
$this->getDefaultOpeningBox('person') .
|
|
$this->engine->render('@ChillPerson/Entity/person.html.twig', [
|
|
'person' => $person,
|
|
'render' => $options['render'] ?? 'raw',
|
|
'options' => $params,
|
|
]) .
|
|
$this->getDefaultClosingBox();
|
|
}
|
|
|
|
/**
|
|
* @param Person $person
|
|
*/
|
|
public function renderString($person, array $options): string
|
|
{
|
|
return $person->getFirstName() . ' ' . $person->getLastName()
|
|
. $this->addAltNames($person, false);
|
|
}
|
|
|
|
public function supports($entity, array $options): bool
|
|
{
|
|
return $entity instanceof Person;
|
|
}
|
|
|
|
protected function addAltNames(Person $person, bool $addSpan): string
|
|
{
|
|
$str = '';
|
|
|
|
if ($this->configAltNamesHelper->hasAltNames()) {
|
|
$altNames = $this->configAltNamesHelper->getChoices();
|
|
$isFirst = true;
|
|
|
|
foreach ($person->getAltNames()->getIterator() as $altName) {
|
|
/** @var \Chill\PersonBundle\Entity\PersonAltName $altName */
|
|
if (array_key_exists($altName->getKey(), $altNames)) {
|
|
if ($isFirst) {
|
|
$str .= ' (';
|
|
$isFirst = false;
|
|
} else {
|
|
$str .= ' ';
|
|
}
|
|
|
|
if ($addSpan) {
|
|
$str .= '<span class="altname altname-' . $altName->getKey() . '">';
|
|
}
|
|
$str .= $altName->getLabel();
|
|
|
|
if ($addSpan) {
|
|
$str .= '</span>';
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$isFirst) {
|
|
$str .= ')';
|
|
}
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
}
|