merge 111_exports_suite into testing branch

This commit is contained in:
2022-09-08 10:03:21 +02:00
182 changed files with 4668 additions and 4386 deletions

View File

@@ -1,20 +1,30 @@
<?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\CalendarBundle\Export\Aggregator;
use Chill\CalendarBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\Entity\UserRender;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class AgentAggregator implements AggregatorInterface
{
private UserRepository $userRepository;
private UserRender $userRender;
private UserRepository $userRepository;
public function __construct(
UserRepository $userRepository,
UserRender $userRender
@@ -23,16 +33,18 @@ final class AgentAggregator implements AggregatorInterface
$this->userRender = $userRender;
}
public function addRole()
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('cal.user', 'u');
if (!in_array('caluser', $qb->getAllAliases(), true)) {
$qb->join('cal.user', 'caluser');
}
$qb->addSelect('u.id AS agent_aggregator');
$qb->addSelect('caluser.id AS agent_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@@ -41,7 +53,6 @@ final class AgentAggregator implements AggregatorInterface
} else {
$qb->groupBy('agent_aggregator');
}
}
public function applyOn(): string
@@ -54,7 +65,7 @@ final class AgentAggregator implements AggregatorInterface
// no form
}
public function getLabels($key, array $values, $data): \Closure
public function getLabels($key, array $values, $data): Closure
{
return function ($value): string {
if ('_header' === $value) {
@@ -74,6 +85,6 @@ final class AgentAggregator implements AggregatorInterface
public function getTitle(): string
{
return 'Group by agent';
return 'Group appointments by agent';
}
}
}

View File

@@ -1,11 +1,21 @@
<?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\CalendarBundle\Export\Aggregator;
use Chill\CalendarBundle\Export\Declarations;
use Chill\CalendarBundle\Repository\CancelReasonRepository;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@@ -23,37 +33,7 @@ class CancelReasonAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
public function getLabels($key, array $values, $data): \Closure
{
return function($value): string {
if ($value === '_header') {
return 'Cancel reason';
}
$j = $this->cancelReasonRepository->find($value);
return $this->translatableStringHelper->localize(
$j->getName()
);
};
}
public function getQueryKeys($data): array
{
return ['cancel_reason_aggregator'];
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getTitle(): string
{
return 'Group by cancel reason';
}
public function addRole()
public function addRole(): ?string
{
return null;
}
@@ -61,7 +41,9 @@ class CancelReasonAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
// TODO: still needs to take into account appointments without a cancel reason somehow
$qb->join('cal.cancelReason', 'cr');
if (!in_array('calcancel', $qb->getAllAliases(), true)) {
$qb->join('cal.cancelReason', 'calcancel');
}
$qb->addSelect('IDENTITY(cal.cancelReason) as cancel_reason_aggregator');
@@ -78,4 +60,34 @@ class CancelReasonAggregator implements AggregatorInterface
{
return Declarations::CALENDAR_TYPE;
}
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data): Closure
{
return function ($value): string {
if ('_header' === $value) {
return 'Cancel reason';
}
$j = $this->cancelReasonRepository->find($value);
return $this->translatableStringHelper->localize(
$j->getName()
);
};
}
public function getQueryKeys($data): array
{
return ['cancel_reason_aggregator'];
}
public function getTitle(): string
{
return 'Group appointments by cancel reason';
}
}

View File

