Merge branch '111_exports' into social_action_exports

This commit is contained in:
Julie Lenaerts 2022-08-16 10:19:04 +02:00
commit afbedf3a4a
32 changed files with 561 additions and 191 deletions

View File

@ -17,7 +17,7 @@ use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Export\Declarations as ExportDeclarations;
use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\Query;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
@ -100,9 +100,9 @@ class CountActivityLinkedToACP implements ExportInterface, GroupedExportInterfac
public function supportsModifiers()
{
return [
ExportDeclarations::PERSON_TYPE,
Declarations::ACTIVITY,
ExportDeclarations::ACP_SHARED
PersonDeclarations::PERSON_TYPE,
//PersonDeclarations::ACP_TYPE,
];
}

View File

@ -78,10 +78,10 @@ final class EvaluationAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb
->join('acp.works', 'acpw')
->join('acpw.accompanyingPeriodWorkEvaluations', 'we')
;
if (!in_array('acpw', $qb->getAllAliases())) {
$qb->join('acp.works', 'acpw');
}
$qb->join('acpw.accompanyingPeriodWorkEvaluations', 'we');
$qb->addSelect('IDENTITY(we.evaluation) AS evaluation_aggregator');

View File

@ -1,6 +1,6 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator;
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserJobRepository;
@ -80,21 +80,9 @@ final class JobAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
switch ($this->getBaseEntityAppliedOn($qb)) {
$qb->join('acp.job', 'j');
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");
}
$qb->addSelect('IDENTITY(acp.job) AS job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@ -110,14 +98,6 @@ final class JobAggregator implements AggregatorInterface
*/
public function applyOn(): string
{
return Declarations::ACP_SHARED;
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
return Declarations::ACP_TYPE;
}
}

View File

