mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
exports: add new countHousehold export
This commit is contained in:
parent
8efbf02f64
commit
3f4d4497af
@ -101,6 +101,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
||||
$loader->load('services/exports_accompanying_course.yaml');
|
||||
$loader->load('services/exports_social_actions.yaml');
|
||||
$loader->load('services/exports_evaluation.yaml');
|
||||
$loader->load('services/exports_household.yaml');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,4 +27,6 @@ abstract class Declarations
|
||||
public const SOCIAL_WORK_ACTION_TYPE = 'social_actions';
|
||||
|
||||
public const EVAL_TYPE = 'evaluation';
|
||||
|
||||
public const HOUSEHOLD_TYPE = 'household';
|
||||
}
|
||||
|
139
src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php
Normal file
139
src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
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\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
class CountHousehold implements ExportInterface, GroupedExportInterface
|
||||
{
|
||||
private EntityRepository $acpRepository;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em
|
||||
) {
|
||||
$this->acpRepository = $em->getRepository(AccompanyingPeriod::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
// TODO: Implement buildForm() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Count households';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
return [FormatterInterface::TYPE_TABULAR];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Count household by various parameters.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
if ('export_result' !== $key) {
|
||||
throw new LogicException("the key {$key} is not used by this export");
|
||||
}
|
||||
|
||||
$labels = array_combine($values, $values);
|
||||
$labels['_header'] = $this->getTitle();
|
||||
|
||||
return static function ($value) use ($labels) {
|
||||
return $labels[$value];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
return ['export_result'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getResult($qb, $data)
|
||||
{
|
||||
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Declarations::HOUSEHOLD_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
||||
{
|
||||
$qb = $this->acpRepository->createQueryBuilder('acp')
|
||||
->join('acp.participations', 'acppart')
|
||||
->join('acppart.person', 'person')
|
||||
->join('person.householdParticipations', 'householdmember')
|
||||
;
|
||||
|
||||
$qb->select('COUNT(DISTINCT householdmember.household) AS export_result');
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function requiredRole()
|
||||
{
|
||||
// TODO HouseholdVoter::STATS !??
|
||||
return new Role(AccompanyingPeriodVoter::STATS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supportsModifiers(): array
|
||||
{
|
||||
return [
|
||||
Declarations::HOUSEHOLD_TYPE,
|
||||
];
|
||||
}
|
||||
|
||||
public function getGroup(): string
|
||||
{
|
||||
return 'Exports of households';
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
services:
|
||||
|
||||
## Indicators
|
||||
chill.person.export.count_household:
|
||||
class: Chill\PersonBundle\Export\Export\CountHousehold
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export, alias: count_household }
|
||||
|
||||
## Filters
|
||||
|
||||
## Aggregators
|
@ -354,6 +354,10 @@ Exports of evaluations: Exports des évaluations
|
||||
Count evaluations: Nombre d'évaluations
|
||||
Count evaluation by various parameters.: Compte le nombre d'évaluations selon différents filtres.
|
||||
|
||||
Exports of households: Exports des ménages
|
||||
Count households: Nombre de ménages
|
||||
Count household by various parameters.: Compte le nombre de ménages selon différents filtres.
|
||||
|
||||
## filters
|
||||
Filter by person gender: Filtrer par genre de la personne
|
||||
Accepted genders: Genres acceptés
|
||||
|
Loading…
x
Reference in New Issue
Block a user