@@ -1,11 +1,21 @@
<?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\CalendarBundle\Export\Aggregator;
use Chill\CalendarBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserJobRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@@ -23,10 +33,42 @@ final class JobAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
public function getLabels($key, array $values, $data): \Closure
public function addRole(): ?string
{
return function($value): string {
if ($value === '_header') {
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('caluser', $qb->getAllAliases(), true)) {
$qb->join('cal.user', 'caluser');
}
$qb->addSelect('IDENTITY(caluser.userJob) as job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('job_aggregator');
} else {
$qb->groupBy('job_aggregator');
}
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data): Closure
{
return function ($value): string {
if ('_header' === $value) {
return 'Job';
}
@@ -43,38 +85,8 @@ final class JobAggregator implements AggregatorInterface
return ['job_aggregator'];
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getTitle(): string
{
return 'Group by agent job';
return 'Group appointments by agent job';
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('cal.user', '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');
}
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
}
}

View File

@@ -1,10 +1,20 @@
<?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\CalendarBundle\Export\Aggregator;
use Chill\CalendarBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\LocationRepository;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Role\Role;
@@ -19,43 +29,16 @@ final class LocationAggregator implements AggregatorInterface
$this->locationRepository = $locationRepository;
}
public function getLabels($key, array $values, $data): \Closure
{
return function($value): string {
if ($value === '_header') {
return 'Location';
}
$l = $this->locationRepository->find($value);
return $l->getName();
};
}
public function getQueryKeys($data): array
{
return ['location_aggregator'];
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getTitle(): string
{
return 'Group by location';
}
public function addRole(): ?Role
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('cal.location', 'l');
if (!in_array('calloc', $qb->getAllAliases(), true)) {
$qb->join('cal.location', 'calloc');
}
$qb->addSelect('IDENTITY(cal.location) as location_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@@ -72,4 +55,31 @@ final class LocationAggregator implements AggregatorInterface
return Declarations::CALENDAR_TYPE;
}
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data): Closure
{
return function ($value): string {
if ('_header' === $value) {
return 'Location';
}
$l = $this->locationRepository->find($value);
return $l->getName();
};
}
public function getQueryKeys($data): array
{
return ['location_aggregator'];
}
public function getTitle(): string
{
return 'Group appointments by location';
}
}

View File

