Add person alt names in list & view

This commit is contained in:
Julien Fastré 2020-01-30 16:40:19 +01:00
parent 426458811c
commit 342449aadc
6 changed files with 88 additions and 10 deletions

View File

@ -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;
}

View File

@ -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:

View File

@ -1,4 +1,6 @@
services:
Chill\PersonBundle\Templating\Entity\PersonRender:
arguments:
$configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
tags:
- 'chill.render_entity'

View File

@ -42,7 +42,7 @@
<td>
{% set is_open = person.isOpen() %}
<a href="{{ path('chill_person_view', { person_id : person.getId }) }}" {% if chill_person.fields.accompanying_period == 'visible' %}{% if is_open %} alt="{{ 'An accompanying period is open'|trans|e('html_attr') }}"{% else %} alt="{{ 'Any accompanying periods are open'|trans|e('html_attr') }}" {% endif %}{% endif %}>
{{person.firstName}} {{person.lastName}}
{{ person|chill_entity_render_box }}
{% spaceless %}
{% if chill_person.fields.accompanying_period == 'visible' %}
{% if is_open == false %}

View File

@ -62,6 +62,12 @@ This view should receive those arguments:
<dt>{{ 'Last name'|trans }}&nbsp;:</dt>
<dd>{{ person.lastName }}</dd>
{% for el in person.altNames %}
{% if el.key in alt_names|keys %}
<dt>{{ alt_names[el.key]|localize_translatable_string }}&nbsp;:</dt>
<dd>{{ el.label }}</dd>
{% endif %}
{% endfor %}
<dt>{{ 'Gender'|trans }}&nbsp;:</dt>
<dd>{{ ( person.gender|default('Not given'))|trans }}</dd>

View File

@ -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').
'<span class="chill-entity__person__first-name">'.$person->getFirstName().'</span>'.
'<span class="chill-entity__person__last-name">'.$person->getLastName().'</span>'.
' <span class="chill-entity__person__last-name">'.$person->getLastName().'</span>'.
$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 .= '<span class="chill-entity__person__alt-name chill-entity__person__altname--'.$altName->getKey().'">';
}
$str .= $altName->getLabel();
if ($addSpan) {
$str .= "</span>";
}
}
if (!$isFirst) {
$str .= ")";
}
}
}
return $str;
}
public function supports($entity, array $options): bool