exports: simplify with querybuilder method to getRootAlias

This commit is contained in:
Mathieu Jaumotte 2022-08-11 11:58:54 +02:00
parent 70488a935d
commit 6e467a62d4
4 changed files with 5 additions and 38 deletions

View File

@ -80,7 +80,7 @@ final class JobAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
switch ($this->getBaseEntityAppliedOn($qb)) {
switch ($qb->getRootAlias()) {
case 'acp':
$qb->join('acp.job', 'j');
@ -112,12 +112,4 @@ final class JobAggregator implements AggregatorInterface
{
return Declarations::ACP_SHARED;
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
}
}

View File

@ -40,7 +40,7 @@ final class ReferrerAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
switch ($this->getBaseEntityAppliedOn($qb)) {
switch ($qb->getRootAlias()) {
case 'acp':
$qb->join('acp.user', 'u');
@ -98,12 +98,4 @@ final class ReferrerAggregator implements AggregatorInterface
{
return 'Group by referrers';
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
}
}

View File

@ -80,7 +80,7 @@ final class ScopeAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
switch ($this->getBaseEntityAppliedOn($qb)) {
switch ($qb->getRootAlias()) {
case 'acp':
$qb->join('acp.scopes', 's');
@ -112,12 +112,4 @@ final class ScopeAggregator implements AggregatorInterface
{
return Declarations::ACP_SHARED;
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
}
}

View File

@ -75,11 +75,10 @@ class ReferrerFilter implements FilterInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
// Use querybuilder from alias to find which export context (indicator)
switch ($this->getBaseEntityAppliedOn($qb)) {
switch ($qb->getRootAlias()) {
case 'acp':
$clause = $qb->expr()->in('acp.user', ':referrers');
break;
@ -103,14 +102,6 @@ class ReferrerFilter implements FilterInterface
$qb->setParameter('referrers', $data['accepted_referrers']);
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
}
/**
* @inheritDoc
*/