@@ -1,11 +1,21 @@
<?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\CalendarBundle\Export\Aggregator;
use Chill\CalendarBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\LocationTypeRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@@ -23,10 +33,42 @@ final class LocationTypeAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
public function getLabels($key, array $values, $data): \Closure
public function addRole(): ?string
{
return function($value): string {
if ($value === '_header') {
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('calloc', $qb->getAllAliases(), true)) {
$qb->join('cal.location', 'calloc');
}
$qb->addSelect('IDENTITY(calloc.locationType) as location_type_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('location_type_aggregator');
} else {
$qb->groupBy('location_type_aggregator');
}
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data): Closure
{
return function ($value): string {
if ('_header' === $value) {
return 'Location type';
}
@@ -43,39 +85,8 @@ final class LocationTypeAggregator implements AggregatorInterface
return ['location_type_aggregator'];
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getTitle(): string
{
return 'Group by location type';
return 'Group appointments by location type';
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('cal.location', 'l');
$qb->addSelect('IDENTITY(l.locationType) as location_type_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('location_type_aggregator');
} else {
$qb->groupBy('location_type_aggregator');
}
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
}
}

View File

@@ -1,5 +1,14 @@
<?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\CalendarBundle\Export\Aggregator;
use Chill\CalendarBundle\Export\Declarations;
@@ -11,37 +20,7 @@ use Symfony\Component\Security\Core\Role\Role;
class MonthYearAggregator implements AggregatorInterface
{
public function getQueryKeys($data): array
{
return ['month_year_aggregator'];
}
public function getLabels($key, array $values, $data): Closure
{
return function($value): string {
if ($value === '_header') {
return 'by month and year';
}
$month = substr($value,0, 2);
$year = substr($value, 3, 4);
return strftime('%B %G', mktime(0, 0, 0, $month, '1', $year));
};
}
public function buildForm(FormBuilderInterface $builder)
{
// No form needed
}
public function getTitle(): string
{
return 'Group by month and year';
}
public function addRole(): ?Role
public function addRole(): ?string
{
return null;
}
@@ -63,4 +42,33 @@ class MonthYearAggregator implements AggregatorInterface
{
return Declarations::CALENDAR_TYPE;
}
}
public function buildForm(FormBuilderInterface $builder)
{
// No form needed
}
public function getLabels($key, array $values, $data): Closure
{
return static function ($value): string {
if ('_header' === $value) {
return 'by month and year';
}
$month = substr($value, 0, 2);
$year = substr($value, 3, 4);
return strftime('%B %G', mktime(0, 0, 0, $month, '1', $year));
};
}
public function getQueryKeys($data): array
{
return ['month_year_aggregator'];
}
public function getTitle(): string
{
return 'Group appointments by month and year';
}
}

View File

@@ -1,11 +1,21 @@
<?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\CalendarBundle\Export\Aggregator;
use Chill\CalendarBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\ScopeRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@@ -23,10 +33,42 @@ final class ScopeAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
public function getLabels($key, array $values, $data): \Closure
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('caluser', $qb->getAllAliases(), true)) {
$qb->join('cal.user', 'caluser');
}
$qb->addSelect('IDENTITY(caluser.mainScope) as scope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('scope_aggregator');
} else {
$qb->groupBy('scope_aggregator');
}
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data): Closure
{
return function ($value): string {
if ($value === '_header') {
if ('_header' === $value) {
return 'Scope';
}
@@ -43,38 +85,8 @@ final class ScopeAggregator implements AggregatorInterface
return ['scope_aggregator'];
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getTitle(): string
{
return 'Group by agent scope';
return 'Group appointments by agent scope';
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('cal.user', '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');
}
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
}
}

View File

@@ -1,13 +1,23 @@
<?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\CalendarBundle\Export\Export;
use Chill\CalendarBundle\Export\Declarations;
use Chill\CalendarBundle\Repository\CalendarRepository;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\CalendarBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Closure;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@@ -16,7 +26,6 @@ use Symfony\Component\Security\Core\Role\Role;
class CountAppointments implements ExportInterface, GroupedExportInterface
{
private CalendarRepository $calendarRepository;
public function __construct(CalendarRepository $calendarRepository)
@@ -39,7 +48,12 @@ class CountAppointments implements ExportInterface, GroupedExportInterface
return 'Count appointments by various parameters.';
}
public function getLabels($key, array $values, $data): \Closure
public function getGroup(): string
{
return 'Exports of calendar';
}
public function getLabels($key, array $values, $data): Closure
{
if ('export_result' !== $key) {
throw new LogicException("the key {$key} is not used by this export");
@@ -89,11 +103,10 @@ class CountAppointments implements ExportInterface, GroupedExportInterface
return $qb;
}
public function requiredRole(): Role
public function requiredRole(): string
{
// which role should we give here?
return new Role(PersonVoter::STATS);
return PersonVoter::STATS;
}
public function supportsModifiers(): array
@@ -102,10 +115,4 @@ class CountAppointments implements ExportInterface, GroupedExportInterface
Declarations::CALENDAR_TYPE,
];
}
public function getGroup(): string
{
return 'Exports of calendar';
}
}
}

View File

