Fix bug in accompanying period export element

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

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');
}
}