mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
namespace Chill\ActivityBundle\Export\Aggregator;
|
|
|
|
use Chill\ActivityBundle\Export\Declarations;
|
|
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
|
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use function in_array;
|
|
|
|
class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorInterface
|
|
{
|
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
|
|
|
private UserJobRepositoryInterface $userJobRepository;
|
|
|
|
public function __construct(UserJobRepositoryInterface $userJobRepository, TranslatableStringHelperInterface $translatableStringHelper)
|
|
{
|
|
$this->userJobRepository = $userJobRepository;
|
|
$this->translatableStringHelper = $translatableStringHelper;
|
|
}
|
|
|
|
public function addRole(): ?string
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function alterQuery(QueryBuilder $qb, $data)
|
|
{
|
|
if (!in_array('actusers', $qb->getAllAliases(), true)) {
|
|
$qb->leftJoin('activity.users', 'actusers');
|
|
}
|
|
|
|
$qb
|
|
->addSelect('IDENTITY(actusers.userJob) AS activity_users_job_aggregator')
|
|
->addGroupBy('activity_users_job_aggregator');
|
|
}
|
|
|
|
public function applyOn()
|
|
{
|
|
return Declarations::ACTIVITY;
|
|
}
|
|
|
|
public function buildForm(FormBuilderInterface $builder)
|
|
{
|
|
// nothing to add in the form
|
|
}
|
|
|
|
public function getLabels($key, array $values, $data)
|
|
{
|
|
return function ($value): string {
|
|
if ('_header' === $value) {
|
|
return 'Users \'s job';
|
|
}
|
|
|
|
if (null === $value) {
|
|
return '';
|
|
}
|
|
|
|
$j = $this->userJobRepository->find($value);
|
|
|
|
return $this->translatableStringHelper->localize(
|
|
$j->getLabel()
|
|
);
|
|
};
|
|
}
|
|
|
|
public function getQueryKeys($data): array
|
|
{
|
|
return ['activity_users_job_aggregator'];
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return 'Aggregate by users job';
|
|
}
|
|
}
|