mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
exports: share Scope and Job Aggregators
This commit is contained in:
parent
fcd7ae3b8d
commit
643f37509f
@ -249,8 +249,8 @@ Country code: Code du pays
|
|||||||
|
|
||||||
# circles / scopes
|
# circles / scopes
|
||||||
Choose the circle: Choisir le cercle
|
Choose the circle: Choisir le cercle
|
||||||
Scope: Service
|
Scope: Cercle
|
||||||
Scopes: Services
|
Scopes: Cercles
|
||||||
|
|
||||||
#export
|
#export
|
||||||
|
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
namespace Chill\PersonBundle\Export\Aggregator;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AggregatorInterface;
|
use Chill\MainBundle\Export\AggregatorInterface;
|
||||||
use Chill\MainBundle\Repository\UserJobRepository;
|
use Chill\MainBundle\Repository\UserJobRepository;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Doctrine\ORM\Query\Expr\From;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
final class UserJobAggregator implements AggregatorInterface
|
final class JobAggregator implements AggregatorInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
private UserJobRepository $jobRepository;
|
private UserJobRepository $jobRepository;
|
||||||
@ -47,7 +48,7 @@ final class UserJobAggregator implements AggregatorInterface
|
|||||||
*/
|
*/
|
||||||
public function getQueryKeys($data): array
|
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)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
$qb->join('acp.job', 'j');
|
switch ($this->getBaseEntityAppliedOn($qb)) {
|
||||||
$qb->addSelect('IDENTITY(acp.job) AS userjob_aggregator');
|
|
||||||
|
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');
|
$groupBy = $qb->getDQLPart('groupBy');
|
||||||
|
|
||||||
if (!empty($groupBy)) {
|
if (!empty($groupBy)) {
|
||||||
$qb->addGroupBy('userjob_aggregator');
|
$qb->addGroupBy('job_aggregator');
|
||||||
} else {
|
} else {
|
||||||
$qb->groupBy('userjob_aggregator');
|
$qb->groupBy('job_aggregator');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +110,14 @@ final class UserJobAggregator implements AggregatorInterface
|
|||||||
*/
|
*/
|
||||||
public function applyOn(): string
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
namespace Chill\PersonBundle\Export\Aggregator;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AggregatorInterface;
|
use Chill\MainBundle\Export\AggregatorInterface;
|
||||||
use Chill\MainBundle\Repository\ScopeRepository;
|
use Chill\MainBundle\Repository\ScopeRepository;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Doctrine\ORM\Query\Expr\From;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
final class UserScopeAggregator implements AggregatorInterface
|
final class ScopeAggregator implements AggregatorInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
private ScopeRepository $scopeRepository;
|
private ScopeRepository $scopeRepository;
|
||||||
@ -36,7 +37,9 @@ final class UserScopeAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
$s = $this->scopeRepository->find($value);
|
$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
|
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)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
$qb->join('acp.scopes', 's');
|
switch ($this->getBaseEntityAppliedOn($qb)) {
|
||||||
$qb->addSelect('s.id as userscope_aggregator');
|
|
||||||
|
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');
|
$groupBy = $qb->getDQLPart('groupBy');
|
||||||
|
|
||||||
if (!empty($groupBy)) {
|
if (!empty($groupBy)) {
|
||||||
$qb->addGroupBy('userscope_aggregator');
|
$qb->addGroupBy('scope_aggregator');
|
||||||
} else {
|
} else {
|
||||||
$qb->groupBy('userscope_aggregator');
|
$qb->groupBy('scope_aggregator');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +110,14 @@ final class UserScopeAggregator implements AggregatorInterface
|
|||||||
*/
|
*/
|
||||||
public function applyOn(): string
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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';
|
|
||||||
}
|
|
||||||
}
|
|
@ -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';
|
|
||||||
}
|
|
||||||
}
|
|
@ -78,10 +78,8 @@ class ReferrerFilter implements FilterInterface
|
|||||||
|
|
||||||
$where = $qb->getDQLPart('where');
|
$where = $qb->getDQLPart('where');
|
||||||
|
|
||||||
$from_alias = $this->getEntityFromQB($qb);
|
|
||||||
|
|
||||||
// Use querybuilder from alias to find which export context (indicator)
|
// Use querybuilder from alias to find which export context (indicator)
|
||||||
switch ($from_alias) {
|
switch ($this->getBaseEntityAppliedOn($qb)) {
|
||||||
case 'acp':
|
case 'acp':
|
||||||
$clause = $qb->expr()->in('acp.user', ':referrers');
|
$clause = $qb->expr()->in('acp.user', ':referrers');
|
||||||
break;
|
break;
|
||||||
@ -92,7 +90,7 @@ class ReferrerFilter implements FilterInterface
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \Exception("Referrer filter doesn't apply on that entity");
|
throw new \Exception("Does not apply on that base entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($where instanceof Andx) {
|
if ($where instanceof Andx) {
|
||||||
@ -105,7 +103,7 @@ class ReferrerFilter implements FilterInterface
|
|||||||
$qb->setParameter('referrers', $data['accepted_referrers']);
|
$qb->setParameter('referrers', $data['accepted_referrers']);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getEntityFromQB(QueryBuilder $qb): string
|
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
|
||||||
{
|
{
|
||||||
/** @var From $from */
|
/** @var From $from */
|
||||||
$from = $qb->getDQLPart('from');
|
$from = $qb->getDQLPart('from');
|
||||||
|
@ -150,19 +150,19 @@ services:
|
|||||||
- { name: chill.export_filter, alias: accompanyingcourse_openbetweendates_filter }
|
- { name: chill.export_filter, alias: accompanyingcourse_openbetweendates_filter }
|
||||||
|
|
||||||
## Aggregators
|
## Aggregators
|
||||||
chill.person.export.aggregator_userscope:
|
chill.person.export.aggregator_scope:
|
||||||
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserScopeAggregator
|
class: Chill\PersonBundle\Export\Aggregator\ScopeAggregator
|
||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.export_aggregator, alias: accompanyingcourse_userscope_aggregator }
|
- { name: chill.export_aggregator, alias: accompanyingcourse_scope_aggregator }
|
||||||
|
|
||||||
chill.person.export.aggregator_userjob:
|
chill.person.export.aggregator_job:
|
||||||
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserJobAggregator
|
class: Chill\PersonBundle\Export\Aggregator\JobAggregator
|
||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.export_aggregator, alias: accompanyingcourse_userjob_aggregator }
|
- { name: chill.export_aggregator, alias: accompanyingcourse_job_aggregator }
|
||||||
|
|
||||||
chill.person.export.aggregator_socialissue:
|
chill.person.export.aggregator_socialissue:
|
||||||
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\SocialIssueAggregator
|
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\SocialIssueAggregator
|
||||||
|
@ -37,20 +37,6 @@ services:
|
|||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator }
|
- { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator }
|
||||||
|
|
||||||
chill.person.export.aggregator_job:
|
|
||||||
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\JobAggregator
|
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
tags:
|
|
||||||
- { name: chill.export_aggregator, alias: social_work_actions_job_aggregator }
|
|
||||||
|
|
||||||
chill.person.export.aggregator_scope:
|
|
||||||
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ScopeAggregator
|
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
tags:
|
|
||||||
- { name: chill.export_aggregator, alias: social_work_actions_scope_aggregator }
|
|
||||||
|
|
||||||
chill.person.export.aggregator_action_type:
|
chill.person.export.aggregator_action_type:
|
||||||
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ActionTypeAggregator
|
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ActionTypeAggregator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user