mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch 'master' into 38_modal_on-the-fly
This commit is contained in:
@@ -390,13 +390,13 @@ class AccompanyingPeriodController extends AbstractController
|
||||
/** @var Person $person */
|
||||
$person = $this->_getPerson($person_id);
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where($criteria->expr()->eq('id', $period_id));
|
||||
|
||||
/* @var $period AccompanyingPeriod */
|
||||
$period = $person->getAccompanyingPeriods()
|
||||
->matching($criteria)
|
||||
->first();
|
||||
$period = \array_filter(
|
||||
$person->getAccompanyingPeriods(),
|
||||
function (AccompanyingPeriod $p) use ($period_id) {
|
||||
return $p->getId() === ($period_id);
|
||||
}
|
||||
)[0] ?? NULL;
|
||||
|
||||
if ($period === NULL) {
|
||||
throw $this->createNotFoundException('period not found');
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
@@ -447,12 +443,13 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
*/
|
||||
public function getParticipationsContainsPerson(Person $person): Collection
|
||||
{
|
||||
return $this->getParticipations($person)->filter(
|
||||
function(AccompanyingPeriodParticipation $participation) use ($person) {
|
||||
if ($person === $participation->getPerson()) {
|
||||
return $participation;
|
||||
return $this
|
||||
->getParticipations()
|
||||
->filter(
|
||||
static function(AccompanyingPeriodParticipation $participation) use ($person): bool {
|
||||
return $person === $participation->getPerson();
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,12 +459,13 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
*/
|
||||
public function getOpenParticipationContainsPerson(Person $person): ?AccompanyingPeriodParticipation
|
||||
{
|
||||
$collection = $this->getParticipationsContainsPerson($person)->filter(
|
||||
function(AccompanyingPeriodParticipation $participation) use ($person) {
|
||||
if (NULL === $participation->getEndDate()) {
|
||||
return $participation;
|
||||
$collection = $this
|
||||
->getParticipationsContainsPerson($person)
|
||||
->filter(
|
||||
static function(AccompanyingPeriodParticipation $participation): bool {
|
||||
return null === $participation->getEndDate();
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
return $collection->count() > 0 ? $collection->first() : NULL;
|
||||
}
|
||||
@@ -557,15 +555,16 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
$participation = $this->getParticipationsContainsPerson($person);
|
||||
if (!null === $participation)
|
||||
$participation = $this->getOpenParticipationContainsPerson($person);
|
||||
|
||||
if (null === $participation)
|
||||
{
|
||||
$person = $participation->getPerson();
|
||||
$periods = $person->getAccompanyingPeriodsOrdered();
|
||||
return end($periods) === $this;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
$periods = $participation->getPerson()->getAccompanyingPeriodsOrdered();
|
||||
|
||||
return end($periods) === $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -825,14 +824,18 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
/**
|
||||
* Get a list of all persons which are participating to this course
|
||||
*
|
||||
* @psalm-return Collection<int, Person>
|
||||
*/
|
||||
public function getPersons(): Collection
|
||||
{
|
||||
return $this->participations->map(
|
||||
function(AccompanyingPeriodParticipation $participation) {
|
||||
return $participation->getPerson();
|
||||
}
|
||||
);
|
||||
return $this
|
||||
->participations
|
||||
->map(
|
||||
static function(AccompanyingPeriodParticipation $participation): Person {
|
||||
return $participation->getPerson();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTimeInterface $datetime): self
|
||||
|
@@ -21,31 +21,19 @@ namespace Chill\PersonBundle\Form\ChoiceLoader;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
|
||||
/**
|
||||
* Class PersonChoiceLoader
|
||||
*
|
||||
* @package Chill\PersonBundle\Form\ChoiceLoader
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Allow to load a list of person
|
||||
*/
|
||||
class PersonChoiceLoader implements ChoiceLoaderInterface
|
||||
{
|
||||
/**
|
||||
* @var EntityRepository
|
||||
*/
|
||||
protected $personRepository;
|
||||
protected PersonRepository $personRepository;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $lazyLoadedPersons = [];
|
||||
protected array $lazyLoadedPersons = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $centers = [];
|
||||
protected array $centers = [];
|
||||
|
||||
/**
|
||||
* PersonChoiceLoader constructor.
|
||||
@@ -54,7 +42,7 @@ class PersonChoiceLoader implements ChoiceLoaderInterface
|
||||
* @param array|null $centers
|
||||
*/
|
||||
public function __construct(
|
||||
EntityRepository $personRepository,
|
||||
PersonRepository $personRepository,
|
||||
array $centers = null
|
||||
) {
|
||||
$this->personRepository = $personRepository;
|
||||
|
@@ -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>
|
||||
|
@@ -14,14 +14,10 @@ class SocialIssueNormalizer implements NormalizerInterface, NormalizerAwareInter
|
||||
|
||||
use NormalizerAwareTrait;
|
||||
|
||||
/**
|
||||
* @param SocialIssueRender $render
|
||||
*/
|
||||
public function __construct(SocialIssueRender $render)
|
||||
{
|
||||
$this->render = $render;
|
||||
}
|
||||
|
||||
|
||||
public function normalize($socialIssue, string $format = null, array $context = [])
|
||||
{
|
||||
|
@@ -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 = '';
|
||||
|
@@ -28,7 +28,7 @@ class AccompanyingCourseControllerTest extends WebTestCase
|
||||
$this->assertResponseRedirects();
|
||||
$location = $this->client->getResponse()->headers->get('Location');
|
||||
|
||||
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/show$|", $location));
|
||||
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/edit$|", $location));
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class AccompanyingCourseControllerTest extends WebTestCase
|
||||
$location = $this->client->getResponse()->headers->get('Location');
|
||||
$matches = [];
|
||||
|
||||
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/show$|", $location, $matches));
|
||||
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/edit$|", $location, $matches));
|
||||
$id = $matches[1];
|
||||
|
||||
$period = self::$container->get(EntityManagerInterface::class)
|
||||
|
@@ -148,7 +148,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
* Test the closing of a periods
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we fill the close form (at /en/person/[id]/accompanying-period/close
|
||||
* and we fill the close form (at /fr/person/[id]/accompanying-period/close
|
||||
* with : dateClosing: 2015-02-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
@@ -158,10 +158,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testClosingCurrentPeriod()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/close');
|
||||
|
||||
$form = $crawler->selectButton('Close accompanying period')->form();
|
||||
|
||||
$form = $crawler->selectButton('Clôre la période')->form();
|
||||
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
@@ -171,7 +171,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
$cr = $this->client->submit($form);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(
|
||||
'/en/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'/fr/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'the server redirects to /accompanying-period page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
@@ -182,7 +182,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
* Test the closing of a periods
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we fill the close form (at /en/person/[id]/accompanying-period/close
|
||||
* and we fill the close form (at /fr/person/[id]/accompanying-period/close
|
||||
* with : dateClosing: 2014-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
@@ -192,10 +192,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testClosingCurrentPeriodWithDateClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/close');
|
||||
|
||||
$form = $crawler->selectButton('Close accompanying period')->form();
|
||||
$form = $crawler->selectButton('Clôre la période')->form();
|
||||
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
@@ -223,10 +223,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testAddNewPeriodBeforeActual()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
@@ -237,7 +237,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(
|
||||
'/en/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'/fr/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'the server redirects to /accompanying-period page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
@@ -257,10 +257,13 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testCreatePeriodWithClosingAfterCurrentFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$this->markTestSkipped("Multiple period may now cover. This test is kept ".
|
||||
"in case of a configuration may add this feature again");
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form = $crawler->selectButton("Créer une période d'accompagnement")->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
@@ -289,10 +292,13 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testCreatePeriodWithOpeningAndClosingAfterCurrentFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$this->markTestSkipped("Multiple period may now cover. This test is kept ".
|
||||
"in case of a configuration may add this feature again");
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form = $crawler->selectButton("Créer une période d'accompagnement")->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
@@ -330,10 +336,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();;
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
@@ -361,10 +367,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testCreatePeriodWithClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
@@ -403,10 +409,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
@@ -444,10 +450,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
@@ -498,7 +504,8 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
//$criteria->where(Criteria::expr()->eq('openingDate', \DateTime::createFromFormat()))
|
||||
$firstPeriod = reset($periods);
|
||||
$lastPeriod = end($periods);
|
||||
|
||||
|
||||
$this->markTestSkipped("From here, the test should be rewritten");
|
||||
// test that it is not possible to open the first period in the list
|
||||
$this->client->request('GET',
|
||||
sprintf('/fr/person/%d/accompanying-period/%d/re-open', $this->person->getId(), reset($periods)->getId())
|
||||
@@ -523,4 +530,4 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
"Test the response is a redirection => the period is re-opened");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AdminControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/{_locale}/admin/person');
|
||||
}
|
||||
|
||||
}
|
@@ -25,7 +25,7 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DomCrawler\Form;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use \Symfony\Component\BrowserKit\Client;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
|
||||
/**
|
||||
* Test creation and deletion for persons
|
||||
@@ -34,7 +34,7 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
private Client $client;
|
||||
private KernelBrowser $client;
|
||||
|
||||
const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]';
|
||||
const LASTNAME_INPUT = "chill_personbundle_person_creation[lastName]";
|
||||
@@ -59,8 +59,8 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
string $firstname = 'God',
|
||||
string $lastname = 'Jesus'
|
||||
) {
|
||||
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname);
|
||||
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname);
|
||||
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname.'_'.uniqid());
|
||||
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname.'_'.uniqid());
|
||||
$creationForm->get(self::GENDER_INPUT)->select("man");
|
||||
$date = new \DateTime('1947-02-01');
|
||||
$creationForm->get(self::BIRTHDATE_INPUT)->setValue($date->format('d-m-Y'));
|
||||
@@ -114,20 +114,6 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $form
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testForgedNullGender(Form $form)
|
||||
{
|
||||
$form->get(self::FIRSTNAME_INPUT)->setValue('john');
|
||||
$form->get(self::LASTNAME_INPUT)->setValue('doe');
|
||||
$date = new \DateTime('1947-02-01');
|
||||
$form->get(self::BIRTHDATE_INPUT)->setValue($date->format('d-m-Y'));
|
||||
$this->client->submit($form);
|
||||
$this->assertResponseStatusCodeSame(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the creation of a valid person.
|
||||
@@ -140,8 +126,8 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
{
|
||||
$this->fillAValidCreationForm($form);
|
||||
$client = $this->client;
|
||||
$client->submit($form);
|
||||
|
||||
$crawler = $client->submit($form);
|
||||
|
||||
$this->assertTrue((bool)$client->getResponse()->isRedirect(),
|
||||
"a valid form redirect to url /{_locale}/person/{personId}/general/edit");
|
||||
$client->followRedirect();
|
||||
|
@@ -20,18 +20,16 @@
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
//ini_set('memory_limit', '-1');
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
|
||||
|
||||
/**
|
||||
* Test the edition of persons
|
||||
*
|
||||
* As I am logged in as "center a_social"
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PersonControllerUpdateTest extends WebTestCase
|
||||
{
|
||||
@@ -71,8 +69,8 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
||||
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
$this->editUrl = '/fr/person/'.$this->person->getId().'/general/edit';
|
||||
$this->viewUrl = '/fr/person/'.$this->person->getId().'/general';
|
||||
|
||||
$this->client = $this->getClientAuthenticated();
|
||||
}
|
||||
@@ -104,10 +102,10 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
public function testHiddenFielsArePresent()
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
|
||||
$configurables = array('placeOfBirth', 'phonenumber', 'email',
|
||||
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus');
|
||||
$form = $crawler->selectButton('Submit')->form(); //;
|
||||
$form = $crawler->selectButton('Enregistrer')->form(); //;
|
||||
|
||||
foreach($configurables as $key) {
|
||||
$this->assertTrue($form->has('chill_personbundle_person['.$key.']'));
|
||||
@@ -162,18 +160,18 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
$form = $crawler->selectButton('Enregistrer')
|
||||
->form();
|
||||
//transform countries into value if needed
|
||||
switch ($field) {
|
||||
case 'nationality':
|
||||
case 'countryOfBirth':
|
||||
if ($value !== NULL) {
|
||||
if (FALSE === empty($value)) {
|
||||
$country = $this->em->getRepository('ChillMainBundle:Country')
|
||||
->findOneByCountryCode($value);
|
||||
$transformedValue = $country->getId();
|
||||
} else {
|
||||
$transformedValue = NULL;
|
||||
$transformedValue = '';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -208,7 +206,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
$selectedLanguages = array('en', 'an', 'bbj');
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
$form = $crawler->selectButton('Enregistrer')
|
||||
->form();
|
||||
$form->get('chill_personbundle_person[spokenLanguages]')
|
||||
->setValue($selectedLanguages);
|
||||
@@ -238,7 +236,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
$form = $crawler->selectButton('Enregistrer')
|
||||
->form();
|
||||
$form->get('chill_personbundle_person['.$field.']')
|
||||
->setValue($value);
|
||||
@@ -264,7 +262,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ],
|
||||
['placeOfBirth', 'none place', function(Person $person) { return $person->getPlaceOfBirth(); }],
|
||||
['birthdate', '15-12-1980', function(Person $person) { return $person->getBirthdate()->format('d-m-Y'); }],
|
||||
['phonenumber', '0123456789', function(Person $person) { return $person->getPhonenumber(); }],
|
||||
['phonenumber', '+32123456789', function(Person $person) { return $person->getPhonenumber(); }],
|
||||
['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }],
|
||||
['countryOfBirth', 'BE', function(Person $person) { return $person->getCountryOfBirth()->getCountryCode(); }],
|
||||
['nationality', 'FR', function(Person $person) { return $person->getNationality()->getCountryCode(); }],
|
||||
@@ -275,7 +273,6 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
['countryOfBirth', NULL, function(Person $person) { return $person->getCountryOfBirth(); }],
|
||||
['nationality', NULL, function(Person $person) { return $person->getNationality(); }],
|
||||
['gender', Person::FEMALE_GENDER, function(Person $person) { return $person->getGender(); }],
|
||||
['maritalStatus', NULL, function(Person $person) {return $person->getMaritalStatus(); }]
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -22,10 +22,6 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Marc Ducobu <marc.ducobu@champs-libres.coop>
|
||||
*/
|
||||
class PersonControllerViewTestWithHiddenFields extends WebTestCase
|
||||
{
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||
@@ -66,6 +62,7 @@ class PersonControllerViewTestWithHiddenFields extends WebTestCase
|
||||
*/
|
||||
public function testViewPerson()
|
||||
{
|
||||
$this->markTestSkipped("This configuration does not allow multiple environnements");
|
||||
$client = static::createClient(
|
||||
array('environment' => 'test_with_hidden_fields'),
|
||||
array(
|
||||
|
@@ -26,7 +26,6 @@ use Chill\PersonBundle\Form\Type\PickPersonType;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PickPersonTypeTest extends KernelTestCase
|
||||
{
|
||||
@@ -59,6 +58,8 @@ class PickPersonTypeTest extends KernelTestCase
|
||||
|
||||
public function testWithoutOption()
|
||||
{
|
||||
$this->markTestSkipped("need to inject locale into url generator without request");
|
||||
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array())
|
||||
->getForm();
|
||||
@@ -86,7 +87,8 @@ class PickPersonTypeTest extends KernelTestCase
|
||||
*/
|
||||
public function testWithOptionCenter()
|
||||
{
|
||||
$center = $this->container->get('doctrine.orm.entity_manager')
|
||||
$this->markTestSkipped("need to inject locale into url generator without request");
|
||||
$center = self::$container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'))
|
||||
;
|
||||
@@ -117,7 +119,8 @@ class PickPersonTypeTest extends KernelTestCase
|
||||
*/
|
||||
public function testWithOptionCenters()
|
||||
{
|
||||
$centers = $this->container->get('doctrine.orm.entity_manager')
|
||||
$this->markTestSkipped("need to inject locale into url generator without request");
|
||||
$centers = self::$container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findAll()
|
||||
;
|
||||
@@ -149,6 +152,7 @@ class PickPersonTypeTest extends KernelTestCase
|
||||
public function testWithInvalidOptionCenters()
|
||||
{
|
||||
|
||||
$this->markTestSkipped("need to inject locale into url generator without request");
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array(
|
||||
'centers' => array('string')
|
||||
@@ -158,6 +162,7 @@ class PickPersonTypeTest extends KernelTestCase
|
||||
|
||||
public function testWithOptionRoleInvalid()
|
||||
{
|
||||
$this->markTestSkipped("need to inject locale into url generator without request");
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array(
|
||||
'role' => new \Symfony\Component\Security\Core\Role\Role('INVALID')
|
||||
|
@@ -52,75 +52,75 @@ class PersonSearchTest extends WebTestCase
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstName()
|
||||
public function testSearchByLastName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Depardieu');
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNameLower()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:depardieu');
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Gérard');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNamePartim()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Dep');
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Ger');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testFirstNameAccentued()
|
||||
public function testLastNameAccentued()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:manço');
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person lastname:manço');
|
||||
|
||||
$this->assertRegExp('/Manço/', $crawlerSpecial->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:manco');
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:manco');
|
||||
|
||||
$this->assertRegExp('/Manço/', $crawlerNoSpecial->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastName()
|
||||
|
||||
public function testSearchByFirstName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Jean');
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastNameLower()
|
||||
public function testSearchByFirstNameLower2()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:jean');
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastNamePartim()
|
||||
public function testSearchByFirstNamePartim2()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:ean');
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:ean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastNameAccented()
|
||||
public function testSearchByFirstNameAccented()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person lastname:Gérard');
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:Gérard');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerSpecial->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:Gerard');
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:Gerard');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerNoSpecial->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineFirstnameAndNationality()
|
||||
public function testSearchCombineLastnameAndNationality()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Depardieu nationality:RU');
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu nationality:RU');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawler->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
@@ -130,7 +130,7 @@ class PersonSearchTest extends WebTestCase
|
||||
|
||||
public function testSearchCombineLastnameAndFirstName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Depardieu lastname:Jean');
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu firstname:Jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
@@ -146,17 +146,17 @@ class PersonSearchTest extends WebTestCase
|
||||
$this->assertRegExp('/Bart/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineBirthdateAndFirstName()
|
||||
public function testSearchCombineBirthdateAndLastName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27 firstname:(Van Snick)');
|
||||
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27 lastname:(Van Snick)');
|
||||
|
||||
$this->assertRegExp('/Bart/', $crawler->text());
|
||||
$this->assertNotRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineGenderAndFirstName()
|
||||
public function testSearchCombineGenderAndLastName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person gender:woman firstname:(Depardieu)');
|
||||
$crawler = $this->generateCrawlerForSearch('@person gender:woman lastname:(Depardieu)');
|
||||
|
||||
$this->assertRegExp('/Charline/', $crawler->text());
|
||||
$this->assertNotRegExp('/Gérard/', $crawler->text());
|
||||
@@ -171,8 +171,6 @@ class PersonSearchTest extends WebTestCase
|
||||
$this->assertNotRegExp('/Jean/', $crawler->text());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testDefaultAccented()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person manço');
|
||||
@@ -215,7 +213,7 @@ class PersonSearchTest extends WebTestCase
|
||||
$client = $this->getAuthenticatedClient($username);
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', array(
|
||||
'q' => $pattern
|
||||
'q' => $pattern,
|
||||
));
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
@@ -50,10 +50,10 @@ class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controlle
|
||||
"the timeline page loads sucessfully");
|
||||
$this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(),
|
||||
"the timeline page contains multiple div inside a .timeline element");
|
||||
$this->assertContains("Ouverture d'une période d'accompagnement",
|
||||
$this->assertContains(" Une période d'accompagnement est ouverte",
|
||||
$crawler->filter('.timeline')->text(),
|
||||
"the text 'une période d'accompagnement a été ouverte' is present");
|
||||
$this->assertContains("Fermeture de la période d'accompagnement",
|
||||
$this->assertContains("Une periode d'accompagnement se clôture",
|
||||
$crawler->Filter('.timeline')->text(),
|
||||
"the text 'Une période d'accompagnement a été fermée' is present");
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -24,18 +24,32 @@ 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
|
||||
arguments:
|
||||
|
@@ -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:
|
||||
|
@@ -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'
|
||||
|
||||
|
@@ -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
|
||||
@@ -165,6 +167,7 @@ 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
|
||||
Create an accompanying course: Créer un parcours
|
||||
This accompanying course is still a draft: Ce parcours est à l'état brouillon
|
||||
Associated peoples: Usagers concernés
|
||||
@@ -179,8 +182,6 @@ Referrer: Référent
|
||||
# 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