Commit 4d5900d9 authored by Julien Fastré's avatar Julien Fastré

Fix bug in accompanying period export element

parent 11178441
......@@ -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
......@@ -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');
}
}
......
......@@ -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')
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment