exports: add condition with distinct alias on join clauses

This commit is contained in:
2022-09-07 19:58:38 +02:00
parent 81359877c4
commit 1dcff2f23c
49 changed files with 343 additions and 220 deletions

View File

@@ -48,12 +48,12 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl
$qb->resetDQLPart('from');
$qb->from(HouseholdMember::class, 'member');
if (!in_array('person', $qb->getAllAliases(), true)) {
$qb->join('member.person', 'person');
if (!in_array('memberperson', $qb->getAllAliases(), true)) {
$qb->join('member.person', 'memberperson');
}
if (!in_array('center', $qb->getAllAliases(), true)) {
$qb->join('person.center', 'center');
if (!in_array('membercenter', $qb->getAllAliases(), true)) {
$qb->join('memberperson.center', 'membercenter');
}
$qb->andWhere($qb->expr()->andX(

View File

@@ -37,8 +37,11 @@ final class MaritalStatusAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('person.maritalStatus', 'ms');
$qb->addSelect('ms.id as marital_status_aggregator');
if (!in_array('personmarital', $qb->getAllAliases(), true)) {
$qb->join('person.maritalStatus', 'personmarital');
}
$qb->addSelect('personmarital.id as marital_status_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -38,8 +38,11 @@ final class ActionTypeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.socialAction', 'sa');
$qb->addSelect('sa.id as action_type_aggregator');
if (!in_array('acpwsocialaction', $qb->getAllAliases(), true)) {
$qb->join('acpw.socialAction', 'acpwsocialaction');
}
$qb->addSelect('acpwsocialaction.id as action_type_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -37,8 +37,11 @@ final class GoalAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.goals', 'g');
$qb->addSelect('g.id as goal_aggregator');
if (!in_array('goal', $qb->getAllAliases(), true)) {
$qb->join('acpw.goals', 'goal');
}
$qb->addSelect('goal.id as goal_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -39,9 +39,11 @@ final class JobAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
}
$qb->addSelect('IDENTITY(u.userJob) as job_aggregator');
$qb->addSelect('IDENTITY(acpwuser.userJob) as job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -39,9 +39,11 @@ final class ReferrerAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
}
$qb->addSelect('u.id AS referrer_aggregator');
$qb->addSelect('acpwuser.id AS referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -37,10 +37,19 @@ final class ResultAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.results', 'res');
$qb->join('acpw.goals', 'g');
$qb->join('g.results', 'gres');
$qb->addSelect('res.id, IDENTITY(g.results) as result_aggregator');
if (!in_array('acpwresult', $qb->getAllAliases(), true)) {
$qb->join('acpw.results', 'acpwresult');
}
if (!in_array('goal', $qb->getAllAliases(), true)) {
$qb->join('acpw.goals', 'goal');
}
if (!in_array('goalresult', $qb->getAllAliases(), true)) {
$qb->join('goal.results', 'goalresult');
}
$qb->addSelect('acpwresult.id, IDENTITY(goal.results) as result_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -39,9 +39,11 @@ final class ScopeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
}
$qb->addSelect('IDENTITY(u.mainScope) as scope_aggregator');
$qb->addSelect('IDENTITY(acpwuser.mainScope) as scope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -45,12 +45,16 @@ class ActivityTypeFilter implements FilterInterface
$qb->resetDQLPart('from');
$qb->from('ChillActivityBundle:Activity', 'activity');
$qb
->join('activity.accompanyingPeriod', 'acp')
->join('activity.activityType', 'aty');
if (!in_array('actacp', $qb->getAllAliases(), true)) {
$qb->join('activity.accompanyingPeriod', 'actacp');
}
if (!in_array('acttype', $qb->getAllAliases(), true)) {
$qb->join('activity.activityType', 'acttype');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('aty.id', ':activitytypes');
$clause = $qb->expr()->in('acttype.id', ':activitytypes');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -47,12 +47,12 @@ class SocialActionFilter implements FilterInterface
$qb->join('acp.works', 'acpw');
}
if (!in_array('acpw', $qb->getAllAliases(), true)) {
$qb->join('acpw.socialAction', 'sa');
if (!in_array('acpwsocialaction', $qb->getAllAliases(), true)) {
$qb->join('acpw.socialAction', 'acpwsocialaction');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('sa.id', ':socialactions');
$clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -39,18 +39,29 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('ChillPersonBundle:Person\ResidentialAddress', 'ra');
$qb->from('ChillPersonBundle:Person\ResidentialAddress', 'resaddr');
$qb->join('ra.person', 'person');
$qb->join('person.center', 'center');
$qb->join('ra.hostThirdParty', 't');
$qb->join('t.categories', 'tc');
if (!in_array('resaddrperson', $qb->getAllAliases(), true)) {
$qb->join('resaddr.person', 'resaddrperson');
}
if (!in_array('resaddrcenter', $qb->getAllAliases(), true)) {
$qb->join('resaddrperson.center', 'resaddrcenter');
}
if (!in_array('tparty', $qb->getAllAliases(), true)) {
$qb->join('resaddr.hostThirdParty', 'tparty');
}
if (!in_array('tpartycat', $qb->getAllAliases(), true)) {
$qb->join('tparty.categories', 'tpartycat');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->isNotNull('ra.hostThirdParty'),
$qb->expr()->between(':date', 'ra.startDate', 'ra.endDate'),
$qb->expr()->in('tc.id', ':type')
$qb->expr()->isNotNull('resaddr.hostThirdParty'),
$qb->expr()->between(':date', 'resaddr.startDate', 'resaddr.endDate'),
$qb->expr()->in('tpartycat.id', ':type')
);
if ($where instanceof Expr\Andx) {

View File

@@ -26,13 +26,18 @@ class ResidentialAddressAtUserFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('ChillPersonBundle:Person\ResidentialAddress', 'ra');
$qb->from('ChillPersonBundle:Person\ResidentialAddress', 'resaddr');
$qb->join('ra.person', 'person');
$qb->join('person.center', 'center');
if (!in_array('resaddrperson', $qb->getAllAliases(), true)) {
$qb->join('resaddr.person', 'resaddrperson');
}
if (!in_array('resaddrcenter', $qb->getAllAliases(), true)) {
$qb->join('resaddrperson.center', 'resaddrcenter');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->isNotNull('ra.hostPerson');
$clause = $qb->expr()->isNotNull('resaddr.hostPerson');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -42,10 +42,12 @@ class JobFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('u.userJob', ':job');
$clause = $qb->expr()->in('acpwuser.userJob', ':job');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -36,10 +36,12 @@ class ReferrerFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('u', ':agents');
$clause = $qb->expr()->in('acpwuser', ':agents');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -42,10 +42,12 @@ class ScopeFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('u.mainScope', ':scope');
$clause = $qb->expr()->in('acpwuser.mainScope', ':scope');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -79,8 +79,8 @@ final class ReferrerFilterTest extends AbstractFilterTest
->select('acpw.id'),
$em->createQueryBuilder()
->from('ChillPersonBundle:AccompanyingPeriod\AccompanyingPeriodWork', 'acpw')
->join('acpw.referrers', 'r')
->select('r.id'),
->join('acpw.referrers', 'acpwuser')
->select('acpwuser.id'),
];
}
}