exports: share Scope and Job Aggregators

This commit is contained in:
2022-08-08 16:12:34 +02:00
parent fcd7ae3b8d
commit 643f37509f
8 changed files with 74 additions and 216 deletions

View File

@@ -1,15 +1,16 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
namespace Chill\PersonBundle\Export\Aggregator;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserJobRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\From;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class UserJobAggregator implements AggregatorInterface
final class JobAggregator implements AggregatorInterface
{
private UserJobRepository $jobRepository;
@@ -47,7 +48,7 @@ final class UserJobAggregator implements AggregatorInterface
*/
public function getQueryKeys($data): array
{
return ['userjob_aggregator'];
return ['job_aggregator'];
}
/**
@@ -79,15 +80,28 @@ final class UserJobAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acp.job', 'j');
$qb->addSelect('IDENTITY(acp.job) AS userjob_aggregator');
switch ($this->getBaseEntityAppliedOn($qb)) {
case 'acp':
$qb->join('acp.job', 'j');
$qb->addSelect('IDENTITY(acp.job) AS job_aggregator');
break;
case 'acpw':
$qb->join('acpw.referrers', 'r');
$qb->addSelect('IDENTITY(r.userJob) as job_aggregator');
break;
default:
throw new \Exception("Does not apply on that base entity");
}
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('userjob_aggregator');
$qb->addGroupBy('job_aggregator');
} else {
$qb->groupBy('userjob_aggregator');
$qb->groupBy('job_aggregator');
}
}
@@ -96,6 +110,14 @@ final class UserJobAggregator implements AggregatorInterface
*/
public function applyOn(): string
{
return Declarations::ACP_TYPE;
return Declarations::ACP_SHARED;
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
}
}

View File

@@ -1,15 +1,16 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
namespace Chill\PersonBundle\Export\Aggregator;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\ScopeRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\From;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class UserScopeAggregator implements AggregatorInterface
final class ScopeAggregator implements AggregatorInterface
{
private ScopeRepository $scopeRepository;
@@ -36,7 +37,9 @@ final class UserScopeAggregator implements AggregatorInterface
$s = $this->scopeRepository->find($value);
return $this->translatableStringHelper->localize($s->getName());
return $this->translatableStringHelper->localize(
$s->getName()
);
};
}
@@ -45,7 +48,7 @@ final class UserScopeAggregator implements AggregatorInterface
*/
public function getQueryKeys($data): array
{
return ['userscope_aggregator'];
return ['scope_aggregator'];
}
/**
@@ -77,15 +80,28 @@ final class UserScopeAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acp.scopes', 's');
$qb->addSelect('s.id as userscope_aggregator');
switch ($this->getBaseEntityAppliedOn($qb)) {
case 'acp':
$qb->join('acp.scopes', 's');
$qb->addSelect('s.id as scope_aggregator');
break;
case 'acpw':
$qb->join('acpw.referrers', 'r');
$qb->addSelect('IDENTITY(r.mainScope) as scope_aggregator');
break;
default:
throw new \Exception("Does not apply on that base entity");
}
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('userscope_aggregator');
$qb->addGroupBy('scope_aggregator');
} else {
$qb->groupBy('userscope_aggregator');
$qb->groupBy('scope_aggregator');
}
}
@@ -94,6 +110,14 @@ final class UserScopeAggregator implements AggregatorInterface
*/
public function applyOn(): string
{
return Declarations::ACP_TYPE;
return Declarations::ACP_SHARED;
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
}
}

View File

@@ -1,86 +0,0 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserJobRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class JobAggregator implements AggregatorInterface
{
private UserJobRepository $userJobRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(UserJobRepository $userJobRepository, TranslatableStringHelper $translatableStringHelper)
{
$this->userJobRepository = $userJobRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'r');
$qb->addSelect('IDENTITY(r.userJob) as job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('job_aggregator');
} else {
$qb->groupBy('job_aggregator');
}
}
public function applyOn()
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'User job';
}
$j = $this->userJobRepository->find($value);
return $this->translatableStringHelper->localize(
$j->getLabel());
};
}
public function getQueryKeys($data)
{
return ['job_aggregator'];
}
public function getTitle()
{
return 'Group social work actions by referrer job';
}
}

View File

@@ -1,86 +0,0 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\ScopeRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class ScopeAggregator implements AggregatorInterface
{
private ScopeRepository $scopeRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(ScopeRepository $scopeRepository, TranslatableStringHelper $translatableStringHelper)
{
$this->scopeRepository = $scopeRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'r');
$qb->addSelect('IDENTITY(r.mainScope) as scope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('scope_aggregator');
} else {
$qb->groupBy('scope_aggregator');
}
}
public function applyOn()
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'User scope';
}
$s = $this->scopeRepository->find($value);
return $this->translatableStringHelper->localize(
$s->getName());
};
}
public function getQueryKeys($data)
{
return ['scope_aggregator'];
}
public function getTitle()
{
return 'Group social work actions by referrer scope';
}
}