@ -9,7 +9,7 @@
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator;
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserRepository;
@ -40,21 +40,9 @@ final class ReferrerAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
switch ($this->getBaseEntityAppliedOn($qb)) {
$qb->join('acp.user', 'u');
case 'acp':
$qb->join('acp.user', 'u');
$qb->addSelect('u.id AS referrer_aggregator');
break;
case 'acpw':
$qb->join('acpw.referrers', 'r');
$qb->addSelect('r.id AS referrer_aggregator');
break;
default:
throw new \Exception("Does not apply on that base entity");
}
$qb->addSelect('u.id AS referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@ -68,7 +56,7 @@ final class ReferrerAggregator implements AggregatorInterface
public function applyOn(): string
{
return Declarations::ACP_SHARED;
return Declarations::ACP_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
@ -98,12 +86,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

@ -1,6 +1,6 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator;
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\ScopeRepository;
@ -80,21 +80,9 @@ final class ScopeAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
switch ($this->getBaseEntityAppliedOn($qb)) {
$qb->join('acp.scopes', 's');
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");
}
$qb->addSelect('s.id as scope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@ -110,14 +98,6 @@ final class ScopeAggregator implements AggregatorInterface
*/
public function applyOn(): string
{
return Declarations::ACP_SHARED;
}
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
{
/** @var From $from */
$from = $qb->getDQLPart('from');
return $from[0]->getAlias();
return Declarations::ACP_TYPE;
}
}

View File

@ -76,7 +76,9 @@ final class SocialActionAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acp.works', 'acpw');
if (!in_array('acpw', $qb->getAllAliases())) {
$qb->join('acp.works', 'acpw');
}
$qb->addSelect('IDENTITY(acpw.socialAction) AS socialaction_aggregator'); // DISTINCT ??

View File

@ -76,8 +76,7 @@ class EvaluationTypeAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('eval.evaluation', 'ev');
$qb->addSelect('ev.id AS evaluationtype_aggregator');
$qb->addSelect('IDENTITY(eval.evaluation) AS evaluationtype_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@ -76,6 +76,10 @@ class ChildrenNumberAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('composition', $qb->getAllAliases())) {
$qb->join('household.compositions', 'composition');
}
$qb->addSelect('composition.numberOfChildren AS childrennumber_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@ -83,6 +83,10 @@ class CompositionAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('composition', $qb->getAllAliases())) {
$qb->join('household.compositions', 'composition');
}
$qb->addSelect('IDENTITY(composition.householdCompositionType) AS composition_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@ -0,0 +1,103 @@
<?php
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\Query\Expr\From;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class JobAggregator implements AggregatorInterface
{
private UserJobRepository $jobRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
UserJobRepository $jobRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->jobRepository = $jobRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function($value): string {
if ($value === '_header') {
return 'Job';
}
$j = $this->jobRepository->find($value);
return $this->translatableStringHelper->localize(
$j->getLabel()
);
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['job_aggregator'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by treating agent job';
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
$qb->addSelect('IDENTITY(u.userJob) as job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('job_aggregator');
} else {
$qb->groupBy('job_aggregator');
}
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@ -0,0 +1,89 @@
<?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\UserRepository;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\From;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class ReferrerAggregator implements AggregatorInterface
{
private UserRepository $userRepository;
private UserRender $userRender;
public function __construct(
UserRepository $userRepository,
UserRender $userRender
) {
$this->userRepository = $userRepository;
$this->userRender = $userRender;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
$qb->addSelect('u.id AS referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('referrer_aggregator');
} else {
$qb->groupBy('referrer_aggregator');
}
}
public function applyOn(): string
{
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 'Referrer';
}
$r = $this->userRepository->find($value);
return $this->userRender->renderString($r, []);
};
}
public function getQueryKeys($data): array
{
return ['referrer_aggregator'];
}
public function getTitle(): string
{
return 'Group by treating agent';
}
}

View File

@ -0,0 +1,103 @@
<?php
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\Query\Expr\From;
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;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ($value === '_header') {
return 'Scope';
}
$s = $this->scopeRepository->find($value);
return $this->translatableStringHelper->localize(
$s->getName()
);
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['scope_aggregator'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by treating agent scope';
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
$qb->addSelect('IDENTITY(u.mainScope) as scope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('scope_aggregator');
} else {
$qb->groupBy('scope_aggregator');
}
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@ -22,8 +22,6 @@ abstract class Declarations
public const ACP_TYPE = 'accompanying_period';
public const ACP_SHARED = 'accompanying_period_shared';
public const SOCIAL_WORK_ACTION_TYPE = 'social_actions';
public const EVAL_TYPE = 'evaluation';

View File

@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@ -26,15 +27,12 @@ use LogicException;
class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
{
/**
* @var EntityManagerInterface
*/
protected $entityManager;
protected EntityRepository $repository;
public function __construct(
EntityManagerInterface $em
) {
$this->entityManager = $em;
$this->repository = $em->getRepository(AccompanyingPeriod::class);
}
public function buildForm(FormBuilderInterface $builder): void
@ -88,12 +86,9 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$qb = $this->entityManager->createQueryBuilder();
$expr = $qb->expr();
$qb = $this->repository->createQueryBuilder('acp');
$qb->select('COUNT(acp.id) AS export_result')
->from('ChillPersonBundle:AccompanyingPeriod', 'acp')
;
$qb->select('COUNT(acp.id) AS export_result');
return $qb;
}
@ -105,7 +100,9 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
public function supportsModifiers(): array
{
return [Declarations::ACP_TYPE, Declarations::ACP_SHARED];
return [
Declarations::ACP_TYPE,
];
}
public function getGroup(): string

View File

@ -5,7 +5,7 @@ namespace Chill\PersonBundle\Export\Export;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
@ -17,12 +17,12 @@ use Symfony\Component\Security\Core\Role\Role;
class CountEvaluation implements ExportInterface, GroupedExportInterface
{
private EntityRepository $evaluationRepository;
private EntityRepository $repository;
public function __construct(
EntityManagerInterface $em
) {
$this->evaluationRepository = $em->getRepository(AccompanyingPeriodWorkEvaluation::class);
$this->repository = $em->getRepository(AccompanyingPeriod::class);
}
/**
@ -103,7 +103,10 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface
*/
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->evaluationRepository->createQueryBuilder('eval');
$qb = $this->repository->createQueryBuilder('acp')
->join('acp.works', 'acpw')
->join('acpw.accompanyingPeriodWorkEvaluations', 'eval')
;
$qb->select('COUNT(eval.id) AS export_result');

View File

@ -16,12 +16,12 @@ use Symfony\Component\Security\Core\Role\Role;
class CountHousehold implements ExportInterface, GroupedExportInterface
{
private EntityRepository $acpRepository;
private EntityRepository $repository;
public function __construct(
EntityManagerInterface $em
) {
$this->acpRepository = $em->getRepository(AccompanyingPeriod::class);
$this->repository = $em->getRepository(AccompanyingPeriod::class);
}
/**
@ -102,12 +102,11 @@ class CountHousehold implements ExportInterface, GroupedExportInterface
*/
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->acpRepository->createQueryBuilder('acp')
$qb = $this->repository->createQueryBuilder('acp')
->join('acp.participations', 'acppart')
->join('acppart.person', 'person')
->join('person.householdParticipations', 'householdmember')
->join('householdmember.household', 'household')
->join('household.compositions', 'composition')
;
$qb->select('COUNT(DISTINCT householdmember.household) AS export_result');

View File

@ -114,7 +114,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface
return [
Declarations::PERSON_TYPE,
Declarations::PERSON_IMPLIED_IN,
Declarations::ACP_SHARED
//Declarations::ACP_TYPE
];
}

View File

@ -14,9 +14,11 @@ namespace Chill\PersonBundle\Export\Export;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@ -25,11 +27,12 @@ use Symfony\Component\Security\Core\Role\Role;
class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
{
protected AccompanyingPeriodWorkRepository $socialActionRepository;
protected EntityRepository $repository;
public function __construct(AccompanyingPeriodWorkRepository $socialActionRepository)
{
$this->socialActionRepository = $socialActionRepository;
public function __construct(
EntityManagerInterface $em
) {
$this->repository = $em->getRepository(AccompanyingPeriod::class);
}
public function buildForm(FormBuilderInterface $builder): void
@ -54,7 +57,7 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function getLabels($key, array $values, $data)
{
if ('export_count_social_work_actions' !== $key) {
if ('export_result' !== $key) {
throw new LogicException("the key {$key} is not used by this export");
}
@ -68,7 +71,7 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function getQueryKeys($data): array
{
return ['export_count_social_work_actions'];
return ['export_result'];
}
public function getResult($qb, $data)
@ -83,10 +86,11 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$qb = $this
->socialActionRepository
->createQueryBuilder('acpw')
->select('COUNT(acpw.id) as export_count_social_work_actions');
$qb = $this->repository->createQueryBuilder('acp')
->join('acp.works', 'acpw')
;
$qb->select('COUNT(acpw.id) as export_result');
return $qb;
}
@ -99,7 +103,9 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function supportsModifiers(): array
{
return [Declarations::SOCIAL_WORK_ACTION_TYPE, Declarations::ACP_SHARED];
return [
Declarations::SOCIAL_WORK_ACTION_TYPE,
];
}
public function getGroup(): string

View File

@ -15,9 +15,11 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@ -26,15 +28,12 @@ use Symfony\Component\Security\Core\Role\Role;
class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportInterface
{
private AccompanyingPeriodRepository $periodRepository;
private EntityRepository $repository;
/**
* @param AccompanyingPeriodRepository $periodRepository
*/
public function __construct(
AccompanyingPeriodRepository $periodRepository
EntityManagerInterface $em
) {
$this->periodRepository = $periodRepository;
$this->repository = $em->getRepository(AccompanyingPeriod::class);
}
/**
@ -118,10 +117,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
*/
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$qb = $this->periodRepository->createQueryBuilder('acp');
$expr = $qb->expr();
$force_closingdate = $data['closingdate']; // parameter from buildForm
$qb = $this->repository->createQueryBuilder('acp');
$qb
->select('AVG(
@ -131,7 +127,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
ELSE :force_closingDate
END ) - acp.openingDate
) AS export_result')
->setParameter('force_closingDate', $force_closingdate)
->setParameter('force_closingDate', $data['closingdate'])
;
return $qb;
@ -150,7 +146,9 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
*/
public function supportsModifiers(): array
{
return [Declarations::ACP_TYPE];
return [
Declarations::ACP_TYPE
];
}
public function getGroup(): string

View File

@ -31,7 +31,7 @@ class ActiveOnDateFilter implements FilterInterface
*/
public function getTitle(): string
{
return 'Filtered by active on date';
return 'Filter by active on date';
}
/**

View File

@ -34,7 +34,7 @@ class ActiveOneDayBetweenDatesFilter implements FilterInterface
*/
public function getTitle(): string
{
return 'Filtered by active at least one day between dates';
return 'Filter by active at least one day between dates';
}
/**

View File

@ -34,7 +34,7 @@ class OpenBetweenDatesFilter implements FilterInterface
*/
public function getTitle(): string
{
return 'Filtered by opened between dates';
return 'Filter by opened between dates';
}
/**

View File

@ -1,6 +1,6 @@
<?php
namespace Chill\PersonBundle\Export\Filter;
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface;
@ -42,7 +42,7 @@ class ReferrerFilter implements FilterInterface
*/
public function getTitle(): string
{
return 'Filtered by referrers';
return 'Filter by referrers';
}
/**
@ -75,23 +75,8 @@ 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)) {
case 'acp':
$clause = $qb->expr()->in('acp.user', ':referrers');
break;
case 'acpw':
$qb->join('acpw.referrers', 'r');
$clause = $qb->expr()->in('r', ':referrers');
break;
default:
throw new \Exception("Does not apply on that base entity");
}
$clause = $qb->expr()->in('acp.user', ':referrers');
if ($where instanceof Andx) {
$where->add($clause);
@ -103,19 +88,11 @@ 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
*/
public function applyOn(): string
{
return Declarations::ACP_SHARED;
return Declarations::ACP_TYPE;
}
}

View File

@ -69,9 +69,10 @@ class SocialActionFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acp.works', 'acpw')
->join('acpw.socialAction', 'sa')
;
if (!in_array('acpw', $qb->getAllAliases())) {
$qb->join('acp.works', 'acpw');
}
$qb->join('acpw.socialAction', 'sa');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('sa.id', ':socialactions');

View File

@ -12,7 +12,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class MaxDateFilter implements FilterInterface
{
private const MAXDATE_CHOICES = [
'is specified' => true,
'is not specified' => false,
@ -89,8 +88,6 @@ class MaxDateFilter implements FilterInterface
}
$qb->add('where', $where);
dump($data['maxdate']);
}
/**

View File

@ -85,6 +85,10 @@ class CompositionFilter implements FilterInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('composition', $qb->getAllAliases())) {
$qb->join('household.compositions', 'composition');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(

View File

@ -39,7 +39,7 @@ class JobFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('userjob', EntityType::class, [
$builder->add('job', EntityType::class, [
'class' => UserJob::class,
'choice_label' => function (UserJob $j) {
return $this->translatableStringHelper->localize(
@ -55,13 +55,13 @@ class JobFilter implements FilterInterface
{
$userjobs = [];
foreach ($data['userjob'] as $j) {
foreach ($data['job'] as $j) {
$userjobs[] = $this->translatableStringHelper->localize(
$j->getLabel());
}
return ['Filtered by the following jobs: only %userjobs%', [
'%userjobs%' => implode(', ou ', $userjobs)
return ['Filtered by treating agent job: only %jobs%', [
'%jobs%' => implode(', ou ', $userjobs)
]];
}
@ -72,10 +72,10 @@ class JobFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'r');
$qb->join('acpw.referrers', 'u');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('r.userJob', ':userjob');
$clause = $qb->expr()->in('u.userJob', ':job');
if ($where instanceof Andx) {
$where->add($clause);
@ -84,7 +84,7 @@ class JobFilter implements FilterInterface
}
$qb->add('where', $where);
$qb->setParameter('userjob', $data['userjob']);
$qb->setParameter('job', $data['job']);
}
public function applyOn()
@ -93,8 +93,8 @@ class JobFilter implements FilterInterface
}
public function getTitle()
public function getTitle(): string
{
return 'Filter by user job';
return 'Filter by treating agent job';
}
}

View File

@ -0,0 +1,100 @@
<?php
namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\Query\Expr\From;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
class ReferrerFilter implements FilterInterface
{
private UserRender $userRender;
public function __construct(UserRender $userRender)
{
$this->userRender = $userRender;
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('accepted_agents', EntityType::class, [
'class' => User::class,
'choice_label' => function (User $u) {
return $this->userRender->renderString($u, []);
},
'multiple' => true,
'expanded' => true
]);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Filter by treating agent';
}
/**
* @inheritDoc
*/
public function describeAction($data, $format = 'string'): array
{
$users = [];
foreach ($data['accepted_agents'] as $r) {
$users[] = $r;
}
return [
'Filtered by treating agent: only %agents%', [
'%agents' => implode(", ou ", $users)
]];
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('u', ':agents');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('agents', $data['accepted_agents']);
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@ -59,8 +59,8 @@ class ScopeFilter implements FilterInterface
$s->getName());
}
return ['Filtered by the following scopes: only %scope%', [
'%scope%' => implode(', ou ', $scopes)
return ['Filtered by treating agent scope: only %scopes%', [
'%scopes%' => implode(', ou ', $scopes)
]];
}
@ -71,10 +71,10 @@ class ScopeFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'r');
$qb->join('acpw.referrers', 'u');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('r.mainScope', ':scope');
$clause = $qb->expr()->in('u.mainScope', ':scope');
if ($where instanceof Andx) {
$where->add($clause);
@ -94,6 +94,6 @@ class ScopeFilter implements FilterInterface
public function getTitle()
{
return 'Filter by scope';
return 'Filter by treating agent scope';
}
}

View File

@ -136,7 +136,7 @@ services:
- { name: chill.export_filter, alias: accompanyingcourse_activeonedaybetweendates_filter }
chill.person.export.filter_referrer:
class: Chill\PersonBundle\Export\Filter\ReferrerFilter
class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ReferrerFilter
autowire: true
autoconfigure: true
tags:
@ -150,19 +150,19 @@ services:
- { name: chill.export_filter, alias: accompanyingcourse_openbetweendates_filter }
## Aggregators
chill.person.export.aggregator_scope:
class: Chill\PersonBundle\Export\Aggregator\ScopeAggregator
chill.person.export.aggregator_referrer_scope:
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ScopeAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_scope_aggregator }
- { name: chill.export_aggregator, alias: accompanyingcourse_referrer_scope_aggregator }
chill.person.export.aggregator_job:
class: Chill\PersonBundle\Export\Aggregator\JobAggregator
chill.person.export.aggregator_referrer_job:
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\JobAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_job_aggregator }
- { name: chill.export_aggregator, alias: accompanyingcourse_referrer_job_aggregator }
chill.person.export.aggregator_socialissue:
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\SocialIssueAggregator
@ -235,7 +235,7 @@ services:
- { name: chill.export_aggregator, alias: accompanyingcourse_intensity_aggregator }
chill.person.export.aggregator_referrer:
class: Chill\PersonBundle\Export\Aggregator\ReferrerAggregator
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ReferrerAggregator
autowire: true
autoconfigure: true
tags:

View File

@ -29,6 +29,13 @@ services:
autoconfigure: true
tags:
- { name: chill.export_filter, alias: social_work_actions_job_filter }
chill.person.export.filter_treatingagent:
class: Chill\PersonBundle\Export\Filter\SocialWorkFilters\ReferrerFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: social_work_actions_treatingagent_filter }
## AGGREGATORS
chill.person.export.aggregator_action_type:
@ -37,6 +44,27 @@ services:
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_action_type_aggregator }
chill.person.export.aggregator_treatingagent_scope:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ScopeAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_treatingagent_scope_aggregator }
chill.person.export.aggregator_treatingagent_job:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\JobAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_treatingagent_job_aggregator }
chill.person.export.aggregator_treatingagent:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ReferrerAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_treatingagent_aggregator }
chill.person.export.aggregator_goal:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalAggregator

