mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-18 20:54:59 +00:00
97 lines
2.3 KiB
PHP
97 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\ActivityBundle\Export\Export;
|
|
|
|
use Chill\ActivityBundle\Repository\ActivityRepository;
|
|
use Chill\MainBundle\Export\ExportInterface;
|
|
use Chill\MainBundle\Export\FormatterInterface;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Symfony\Component\Security\Core\Role\Role;
|
|
use Doctrine\ORM\Query;
|
|
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
|
|
|
class CountActivity implements ExportInterface
|
|
{
|
|
protected ActivityRepository $activityRepository;
|
|
|
|
public function __construct(
|
|
ActivityRepository $activityRepository
|
|
) {
|
|
$this->activityRepository = $activityRepository;
|
|
}
|
|
|
|
public function buildForm(FormBuilderInterface $builder)
|
|
{
|
|
|
|
}
|
|
|
|
public function getDescription()
|
|
{
|
|
return 'Count activities by various parameters.';
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return 'Count activities';
|
|
}
|
|
|
|
public function getType()
|
|
{
|
|
return 'activity';
|
|
}
|
|
|
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data = array())
|
|
{
|
|
$centers = array_map(static fn($el) => $el['center'], $acl);
|
|
|
|
$qb = $this
|
|
->activityRepository
|
|
->createQueryBuilder('activity')
|
|
->select('COUNT(activity.id) as export_count_activity')
|
|
->join('activity.person', 'person');
|
|
|
|
$qb
|
|
->where($qb->expr()->in('person.center', ':centers'))
|
|
->setParameter('centers', $centers);
|
|
|
|
return $qb;
|
|
}
|
|
|
|
public function supportsModifiers()
|
|
{
|
|
return ['person', 'activity'];
|
|
}
|
|
|
|
public function requiredRole()
|
|
{
|
|
return new Role(ActivityStatsVoter::STATS);
|
|
}
|
|
|
|
public function getAllowedFormattersTypes()
|
|
{
|
|
return [FormatterInterface::TYPE_TABULAR];
|
|
}
|
|
|
|
public function getLabels($key, array $values, $data)
|
|
{
|
|
if ($key !== 'export_count_activity') {
|
|
throw new \LogicException("the key $key is not used by this export");
|
|
}
|
|
|
|
return static fn($value) => $value === '_header' ? 'Number of activities' : $value;
|
|
}
|
|
|
|
public function getQueryKeys($data)
|
|
{
|
|
return ['export_count_activity'];
|
|
}
|
|
|
|
public function getResult($qb, $data)
|
|
{
|
|
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
|
|
}
|
|
|
|
}
|