start of social actions export

This commit is contained in:
2022-07-26 10:41:24 +02:00
parent 70f118011b
commit a06a2c9592
5 changed files with 132 additions and 10 deletions

View File

@@ -21,4 +21,6 @@ abstract class Declarations
public const PERSON_TYPE = 'person';
public const ACP_TYPE = 'accompanying_period';
public const SOCIAL_ACTION_TYPE = 'social_actions';
}

View File

@@ -0,0 +1,107 @@
<?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\Export;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use LogicException;
class CountSocialAction implements ExportInterface, GroupedExportInterface
{
protected SocialActionRepository $socialActionRepository;
public function __construct(SocialActionRepository $socialActionRepository)
{
$this->socialActionRepository = $socialActionRepository;
}
public function buildForm(FormBuilderInterface $builder): void
{
// TODO: Implement buildForm() method.
}
public function getTitle(): string
{
return 'Count social actions';
}
public function getAllowedFormattersTypes(): array
{
return [FormatterInterface::TYPE_TABULAR];
}
public function getDescription(): string
{
return 'Count social actions by various parameters';
}
public function getLabels($key, array $values, $data)
{
if ('export_count_social_actions' !== $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];
};
}
public function getQueryKeys($data): array
{
return ['export_count_social_actions'];
}
public function getResult($qb, $data)
{
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
}
public function getType(): string
{
return Declarations::SOCIAL_ACTION_TYPE;
}
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$qb = $this
->socialActionRepository
->createQueryBuilder('sa')
->select('COUNT(sa.id) as export_count_social_actions');
return $qb;
}
public function requiredRole(): string
{
return AccompanyingPeriodVoter::STATS;
}
public function supportsModifiers(): array
{
return [Declarations::SOCIAL_ACTION_TYPE];
}
public function getGroup(): string
{
return 'Exports of social actions';
}
}