@@ -1,5 +1,14 @@
<?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\CalendarBundle\Export\Export;
use Chill\CalendarBundle\Export\Declarations;
@@ -10,12 +19,11 @@ use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Role\Role;
class StatAppointmentAvgDuration implements ExportInterface, GroupedExportInterface
{
private CalendarRepository $calendarRepository;
public function __construct(
@@ -29,11 +37,6 @@ class StatAppointmentAvgDuration implements ExportInterface, GroupedExportInterf
// no form needed
}
public function getTitle(): string
{
return 'Average appointment duration';
}
public function getAllowedFormattersTypes(): array
{
return [FormatterInterface::TYPE_TABULAR];
@@ -44,10 +47,15 @@ class StatAppointmentAvgDuration implements ExportInterface, GroupedExportInterf
return 'Get the average of appointment duration according to various filters';
}
public function getGroup(): string
{
return 'Exports of calendar';
}
public function getLabels($key, array $values, $data)
{
if ('export_result' !== $key) {
throw new \LogicException("the key {$key} is not used by this export");
throw new LogicException("the key {$key} is not used by this export");
}
$labels = array_combine($values, $values);
@@ -68,6 +76,11 @@ class StatAppointmentAvgDuration implements ExportInterface, GroupedExportInterf
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
}
public function getTitle(): string
{
return 'Average appointment duration';
}
public function getType(): string
{
return Declarations::CALENDAR_TYPE;
@@ -83,21 +96,15 @@ class StatAppointmentAvgDuration implements ExportInterface, GroupedExportInterf
return $qb;
}
public function requiredRole(): Role
public function requiredRole(): string
{
return new Role(AccompanyingPeriodVoter::STATS);
return AccompanyingPeriodVoter::STATS;
}
public function supportsModifiers(): array
{
return [
Declarations::CALENDAR_TYPE
Declarations::CALENDAR_TYPE,
];
}
public function getGroup(): string
{
return 'Exports of calendar';
}
}
}

View File

@@ -1,5 +1,14 @@
<?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\CalendarBundle\Export\Export;
use Chill\CalendarBundle\Export\Declarations;
@@ -10,8 +19,8 @@ use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Role\Role;
class StatAppointmentSumDuration implements ExportInterface, GroupedExportInterface
{
@@ -28,11 +37,6 @@ class StatAppointmentSumDuration implements ExportInterface, GroupedExportInterf
// no form needed
}
public function getTitle(): string
{
return 'Sum of appointment durations';
}
public function getAllowedFormattersTypes(): array
{
return [FormatterInterface::TYPE_TABULAR];
@@ -43,10 +47,15 @@ class StatAppointmentSumDuration implements ExportInterface, GroupedExportInterf
return 'Get the sum of appointment durations according to various filters';
}
public function getGroup(): string
{
return 'Exports of calendar';
}
public function getLabels($key, array $values, $data)
{
if ('export_result' !== $key) {
throw new \LogicException("the key {$key} is not used by this export");
throw new LogicException("the key {$key} is not used by this export");
}
$labels = array_combine($values, $values);
@@ -67,6 +76,11 @@ class StatAppointmentSumDuration implements ExportInterface, GroupedExportInterf
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
}
public function getTitle(): string
{
return 'Sum of appointment durations';
}
public function getType(): string
{
return Declarations::CALENDAR_TYPE;
@@ -82,21 +96,15 @@ class StatAppointmentSumDuration implements ExportInterface, GroupedExportInterf
return $qb;
}
public function requiredRole(): Role
public function requiredRole(): string
{
return new Role(AccompanyingPeriodVoter::STATS);
return AccompanyingPeriodVoter::STATS;
}
public function supportsModifiers(): array
{
return [
Declarations::CALENDAR_TYPE
Declarations::CALENDAR_TYPE,
];
}
public function getGroup(): string
{
return 'Exports of calendar';
}
}
}

View File

@@ -1,5 +1,14 @@
<?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\CalendarBundle\Export\Filter;
use Chill\CalendarBundle\Export\Declarations;
@@ -20,39 +29,7 @@ class AgentFilter implements FilterInterface
$this->userRender = $userRender;
}
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
]);
}
public function getTitle(): string
{
return 'Filter by agent';
}
public function describeAction($data, $format = 'string'): array
{
$users = [];
foreach ($data['accepted_agents'] as $r) {
$users[] = $r;
}
return [
'Filtered by agent: only %agents%', [
'%agents' => implode(", ou ", $users)
]];
}
public function addRole()
public function addRole(): ?string
{
return null;
}
@@ -76,4 +53,35 @@ class AgentFilter implements FilterInterface
{
return Declarations::CALENDAR_TYPE;
}
}
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,
]);
}
public function describeAction($data, $format = 'string'): array
{
$users = [];
foreach ($data['accepted_agents'] as $r) {
$users[] = $r;
}
return [
'Filtered by agent: only %agents%', [
'%agents' => implode(', ou ', $users),
], ];
}
public function getTitle(): string
{
return 'Filter appointments by agent';
}
}

