diff --git a/Controller/PersonController.php b/Controller/PersonController.php index d89b55a75..bdc1250ae 100644 --- a/Controller/PersonController.php +++ b/Controller/PersonController.php @@ -35,6 +35,8 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\PersonBundle\Search\SimilarPersonMatcher; use Symfony\Component\Translation\TranslatorInterface; use Chill\MainBundle\Search\SearchProvider; +use Chill\PersonBundle\Repository\PersonRepository; +use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; class PersonController extends Controller { @@ -56,14 +58,31 @@ class PersonController extends Controller */ protected $eventDispatcher; + /** + * + * @var PersonRepository; + */ + protected $personRepository; + + /** + * + * @var ConfigPersonAltNamesHelper + */ + protected $configPersonAltNameHelper; + public function __construct( SimilarPersonMatcher $similarPersonMatcher, TranslatorInterface $translator, - EventDispatcherInterface $eventDispatcher + EventDispatcherInterface $eventDispatcher, + PersonRepository $personRepository, + ConfigPersonAltNamesHelper $configPersonAltNameHelper + ) { $this->similarPersonMatcher = $similarPersonMatcher; $this->translator = $translator; $this->eventDispatcher = $eventDispatcher; + $this->configPersonAltNameHelper = $configPersonAltNameHelper; + $this->personRepository = $personRepository; } public function getCFGroup() @@ -97,8 +116,11 @@ class PersonController extends Controller $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); return $this->render('ChillPersonBundle:Person:view.html.twig', - array("person" => $person, - "cFGroup" => $this->getCFGroup())); + array( + "person" => $person, + "cFGroup" => $this->getCFGroup(), + "alt_names" => $this->configPersonAltNameHelper->getChoices(), + )); } public function editAction($person_id) @@ -373,10 +395,7 @@ class PersonController extends Controller */ private function _getPerson($id) { - $em = $this->getDoctrine()->getManager(); - - $person = $em->getRepository('ChillPersonBundle:Person') - ->find($id); + $person = $this->personRepository->find($id); return $person; } diff --git a/Resources/config/services/controller.yml b/Resources/config/services/controller.yml index 8e2fb9fdf..76829d073 100644 --- a/Resources/config/services/controller.yml +++ b/Resources/config/services/controller.yml @@ -4,6 +4,8 @@ services: $similarPersonMatcher: '@Chill\PersonBundle\Search\SimilarPersonMatcher' $translator: '@Symfony\Component\Translation\TranslatorInterface' $eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' + $personRepository: '@Chill\PersonBundle\Repository\PersonRepository' + $configPersonAltNameHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' tags: ['controller.service_arguments'] Chill\PersonBundle\Controller\TimelinePersonController: diff --git a/Resources/config/services/templating.yml b/Resources/config/services/templating.yml index 395c3e9f3..813824448 100644 --- a/Resources/config/services/templating.yml +++ b/Resources/config/services/templating.yml @@ -1,4 +1,6 @@ services: Chill\PersonBundle\Templating\Entity\PersonRender: + arguments: + $configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' tags: - 'chill.render_entity' diff --git a/Resources/views/Person/list.html.twig b/Resources/views/Person/list.html.twig index c1f1daf0c..c1ba58b7f 100644 --- a/Resources/views/Person/list.html.twig +++ b/Resources/views/Person/list.html.twig @@ -42,7 +42,7 @@ {% set is_open = person.isOpen() %} - {{person.firstName}} {{person.lastName}} + {{ person|chill_entity_render_box }} {% spaceless %} {% if chill_person.fields.accompanying_period == 'visible' %} {% if is_open == false %} diff --git a/Resources/views/Person/view.html.twig b/Resources/views/Person/view.html.twig index c6db21ef5..ac93b1d2b 100644 --- a/Resources/views/Person/view.html.twig +++ b/Resources/views/Person/view.html.twig @@ -62,6 +62,12 @@ This view should receive those arguments:
{{ 'Last name'|trans }} :
{{ person.lastName }}
+ {% for el in person.altNames %} + {% if el.key in alt_names|keys %} +
{{ alt_names[el.key]|localize_translatable_string }} :
+
{{ el.label }}
+ {% endif %} + {% endfor %}
{{ 'Gender'|trans }} :
{{ ( person.gender|default('Not given'))|trans }}
diff --git a/Templating/Entity/PersonRender.php b/Templating/Entity/PersonRender.php index 42bdfb6a9..98398d8d5 100644 --- a/Templating/Entity/PersonRender.php +++ b/Templating/Entity/PersonRender.php @@ -22,6 +22,7 @@ namespace Chill\PersonBundle\Templating\Entity; use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; /** * Render a Person @@ -29,6 +30,17 @@ use Chill\PersonBundle\Entity\Person; */ class PersonRender extends AbstractChillEntityRender { + /** + * + * @var ConfigPersonAltNamesHelper + */ + protected $configAltNamesHelper; + + public function __construct(ConfigPersonAltNamesHelper $configAltNamesHelper) + { + $this->configAltNamesHelper = $configAltNamesHelper; + } + /** * * @param Person $person @@ -40,7 +52,8 @@ class PersonRender extends AbstractChillEntityRender return $this->getDefaultOpeningBox('person'). ''.$person->getFirstName().''. - ''.$person->getLastName().''. + ' '.$person->getLastName().''. + $this->addAltNames($person, true). $this->getDefaultClosingBox() ; } @@ -53,7 +66,43 @@ class PersonRender extends AbstractChillEntityRender */ public function renderString($person, array $options): string { - return $person->getFirstName().' '.$person->getLastName(); + return $person->getFirstName().' '.$person->getLastName() + .$this->addAltNames($person, false); + } + + protected function addAltNames(Person $person, bool $addSpan) + { + $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 .= ''; + } + $str .= $altName->getLabel(); + + if ($addSpan) { + $str .= ""; + } + } + if (!$isFirst) { + $str .= ")"; + } + } + } + + return $str; } public function supports($entity, array $options): bool