View File

@ -511,23 +511,41 @@ is regular: le parcours est régulier
Intensity: Intensité
Group by intensity: Grouper par intensité
Filtered by active on date: Filtrer les parcours actifs à une date
Filter by active on date: Filtrer les parcours actifs à une date
On date: Actifs à cette date
"Filtered by actives courses: active on %ondate%": "Filtrer les parcours actifs: actifs le %ondate%"
Filtered by active at least one day between dates: Filtrer les parcours actifs au moins un jour dans la période
Filter by active at least one day between dates: Filtrer les parcours actifs au moins un jour dans la période
"Filtered by actives courses: at least one day between %datefrom% and %dateto%": "Filtrer les parcours actifs: au moins un jour entre le %datefrom% et le %dateto%"
Filtered by referrers: Filtrer par référent
Filter by referrers: Filtrer par référent
Accepted referrers: Référents
"Filtered by referrer: only %referrers%": "Filtré par référent: uniquement %referrers%"
Group by referrers: Grouper par référent
Filtered by opened between dates: Filtrer les parcours ouverts entre deux dates
Filter by opened between dates: Filtrer les parcours ouverts entre deux dates
Date from: Date de début
Date to: Date de fin
"Filtered by opening dates: between %datefrom% and %dateto%": "Filtrer les parcours ouverts entre deux dates: entre le %datefrom% et le %dateto%"
Group social work actions by action type: Grouper les actions par type d'action
Filter by treating agent scope: Filtrer les actions par service de l'agent traitant
"Filtered by treating agent scope: only %scopes%": "Filtré par service de l'agent traitant: uniquement %scopes%"
Group by treating agent scope: Grouper les actions par service de l'agent traitant
Filter by treating agent job: Filtrer les actions par métier de l'agent traitant
"Filtered by treating agent job: only %jobs%": "Filtré par métier de l'agent traitant: uniquement %jobs%"
Group by treating agent job: Grouper les actions par métier de l'agent traitant
Filter by treating agent: Filtrer les actions par agent traitant
Accepted agents: Agent traitant
"Filtered by treating agent: only %agents%": "Filtré par agent traitant: uniquement %agents%"
Group by treating agent: Grouper les actions par agent traitant
Group social work actions by goal: Grouper les actions par objectif
Group social work actions by result: Grouper les actions par résultat
Filter by evaluation type: Filtrer par type d'évaluation
Accepted evaluationtype: Évaluations
"Filtered by evaluation type: only %evals%": "Filtré par type d'évaluation: uniquement %evals%"