View File

@@ -1,32 +1,67 @@
<?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\CalendarBundle\Export\Filter;
use Chill\CalendarBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class BetweenDatesFilter implements FilterInterface
{
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->gte('cal.startDate', ':dateFrom'),
$qb->expr()->lte('cal.endDate', ':dateTo')
);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('dateFrom', $data['date_from'], Types::DATE_MUTABLE);
// modify dateTo so that entire day is also taken into account up until the beginning of the next day.
$qb->setParameter('dateTo', $data['date_to']->modify('+1 day'), Types::DATE_MUTABLE);
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('date_from', ChillDateType::class, [
'data' => new \DateTime(),
'data' => new DateTime(),
])
->add('date_to', ChillDateType::class, [
'data' => new \DateTime(),
])
;
}
public function getTitle(): string
{
return 'Filter by appointments between certain dates';
'data' => new DateTime(),
]);
}
public function describeAction($data, $format = 'string'): array
@@ -37,34 +72,8 @@ class BetweenDatesFilter implements FilterInterface
]];
}
public function addRole()
public function getTitle(): string
{
return null;
return 'Filter appointments between certain dates';
}
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->gte('cal.startDate', ':dateFrom'),
$qb->expr()->lte('cal.endDate', ':dateTo')
);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('dateFrom', $data['date_from']);
// modify dateTo so that entire day is also taken into account up until the beginning of the next day.
$qb->setParameter('dateTo', $data['date_to']->modify('+1 day'));
}
public function applyOn(): string
{
return Declarations::CALENDAR_TYPE;
}
}
}

View File

@@ -23,7 +23,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class JobFilter implements FilterInterface
{
protected TranslatorInterface $translator;
private TranslatableStringHelper $translatableStringHelper;
@@ -36,45 +35,19 @@ class JobFilter implements FilterInterface
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('job', EntityType::class, [
'class' => UserJob::class,
'choice_label' => function (UserJob $j) {
return $this->translatableStringHelper->localize(
$j->getLabel()
);
},
'multiple' => true,
'expanded' => true
]);
}
public function describeAction($data, $format = 'string'): array
{
$userJobs = [];
foreach ($data['job'] as $j) {
$userJobs[] = $this->translatableStringHelper->localize(
$j->getLabel());
}
return ['Filtered by agent job: only %jobs%', [
'%jobs%' => implode(', ou ', $userJobs)
]];
}
public function addRole()
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('cal.user', 'u');
if (!in_array('caluser', $qb->getAllAliases(), true)) {
$qb->join('cal.user', 'caluser');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('u.userJob', ':job');
$clause = $qb->expr()->in('caluser.userJob', ':job');
if ($where instanceof Andx) {
$where->add($clause);
@@ -91,9 +64,37 @@ class JobFilter implements FilterInterface
return Declarations::CALENDAR_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('job', EntityType::class, [
'class' => UserJob::class,
'choice_label' => function (UserJob $j) {
return $this->translatableStringHelper->localize(
$j->getLabel()
);
},
'multiple' => true,
'expanded' => true,
]);
}
public function describeAction($data, $format = 'string'): array
{
$userJobs = [];
foreach ($data['job'] as $j) {
$userJobs[] = $this->translatableStringHelper->localize(
$j->getLabel()
);
}
return ['Filtered by agent job: only %jobs%', [
'%jobs%' => implode(', ou ', $userJobs),
]];
}
public function getTitle(): string
{
return 'Filter by agent job';
return 'Filter appointments by agent job';
}
}

View File

