Merge branch 'dune-risky'

Conflicts:
	src/Bundle/ChillActivityBundle/config/services.yaml
	src/Bundle/ChillPersonBundle/translations/messages.fr.yml
This commit is contained in:
2021-06-02 16:23:45 +02:00
38 changed files with 1267 additions and 426 deletions

View File

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

View File

@@ -369,13 +369,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
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;
}

View File

@@ -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 }}&nbsp;:</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>

View File

@@ -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 }}&nbsp;:</dd>
<dt>
<ul>
{% for p in period.participations %}
<li>{{ 'Since %date%'|trans( {'%date%': p.startDate|format_date("long") } ) }}&nbsp;: {{ p.person|chill_entity_render_box({ 'addLink': true }) }}</li>
{% endfor %}
</ul>
</dt>
</div>
</div>

View File

@@ -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 = '';

View File

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

View File

@@ -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 ];
}
/**

View File

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

View File

@@ -24,17 +24,23 @@ 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.birthdate_validation:
class: Chill\PersonBundle\Validator\Constraints\BirthdateValidator

View File

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

View File

@@ -7,6 +7,7 @@ services:
Chill\PersonBundle\Templating\Entity\PersonRender:
arguments:
$configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
$engine: '@Symfony\Component\Templating\EngineInterface'
tags:
- 'chill.render_entity'

View File

@@ -152,6 +152,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
@@ -176,11 +178,10 @@ See accompanying periods: Voir les périodes d'accompagnement
See accompanying period: Voir cette période d'accompagnement
Referrer: Référent
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%