mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix: Let Symfony inject dependencies automatically.
This commit is contained in:
parent
d9b862925f
commit
6ccc8d4cb8
@ -1,25 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
declare(strict_types=1);
|
||||||
* Copyright (C) 2017 Champs-Libres <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\ActivityBundle\Export\Filter;
|
namespace Chill\ActivityBundle\Export\Filter;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
use Symfony\Component\Form\FormEvents;
|
use Symfony\Component\Form\FormEvents;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
@ -28,31 +15,21 @@ use Chill\MainBundle\Form\Type\Export\FilterType;
|
|||||||
use Doctrine\ORM\Query\Expr;
|
use Doctrine\ORM\Query\Expr;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
|
||||||
*/
|
|
||||||
class ActivityDateFilter implements FilterInterface
|
class ActivityDateFilter implements FilterInterface
|
||||||
{
|
{
|
||||||
/**
|
protected TranslatorInterface $translator;
|
||||||
*
|
|
||||||
* @var TranslatorInterface
|
|
||||||
*/
|
|
||||||
protected $translator;
|
|
||||||
|
|
||||||
function __construct(TranslatorInterface $translator)
|
function __construct(TranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addRole()
|
public function addRole()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
$where = $qb->getDQLPart('where');
|
$where = $qb->getDQLPart('where');
|
||||||
$clause = $qb->expr()->between('activity.date', ':date_from',
|
$clause = $qb->expr()->between('activity.date', ':date_from',
|
||||||
@ -74,23 +51,31 @@ class ActivityDateFilter implements FilterInterface
|
|||||||
return 'activity';
|
return 'activity';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$builder->add('date_from', DateType::class, array(
|
$builder->add(
|
||||||
'label' => "Activities after this date",
|
'date_from',
|
||||||
'data' => new \DateTime(),
|
DateType::class,
|
||||||
'attr' => array('class' => 'datepicker'),
|
[
|
||||||
'widget'=> 'single_text',
|
'label' => 'Activities after this date',
|
||||||
'format' => 'dd-MM-yyyy',
|
'data' => new \DateTime(),
|
||||||
));
|
'attr' => ['class' => 'datepicker'],
|
||||||
|
'widget'=> 'single_text',
|
||||||
|
'format' => 'dd-MM-yyyy',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$builder->add('date_to', DateType::class, array(
|
$builder->add(
|
||||||
'label' => "Activities before this date",
|
'date_to',
|
||||||
'data' => new \DateTime(),
|
DateType::class,
|
||||||
'attr' => array('class' => 'datepicker'),
|
[
|
||||||
'widget'=> 'single_text',
|
'label' => 'Activities before this date',
|
||||||
'format' => 'dd-MM-yyyy',
|
'data' => new \DateTime(),
|
||||||
));
|
'attr' => ['class' => 'datepicker'],
|
||||||
|
'widget'=> 'single_text',
|
||||||
|
'format' => 'dd-MM-yyyy',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
|
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
|
||||||
/* @var $filterForm \Symfony\Component\Form\FormInterface */
|
/* @var $filterForm \Symfony\Component\Form\FormInterface */
|
||||||
@ -132,17 +117,18 @@ class ActivityDateFilter implements FilterInterface
|
|||||||
|
|
||||||
public function describeAction($data, $format = 'string')
|
public function describeAction($data, $format = 'string')
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
"Filtered by date of activity: only between %date_from% and %date_to%",
|
'Filtered by date of activity: only between %date_from% and %date_to%',
|
||||||
array(
|
[
|
||||||
"%date_from%" => $data['date_from']->format('d-m-Y'),
|
'%date_from%' => $data['date_from']->format('d-m-Y'),
|
||||||
'%date_to%' => $data['date_to']->format('d-m-Y')
|
'%date_to%' => $data['date_to']->format('d-m-Y')
|
||||||
));
|
]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return "Filtered by date activity";
|
return 'Filtered by date activity';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, ExportEl
|
|||||||
protected TranslatorInterface $translator;
|
protected TranslatorInterface $translator;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TranslatableStringHelper $translatableStringHelper,
|
TranslatableStringHelper $translatableStringHelper,
|
||||||
ActivityReasonRepository $activityReasonRepository,
|
ActivityReasonRepository $activityReasonRepository,
|
||||||
TranslatorInterface $translator
|
TranslatorInterface $translator
|
||||||
) {
|
) {
|
||||||
$this->translatableStringHelper = $translatableStringHelper;
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
$this->activityReasonRepository = $activityReasonRepository;
|
$this->activityReasonRepository = $activityReasonRepository;
|
||||||
@ -187,7 +187,7 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, ExportEl
|
|||||||
|
|
||||||
public function getTitle()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return "Filtered by person having an activity in a period";
|
return 'Filtered by person having an activity in a period';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user