mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
add filtering on accompanying period + fix problems in gender filter
This commit is contained in:
47
Export/AbstractAccompanyingPeriodExportElement.php
Normal file
47
Export/AbstractAccompanyingPeriodExportElement.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Export;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class AbstractAccompanyingPeriodExportElement
|
||||
{
|
||||
protected function havingAccompanyingPeriodInJoin(QueryBuilder $query)
|
||||
{
|
||||
$joins = $query->getDQLPart('join');
|
||||
|
||||
foreach ($joins['person'] as $join) {
|
||||
if ($join->getAlias() === 'accompanying_period') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function addJoinAccompanyingPeriod(QueryBuilder $query)
|
||||
{
|
||||
if (FALSE === $this->havingAccompanyingPeriodInJoin($query)) {
|
||||
$query->join('person.accompanyingPeriods', 'accompanying_period');
|
||||
}
|
||||
}
|
||||
}
|
85
Export/Filter/AccompanyingPeriodClosingFilter.php
Normal file
85
Export/Filter/AccompanyingPeriodClosingFilter.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Export\Filter;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Chill\PersonBundle\Export\AbstractAccompanyingPeriodExportElement;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class AccompanyingPeriodClosingFilter extends AbstractAccompanyingPeriodExportElement implements FilterInterface
|
||||
{
|
||||
public function addRole()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$this->addJoinAccompanyingPeriod($qb);
|
||||
|
||||
$clause = $qb->expr()->andX(
|
||||
$qb->expr()->lte('accompanying_period.closingDate', ':date_to'),
|
||||
$qb->expr()->gte('accompanying_period.closingDate', ':date_from'));
|
||||
|
||||
$qb->andWhere($clause);
|
||||
$qb->setParameter('date_from', $data['date_from'], Type::DATE);
|
||||
$qb->setParameter('date_to', $data['date_to'], Type::DATE);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
{
|
||||
return 'person';
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('date_from', ChillDateType::class, array(
|
||||
'label' => "Having an accompanying period closed after this date",
|
||||
'data' => new \DateTime("-1 month"),
|
||||
));
|
||||
|
||||
$builder->add('date_to', ChillDateType::class, array(
|
||||
'label' => "Having an accompanying period closed before this date",
|
||||
'data' => new \DateTime(),
|
||||
));
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
return [
|
||||
"Filtered by accompanying period: persons having an accompanying period"
|
||||
. " closed between the %date_from% and %date_to%",
|
||||
[
|
||||
'%date_from%' => $data['date_from']->format('d-m-Y'),
|
||||
'%date_to%' => $data['date_to']->format('d-m-Y')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Filter by accompanying period: closed between two dates";
|
||||
}
|
||||
}
|
95
Export/Filter/AccompanyingPeriodFilter.php
Normal file
95
Export/Filter/AccompanyingPeriodFilter.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Export\Filter;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Chill\PersonBundle\Export\AbstractAccompanyingPeriodExportElement;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class AccompanyingPeriodFilter extends AbstractAccompanyingPeriodExportElement implements FilterInterface
|
||||
{
|
||||
public function addRole()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$this->addJoinAccompanyingPeriod($qb);
|
||||
|
||||
$clause = $qb->expr()->andX();
|
||||
|
||||
$clause->add(
|
||||
$qb->expr()->lte('accompanying_period.openingDate', ':date_to')
|
||||
);
|
||||
$clause->add(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->gte('accompanying_period.closingDate', ':date_from'),
|
||||
$qb->expr()->isNull('accompanying_period.closingDate')
|
||||
)
|
||||
);
|
||||
|
||||
$qb->andWhere($clause);
|
||||
$qb->setParameter('date_from', $data['date_from'], Type::DATE);
|
||||
$qb->setParameter('date_to', $data['date_to'], Type::DATE);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
{
|
||||
return 'person';
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('date_from', ChillDateType::class, array(
|
||||
'label' => "Having an accompanying period opened after this date",
|
||||
'data' => new \DateTime("-1 month"),
|
||||
));
|
||||
|
||||
$builder->add('date_to', ChillDateType::class, array(
|
||||
'label' => "Having an accompanying period ending before this date, or "
|
||||
. "still opened at this date",
|
||||
'data' => new \DateTime(),
|
||||
));
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
return [
|
||||
"Filtered by accompanying period: persons having an accompanying period"
|
||||
. " opened after the %date_from% and closed before the %date_to% (or still opened "
|
||||
. "at the %date_to%)",
|
||||
[
|
||||
'%date_from%' => $data['date_from']->format('d-m-Y'),
|
||||
'%date_to%' => $data['date_to']->format('d-m-Y')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Filter by accompanying period: active period";
|
||||
}
|
||||
}
|
85
Export/Filter/AccompanyingPeriodOpeningFilter.php
Normal file
85
Export/Filter/AccompanyingPeriodOpeningFilter.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Export\Filter;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Chill\PersonBundle\Export\AbstractAccompanyingPeriodExportElement;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class AccompanyingPeriodOpeningFilter extends AbstractAccompanyingPeriodExportElement implements FilterInterface
|
||||
{
|
||||
public function addRole()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$this->addJoinAccompanyingPeriod($qb);
|
||||
|
||||
$clause = $qb->expr()->andX(
|
||||
$qb->expr()->lte('accompanying_period.openingDate', ':date_to'),
|
||||
$qb->expr()->gte('accompanying_period.openingDate', ':date_from'));
|
||||
|
||||
$qb->andWhere($clause);
|
||||
$qb->setParameter('date_from', $data['date_from'], Type::DATE);
|
||||
$qb->setParameter('date_to', $data['date_to'], Type::DATE);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
{
|
||||
return 'person';
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('date_from', ChillDateType::class, array(
|
||||
'label' => "Having an accompanying period opened after this date",
|
||||
'data' => new \DateTime("-1 month"),
|
||||
));
|
||||
|
||||
$builder->add('date_to', ChillDateType::class, array(
|
||||
'label' => "Having an accompanying period opened before this date",
|
||||
'data' => new \DateTime(),
|
||||
));
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
return [
|
||||
"Filtered by accompanying period: persons having an accompanying period"
|
||||
. " opened between the %date_from% and %date_to%",
|
||||
[
|
||||
'%date_from%' => $data['date_from']->format('d-m-Y'),
|
||||
'%date_to%' => $data['date_to']->format('d-m-Y')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Filter by accompanying period: starting between two dates";
|
||||
}
|
||||
}
|
@@ -28,6 +28,7 @@ use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -37,8 +38,18 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
class GenderFilter implements FilterInterface,
|
||||
ExportElementValidatedInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
public function applyOn()
|
||||
{
|
||||
return 'person';
|
||||
}
|
||||
@@ -111,11 +122,19 @@ class GenderFilter implements FilterInterface,
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
switch($data['accepted_genders']) {
|
||||
case Person::MALE_GENDER:
|
||||
return 'Filtering by gender: male only';
|
||||
case Person::FEMALE_GENDER:
|
||||
return array('Filtering by gender: female only');
|
||||
$genders = [];
|
||||
|
||||
foreach ($data['accepted_genders'] as $g) {
|
||||
if ('null' === $g) {
|
||||
$genders[] = $this->translator->trans('Not given');
|
||||
} else {
|
||||
$genders[] = $this->translator->trans($g);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"Filtering by genders: only %genders%",
|
||||
[ "%genders%" => \implode(", ", $genders)]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user