Fix bug in accompanying period export element

This commit is contained in:
Julien Fastré 2019-03-20 12:28:28 +01:00
parent 111784410a
commit 4d5900d902
3 changed files with 34 additions and 11 deletions

View File

@ -25,3 +25,8 @@ Version 1.5.3
- add filtering on accompanying period
- fix problems in gender filter
Version 1.5.4
=============
- Fix bug in accompanying period filter

View File

@ -25,22 +25,34 @@ use Doctrine\ORM\QueryBuilder;
*/
class AbstractAccompanyingPeriodExportElement
{
protected function havingAccompanyingPeriodInJoin(QueryBuilder $query)
/**
* Return true if "accompanying_period" alias is present in the query alises.
*
* @param QueryBuilder $query
* @return bool
*/
protected function havingAccompanyingPeriodInJoin(QueryBuilder $query): bool
{
$joins = $query->getDQLPart('join');
$joins = $query->getDQLPart('join') ?? [];
foreach ($joins['person'] as $join) {
if ($join->getAlias() === 'accompanying_period') {
return true;
}
}
return false;
return (\in_array('accompanying_period', $query->getAllAliases()));
}
protected function addJoinAccompanyingPeriod(QueryBuilder $query)
/**
* Add the accompanying period alias to the query
*
* @param QueryBuilder $query
* @return void
* @throws \LogicException if the "person" alias is not present and attaching accompanying period is not possible
*/
protected function addJoinAccompanyingPeriod(QueryBuilder $query): void
{
if (FALSE === $this->havingAccompanyingPeriodInJoin($query)) {
if (FALSE === \in_array('person', $query->getAllAliases())) {
throw new \LogicException("the alias 'person' does not exists in "
. "query builder");
}
$query->join('person.accompanyingPeriods', 'accompanying_period');
}
}

View File

@ -89,7 +89,13 @@ class AccompanyingPeriodFilterTest extends AbstractFilterTest
->from('ChillPersonBundle:Person', 'person')
->join('person.accompanyingPeriods', 'accompanying_period')
// add a dummy where clause
->where('person.firstname IS NOT NULL')
->where('person.firstname IS NOT NULL'),
$em->createQueryBuilder()
->select('activity.date AS date')
->select('activity.attendee as attendee')
->from("ChillActivityBundle:Activity", 'activity')
->join('activity.person', 'person')
->join('person.center', 'center')
);
}
}