mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
add validation and translations
This commit is contained in:
parent
7a76868f6a
commit
13f3a1f55f
@ -26,6 +26,7 @@ use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Chill\MainBundle\Form\Type\Export\FilterType;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -34,6 +35,17 @@ use Doctrine\ORM\Query\Expr;
|
||||
*/
|
||||
class ActivityDateFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
|
||||
public function addRole()
|
||||
{
|
||||
@ -93,12 +105,14 @@ class ActivityDateFilter implements FilterInterface
|
||||
|
||||
// check that fields are not empty
|
||||
if ($date_from === null) {
|
||||
$form->get('date_from')->addError(new FormError('This field '
|
||||
. 'should not be empty'));
|
||||
$form->get('date_from')->addError(new FormError(
|
||||
$this->translator->trans('This field '
|
||||
. 'should not be empty')));
|
||||
}
|
||||
if ($date_to === null) {
|
||||
$form->get('date_to')->addError(new FormError('This field '
|
||||
. 'should not be empty'));
|
||||
$form->get('date_to')->addError(new FormError(
|
||||
$this->translator->trans('This field '
|
||||
. 'should not be empty')));
|
||||
}
|
||||
|
||||
// check that date_from is before date_to
|
||||
@ -107,8 +121,10 @@ class ActivityDateFilter implements FilterInterface
|
||||
&&
|
||||
$date_from >= $date_to
|
||||
) {
|
||||
$form->get('date_to')->addError(new FormError('This date '
|
||||
. 'should be after the date given in "activities after" field'));
|
||||
$form->get('date_to')->addError(new FormError(
|
||||
$this->translator->trans('This date should be after '
|
||||
. 'the date given in "Implied in an activity after '
|
||||
. 'this date" field')));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -30,13 +30,16 @@ use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ActivityReasonFilter implements FilterInterface
|
||||
class ActivityReasonFilter implements FilterInterface,
|
||||
ExportElementValidatedInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
@ -131,8 +134,16 @@ class ActivityReasonFilter implements FilterInterface
|
||||
'expanded' => false
|
||||
));
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
if ($data['reasons'] === null || count($data['reasons']) === 0) {
|
||||
$context->buildViolation("At least one reason must be choosen")
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Filter by reason';
|
||||
}
|
||||
|
@ -32,13 +32,17 @@ use Chill\ActivityBundle\Entity\ActivityReason;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PersonHavingActivityBetweenDateFilter implements FilterInterface
|
||||
class PersonHavingActivityBetweenDateFilter implements FilterInterface,
|
||||
ExportElementValidatedInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@ -53,12 +57,20 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface
|
||||
*/
|
||||
protected $activityReasonRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
EntityRepository $activityReasonRepository
|
||||
EntityRepository $activityReasonRepository,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->activityReasonRepository = $activityReasonRepository;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
|
||||
@ -158,12 +170,14 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface
|
||||
|
||||
// check that fields are not empty
|
||||
if ($date_from === null) {
|
||||
$form->get('date_from')->addError(new FormError('This field '
|
||||
. 'should not be empty'));
|
||||
$form->get('date_from')->addError(new FormError(
|
||||
$this->translator->trans('This field '
|
||||
. 'should not be empty')));
|
||||
}
|
||||
if ($date_to === null) {
|
||||
$form->get('date_to')->addError(new FormError('This field '
|
||||
. 'should not be empty'));
|
||||
$form->get('date_to')->addError(new FormError(
|
||||
$this->translator->trans('This field '
|
||||
. 'should not be empty')));
|
||||
}
|
||||
|
||||
// check that date_from is before date_to
|
||||
@ -172,13 +186,22 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface
|
||||
&&
|
||||
$date_from >= $date_to
|
||||
) {
|
||||
$form->get('date_to')->addError(new FormError('This date '
|
||||
$form->get('date_to')->addError(new FormError(
|
||||
$this->translator->trans('This date '
|
||||
. 'should be after the date given in "Implied in an '
|
||||
. 'activity after this date" field'));
|
||||
. 'activity after this date" field')));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
if ($data['reasons'] === null || count($data['reasons']) === 0) {
|
||||
$context->buildViolation("At least one reason must be choosen")
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -33,6 +33,8 @@ services:
|
||||
|
||||
chill.activity.export.date_filter:
|
||||
class: Chill\ActivityBundle\Export\Filter\ActivityDateFilter
|
||||
arguments:
|
||||
- "@translator"
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: 'activity_date_filter' }
|
||||
|
||||
@ -41,6 +43,7 @@ services:
|
||||
arguments:
|
||||
- "@chill.main.helper.translatable_string"
|
||||
- "@chill_activity.repository.reason"
|
||||
- "@translator"
|
||||
tags:
|
||||
- #0 register as a filter
|
||||
name: chill.export_filter
|
||||
|
@ -103,8 +103,11 @@ Count activities by various parameters.: Compte le nombre d'activités enregistr
|
||||
Filter by reason: Filtrer par sujet d'activité
|
||||
'Filtered by reasons: only %list%': 'Filtré par sujet: seulement %list%'
|
||||
|
||||
|
||||
Filtered by date activity: Filtrer par date d'activité
|
||||
Activities after this date: Activités après cette date
|
||||
Activities before this date: Activités avant cette date
|
||||
"Filtered by date of activity: only between %date_from% and %date_to%": "Filtré par date de l'activité: uniquement entre %date_from% et %date_to%"
|
||||
This date should be after the date given in "Implied in an activity after this date" field: Cette date devrait être postérieure à la date donnée dans le champ "activités après cette date"
|
||||
|
||||
Filtered by person having an activity in a period: Uniquement les personnes ayant eu une activité dans la période donnée
|
||||
Implied in an activity after this date: Impliqué dans une activité après cette date
|
||||
@ -112,8 +115,10 @@ Implied in an activity before this date: Impliqué dans une activité avant cett
|
||||
Filtered by person having an activity between %date_from% and %date_to% with reasons %reasons_name%: Filtré par personnes associées à une activité entre %date_from% et %date_to% avec les sujets %reasons_name%
|
||||
Activity reasons for those activities: Sujets de ces activités
|
||||
|
||||
|
||||
#aggregators
|
||||
Aggregate by activity reason: Aggréger par sujet de l'activité
|
||||
By reason: Par sujet
|
||||
By category of reason: Par catégorie de sujet
|
||||
Reason's level: Niveau du sujet
|
||||
Aggregate by activity type: Aggréger par date d'activité
|
||||
|
@ -1 +1,2 @@
|
||||
The reasons's level should not be empty: Le niveau du sujet ne peut pas être vide
|
||||
At least one reason must be choosen: Au moins un sujet doit être choisi
|
||||
|
Loading…
x
Reference in New Issue
Block a user