@@ -23,7 +23,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class ScopeFilter implements FilterInterface
{
protected TranslatorInterface $translator;
private TranslatableStringHelper $translatableStringHelper;
@@ -36,45 +35,19 @@ class ScopeFilter implements FilterInterface
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('scope', EntityType::class, [
'class' => Scope::class,
'choice_label' => function (Scope $s) {
return $this->translatableStringHelper->localize(
$s->getName()
);
},
'multiple' => true,
'expanded' => true
]);
}
public function describeAction($data, $format = 'string')
{
$scopes = [];
foreach ($data['scope'] as $s) {
$scopes[] = $this->translatableStringHelper->localize(
$s->getName());
}
return ['Filtered by agent scope: only %scopes%', [
'%scopes%' => implode(', ou ', $scopes)
]];
}
public function addRole()
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('cal.user', 'u');
if (!in_array('caluser', $qb->getAllAliases(), true)) {
$qb->join('cal.user', 'caluser');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('u.mainScope', ':scope');
$clause = $qb->expr()->in('caluser.mainScope', ':scope');
if ($where instanceof Andx) {
$where->add($clause);
@@ -91,9 +64,37 @@ class ScopeFilter implements FilterInterface
return Declarations::CALENDAR_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('scope', EntityType::class, [
'class' => Scope::class,
'choice_label' => function (Scope $s) {
return $this->translatableStringHelper->localize(
$s->getName()
);
},
'multiple' => true,
'expanded' => true,
]);
}
public function describeAction($data, $format = 'string')
{
$scopes = [];
foreach ($data['scope'] as $s) {
$scopes[] = $this->translatableStringHelper->localize(
$s->getName()
);
}
return ['Filtered by agent scope: only %scopes%', [
'%scopes%' => implode(', ou ', $scopes),
]];
}
public function getTitle()
{
return 'Filter by agent scope';
return 'Filter appointments by agent scope';
}
}
}

View File

@@ -82,21 +82,21 @@ Sum of appointment durations: Somme de la durée des rendez-vous
Get the sum of appointment durations according to various filters: Calcule la somme des durées des rendez-vous en fonction de différents paramètres.
'Filtered by agent: only %agents%': "Filtré par agents: uniquement %agents%"
Filter by agent: Filtrer par agents
Filter by agent job: Filtrer par métiers des agents
Filter appointments by agent: Filtrer les rendez-vous par agents
Filter appointments by agent job: Filtrer les rendez-vous par métiers des agents
'Filtered by agent job: only %jobs%': 'Filtré par métiers des agents: uniquement les %jobs%'
Filter by agent scope: Filtrer par services des agents
Filter appointments by agent scope: Filtrer les rendez-vous par services des agents
'Filtered by agent scope: only %scopes%': 'Filtré par services des agents: uniquement les services %scopes%'
Filter by appointments between certain dates: Filtrer par date du rendez-vous
Filter appointments between certain dates: Filtrer les rendez-vous par date du rendez-vous
'Filtered by appointments between %dateFrom% and %dateTo%': 'Filtré par rendez-vous entre %dateFrom% et %dateTo%'
Group by agent: Grouper par agent
Group by agent job: Grouper par métier de l'agent
Group by agent scope: Grouper par service de l'agent
Group by location type: Grouper par type de localisation
Group by location: Grouper par lieu de rendez-vous
Group by cancel reason: Grouper par motif d'annulation
Group by month and year: Grouper par mois et année
Group appointments by agent: Grouper les rendez-vous par agent
Group appointments by agent job: Grouper les rendez-vous par métier de l'agent
Group appointments by agent scope: Grouper les rendez-vous par service de l'agent
Group appointments by location type: Grouper les rendez-vous par type de localisation
Group appointments by location: Grouper les rendez-vous par lieu de rendez-vous
Group appointments by cancel reason: Grouper les rendez-vous par motif d'annulation
Group appointments by month and year: Grouper les rendez-vous par mois et année
Scope: Service
Job: Métier
Location type: Type de localisation