mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/dune-risky' into fix-person-tests
This commit is contained in:
@@ -27,32 +27,17 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\MainBundle\Timeline\TimelineBuilder;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
/**
|
||||
* Class TimelinePersonController
|
||||
*
|
||||
* @package Chill\PersonBundle\Controller
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class TimelinePersonController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
protected EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TimelineBuilder
|
||||
*/
|
||||
protected $timelineBuilder;
|
||||
protected TimelineBuilder $timelineBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var PaginatorFactory
|
||||
*/
|
||||
protected $paginatorFactory;
|
||||
protected PaginatorFactory $paginatorFactory;
|
||||
|
||||
/**
|
||||
* TimelinePersonController constructor.
|
||||
@@ -62,11 +47,13 @@ class TimelinePersonController extends AbstractController
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
TimelineBuilder $timelineBuilder,
|
||||
PaginatorFactory $paginatorFactory
|
||||
PaginatorFactory $paginatorFactory,
|
||||
AuthorizationHelper $authorizationHelper
|
||||
) {
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->timelineBuilder = $timelineBuilder;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -302,13 +302,9 @@ class AccompanyingPeriod
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setRemark(string $remark): self
|
||||
public function setRemark(string $remark = null): self
|
||||
{
|
||||
if ($remark === null) {
|
||||
$remark = '';
|
||||
}
|
||||
|
||||
$this->remark = $remark;
|
||||
$this->remark = (string) $remark;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@@ -0,0 +1,15 @@
|
||||
<span class="chill-entity chill-entity__person">
|
||||
{%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%}
|
||||
{%- set showLink = true -%}<a href="{{ chill_path_add_return_path('chill_person_view', { 'person_id': person.id }) }}">{%- endif -%}
|
||||
<span class="chill-entity__person__first-name">{{ person.firstName }}</span>
|
||||
<span class="chill-entity__person__last-name">{{ person.lastName }}</span>
|
||||
{%- if addAltNames -%}
|
||||
{%- for n in person.altNames -%}
|
||||
{%- if loop.first -%}({% else %} {%- endif -%}
|
||||
<span class="chill-entity__person__alt-name chill-entity__person__altname--{{ n.key }}">
|
||||
{{ n.label }}
|
||||
</span>
|
||||
{%- if loop.last %}) {% endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- if showLink is defined -%}</a>{%- endif -%}</span>
|
@@ -1,11 +1,24 @@
|
||||
<h3 class="single-line">
|
||||
<div>
|
||||
<h3 class="single-line">
|
||||
{{ period.closingDate|format_date('long') }}
|
||||
<span class="person"> /
|
||||
<a href="{{ path('chill_person_accompanying_period_list', { 'person_id': person.id } ) }}">
|
||||
{{ 'Closing the accompanying period' | trans }}
|
||||
</a>
|
||||
<span>
|
||||
<span class="chill-red">
|
||||
<i class="fa fa-folder"></i>
|
||||
</span>
|
||||
</h3>
|
||||
<span class="person"> / </span>
|
||||
{{ 'An accompanying period ends'|trans }}
|
||||
{% if 'person' != context %}
|
||||
{% for p in period.persons %}
|
||||
/ {{ p|chill_entity_render_box({'addLink': true}) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</h3>
|
||||
|
||||
<div class="statement">
|
||||
<dl class="chill_view_data">
|
||||
<dd>{{ 'Participants'|trans }} :</dd>
|
||||
<dt>
|
||||
<ul>
|
||||
{% for p in period.participations %}
|
||||
<li>{{ p.person|chill_entity_render_box({ 'addLink': true }) }}: {{ 'since %date%'|trans({'%date%': p.startDate|format_date("long") } ) }}, {{ 'until %date%'|trans({'%date%': (p.endDate is not null ? p.endDate : period.closingDate)|format_date("long") }) }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</dt>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1,11 +1,24 @@
|
||||
<h3 class="single-line">
|
||||
<div>
|
||||
<h3 class="single-line">
|
||||
{{ period.openingDate|format_date('long') }}
|
||||
<span class="person"> /
|
||||
<a href="{{ path('chill_person_accompanying_period_list', { 'person_id': person.id } ) }}">
|
||||
{{ 'Opening the accompanying period' | trans }}
|
||||
</a>
|
||||
</span>
|
||||
<span class="chill-green">
|
||||
<i class="fa fa-folder-open"></i>
|
||||
</span>
|
||||
</h3>
|
||||
<span class="person"> / </span>
|
||||
{{ 'An accompanying period starts'|trans }}
|
||||
{% if 'person' != context %}
|
||||
{% for p in period.persons %}
|
||||
/ {{ p|chill_entity_render_box({'addLink': true}) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</h3>
|
||||
|
||||
<div class="statement">
|
||||
<dl class="chill_view_data">
|
||||
<dd>{{ 'Participants'|trans }} :</dd>
|
||||
<dt>
|
||||
<ul>
|
||||
{% for p in period.participations %}
|
||||
<li>{{ 'Since %date%'|trans( {'%date%': p.startDate|format_date("long") } ) }} : {{ p.person|chill_entity_render_box({ 'addLink': true }) }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</dt>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -23,6 +23,8 @@ namespace Chill\PersonBundle\Templating\Entity;
|
||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Render a Person
|
||||
@@ -30,15 +32,16 @@ use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
*/
|
||||
class PersonRender extends AbstractChillEntityRender
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ConfigPersonAltNamesHelper
|
||||
*/
|
||||
protected $configAltNamesHelper;
|
||||
private ConfigPersonAltNamesHelper $configAltNamesHelper;
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
public function __construct(ConfigPersonAltNamesHelper $configAltNamesHelper)
|
||||
{
|
||||
public function __construct(
|
||||
ConfigPersonAltNamesHelper $configAltNamesHelper,
|
||||
EngineInterface $engine
|
||||
) {
|
||||
$this->configAltNamesHelper = $configAltNamesHelper;
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,13 +52,13 @@ class PersonRender extends AbstractChillEntityRender
|
||||
*/
|
||||
public function renderBox($person, array $options): string
|
||||
{
|
||||
return
|
||||
$this->getDefaultOpeningBox('person').
|
||||
'<span class="chill-entity__person__first-name">'.$person->getFirstName().'</span>'.
|
||||
' <span class="chill-entity__person__last-name">'.$person->getLastName().'</span>'.
|
||||
$this->addAltNames($person, true).
|
||||
$this->getDefaultClosingBox()
|
||||
;
|
||||
return $this->engine->render('@ChillPerson/Entity/person.html.twig',
|
||||
[
|
||||
'person' => $person,
|
||||
'addAltNames' => $this->configAltNamesHelper->hasAltNames(),
|
||||
'addLink' => $options['addLink'] ?? false
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +72,7 @@ class PersonRender extends AbstractChillEntityRender
|
||||
return $person->getFirstName().' '.$person->getLastName()
|
||||
.$this->addAltNames($person, false);
|
||||
}
|
||||
|
||||
|
||||
protected function addAltNames(Person $person, bool $addSpan)
|
||||
{
|
||||
$str = '';
|
||||
|
@@ -21,6 +21,14 @@ namespace Chill\PersonBundle\Timeline;
|
||||
|
||||
use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Timeline\TimelineSingleQuery;
|
||||
|
||||
/**
|
||||
* Provide method to build timeline for accompanying periods
|
||||
@@ -28,19 +36,22 @@ use Doctrine\ORM\EntityManager;
|
||||
* This class is resued by TimelineAccompanyingPeriodOpening (for opening)
|
||||
* and TimelineAccompanyingPeriodClosing (for closing)
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $em;
|
||||
protected EntityManager $em;
|
||||
|
||||
private Security $security;
|
||||
|
||||
private AuthorizationHelper $authorizationHelper;
|
||||
|
||||
private const SUPPORTED_CONTEXTS = [ 'person', 'center' ];
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
public function __construct(EntityManager $em, Security $security, AuthorizationHelper $authorizationHelper)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->security = $security;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,23 +83,74 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
|
||||
*/
|
||||
protected function basicFetchQuery($context, array $args)
|
||||
{
|
||||
if ($context !== 'person') {
|
||||
if (FALSE === \in_array($context, self::SUPPORTED_CONTEXTS)) {
|
||||
throw new \LogicException('TimelineAccompanyingPeriod is not able '
|
||||
. 'to render context '.$context);
|
||||
}
|
||||
|
||||
$metadata = $this->em
|
||||
->getClassMetadata('ChillPersonBundle:AccompanyingPeriod')
|
||||
->getClassMetadata(AccompanyingPeriod::class)
|
||||
;
|
||||
|
||||
return array(
|
||||
'id' => $metadata->getColumnName('id'),
|
||||
'FROM' => $metadata->getTableName(),
|
||||
'WHERE' => sprintf('%s = %d',
|
||||
$metadata
|
||||
->getAssociationMapping('person')['joinColumns'][0]['name'],
|
||||
$args['person']->getId())
|
||||
);
|
||||
[$where, $parameters] = $this->buildWhereClause($context, $args);
|
||||
|
||||
return TimelineSingleQuery::fromArray([
|
||||
'id' => "{$metadata->getTableName()}.{$metadata->getColumnName('id')}",
|
||||
'FROM' => $this->buildFromClause($context),
|
||||
'WHERE' => $where,
|
||||
'parameters' => $parameters
|
||||
]);
|
||||
}
|
||||
|
||||
private function buildFromClause($context)
|
||||
{
|
||||
$period = $this->em->getClassMetadata(AccompanyingPeriod::class);
|
||||
$participation = $this->em->getClassMetadata(AccompanyingPeriodParticipation::class);
|
||||
$person = $this->em->getClassMetadata(Person::class);
|
||||
$join = $participation->getAssociationMapping('accompanyingPeriod')['joinColumns'][0];
|
||||
$joinPerson = $participation->getAssociationMapping('person')['joinColumns'][0];
|
||||
|
||||
if ($context === 'person') {
|
||||
return "{$period->getTableName()} ".
|
||||
"JOIN {$participation->getTableName()} ".
|
||||
"ON {$participation->getTableName()}.{$join['name']} = ".
|
||||
"{$period->getTableName()}.{$join['referencedColumnName']}";
|
||||
} else {
|
||||
return "{$period->getTableName()} ".
|
||||
"JOIN {$participation->getTableName()} ".
|
||||
"ON {$participation->getTableName()}.{$join['name']} = ".
|
||||
"{$period->getTableName()}.{$join['referencedColumnName']} ".
|
||||
"JOIN {$person->getTableName()} ".
|
||||
"ON {$participation->getTableName()}.{$joinPerson['name']} = ".
|
||||
"{$person->getTableName()}.{$joinPerson['referencedColumnName']}"
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function buildWhereClause($context, array $args): array
|
||||
{
|
||||
$participation = $this->em->getClassMetadata(AccompanyingPeriodParticipation::class);
|
||||
$join = $participation->getAssociationMapping('person')['joinColumns'][0];
|
||||
$person = $this->em->getClassMetadata(Person::class);
|
||||
$joinCenter = $person->getAssociationMapping('center')['joinColumns'][0];
|
||||
|
||||
if ($context === 'center') {
|
||||
$allowedCenters = $this->authorizationHelper->filterReachableCenters($this->security->getUser(), $args['centers'], PersonVoter::SEE);
|
||||
$params = [];
|
||||
$questionMarks = [];
|
||||
$query = "{$person->getTableName()}.{$joinCenter['name']} IN (";
|
||||
foreach ($allowedCenters as $c) {
|
||||
$questionMarks[] = '?';
|
||||
$params[] = $c->getId();
|
||||
}
|
||||
$query .= \implode(", ", $questionMarks).")";
|
||||
|
||||
return [$query, $params];
|
||||
} elseif ($context === 'person') {
|
||||
return [ "{$participation->getTableName()}.{$join['name']} = ?", [ $args['person']->getId() ]];
|
||||
}
|
||||
|
||||
throw new \LogicException("this context is not supported: $context");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +166,7 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
|
||||
{
|
||||
return array(
|
||||
'template' => $template,
|
||||
'template_data' => ['person' => $args['person'], 'period' => $entity]
|
||||
'template_data' => ['period' => $entity, 'context' => $context]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -21,11 +21,10 @@ namespace Chill\PersonBundle\Timeline;
|
||||
|
||||
use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
/**
|
||||
* Provide information for opening periods to timeline
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class TimelineAccompanyingPeriodClosing extends AbstractTimelineAccompanyingPeriod
|
||||
{
|
||||
@@ -46,20 +45,27 @@ class TimelineAccompanyingPeriodClosing extends AbstractTimelineAccompanyingPeri
|
||||
public function fetchQuery($context, array $args)
|
||||
{
|
||||
$metadata = $this->em
|
||||
->getClassMetadata('ChillPersonBundle:AccompanyingPeriod');
|
||||
->getClassMetadata(AccompanyingPeriod::class);
|
||||
|
||||
$data = $this->basicFetchQuery($context, $args);
|
||||
|
||||
$data['type'] = 'accompanying_period_closing';
|
||||
$data['date'] = $metadata->getColumnName('closingDate');
|
||||
$data['WHERE'] = sprintf('%s = %d AND %s IS NOT NULL',
|
||||
$metadata
|
||||
->getAssociationMapping('person')['joinColumns'][0]['name'],
|
||||
$args['person']->getId(),
|
||||
$metadata->getColumnName('closingDate'))
|
||||
$query = $this->basicFetchQuery($context, $args);
|
||||
[$where, $parameters] = $this->buildWhereClause($context, $args);
|
||||
$query->setKey('accompanying_period_closing')
|
||||
->setDate($metadata->getColumnName('closingDate'))
|
||||
->setWhere($where)
|
||||
->setParameters($parameters)
|
||||
;
|
||||
|
||||
return $data;
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function buildWhereClause($context, array $args): array
|
||||
{
|
||||
list($query, $params) = parent::buildWhereClause($context, $args);
|
||||
$period = $this->em->getClassMetadata(AccompanyingPeriod::class);
|
||||
|
||||
$query .= " AND {$period->getColumnName('closingDate')} IS NOT NULL ";
|
||||
|
||||
return [ $query, $params ];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,11 +21,10 @@ namespace Chill\PersonBundle\Timeline;
|
||||
|
||||
use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
/**
|
||||
* Provide information for opening periods to timeline
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class TimelineAccompanyingPeriodOpening extends AbstractTimelineAccompanyingPeriod
|
||||
{
|
||||
@@ -46,14 +45,14 @@ class TimelineAccompanyingPeriodOpening extends AbstractTimelineAccompanyingPeri
|
||||
public function fetchQuery($context, array $args)
|
||||
{
|
||||
$metadata = $this->em
|
||||
->getClassMetadata('ChillPersonBundle:AccompanyingPeriod');
|
||||
->getClassMetadata(AccompanyingPeriod::class);
|
||||
|
||||
$data = $this->basicFetchQuery($context, $args);
|
||||
$query = $this->basicFetchQuery($context, $args);
|
||||
|
||||
$data['type'] = 'accompanying_period_opening';
|
||||
$data['date'] = $metadata->getColumnName('openingDate');
|
||||
$query->setKey('accompanying_period_opening')
|
||||
->setDate($metadata->getColumnName('openingDate'));
|
||||
|
||||
return $data;
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,17 +16,31 @@ services:
|
||||
class: Chill\PersonBundle\Timeline\TimelineAccompanyingPeriodOpening
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
- '@Symfony\Component\Security\Core\Security'
|
||||
- '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
||||
public: true
|
||||
tags:
|
||||
- { name: chill.timeline, context: 'person' }
|
||||
- { name: chill.timeline, context: 'center' }
|
||||
|
||||
chill.person.timeline.accompanying_period_closing:
|
||||
class: Chill\PersonBundle\Timeline\TimelineAccompanyingPeriodClosing
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
- '@Symfony\Component\Security\Core\Security'
|
||||
- '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
||||
public: true
|
||||
tags:
|
||||
- { name: chill.timeline, context: 'person' }
|
||||
- { name: chill.timeline, context: 'center' }
|
||||
|
||||
chill.person.security.authorization.person:
|
||||
class: Chill\PersonBundle\Security\Authorization\PersonVoter
|
||||
arguments:
|
||||
- "@chill.main.security.authorization.helper"
|
||||
tags:
|
||||
- { name: security.voter }
|
||||
- { name: chill.role }
|
||||
|
||||
chill.person.birthdate_validation:
|
||||
class: Chill\PersonBundle\Validator\Constraints\BirthdateValidator
|
||||
|
@@ -16,6 +16,7 @@ services:
|
||||
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface'
|
||||
$timelineBuilder: '@chill_main.timeline_builder'
|
||||
$paginatorFactory: '@chill_main.paginator_factory'
|
||||
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\PersonBundle\Controller\AccompanyingPeriodController:
|
||||
|
@@ -2,6 +2,7 @@ services:
|
||||
Chill\PersonBundle\Templating\Entity\PersonRender:
|
||||
arguments:
|
||||
$configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
|
||||
$engine: '@Symfony\Component\Templating\EngineInterface'
|
||||
tags:
|
||||
- 'chill.render_entity'
|
||||
|
||||
|
@@ -150,6 +150,8 @@ Update accompanying period: Mettre à jour une période d'accompagnement
|
||||
'Closing motive': 'Motif de clôture'
|
||||
'Person details': 'Détails de la personne'
|
||||
'Update details for %name%': 'Modifier détails de %name%'
|
||||
An accompanying period ends: Une periode d'accompagnement se clôture
|
||||
An accompanying period starts: Une période d'accompagnement est ouverte
|
||||
Any accompanying periods are open: Aucune période d'accompagnement ouverte
|
||||
An accompanying period is open: Une période d'accompagnement est ouverte
|
||||
Accompanying period list: Périodes d'accompagnement
|
||||
@@ -162,11 +164,10 @@ Pediod closing form is not valid: Le formulaire n'est pas valide
|
||||
Accompanying user: Accompagnant
|
||||
No accompanying user: Aucun accompagnant
|
||||
No data given: Pas d'information
|
||||
Participants: Personnes impliquées
|
||||
# pickAPersonType
|
||||
Pick a person: Choisir une personne
|
||||
|
||||
#address
|
||||
Since %date%: Depuis le %date%
|
||||
No address given: Pas d'adresse renseignée
|
||||
The address has been successfully updated: L'adresse a été mise à jour avec succès
|
||||
Update address for %name%: Mettre à jour une adresse pour %name%
|
||||
|
Reference in New Issue
Block a user