mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
allow to remove some units from date interval
This commit is contained in:
parent
c1b8de4ee5
commit
d2895bfb7c
@ -50,3 +50,7 @@ Version 1.5.7
|
|||||||
- add css layout for boxes ;
|
- add css layout for boxes ;
|
||||||
- collect supplementary query parameters in SearchController ;
|
- collect supplementary query parameters in SearchController ;
|
||||||
|
|
||||||
|
Version 1.5.8
|
||||||
|
=============
|
||||||
|
|
||||||
|
- allow to remove interval units from DateInterval
|
||||||
|
@ -23,9 +23,38 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
use Chill\MainBundle\Form\Type\DataTransformer\DateIntervalTransformer;
|
use Chill\MainBundle\Form\Type\DataTransformer\DateIntervalTransformer;
|
||||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Show a dateInterval type
|
||||||
*
|
*
|
||||||
|
* Options:
|
||||||
|
*
|
||||||
|
* - `unit_choices`: an array of available units choices.
|
||||||
|
*
|
||||||
|
* The oiriginal `unit_choices` are :
|
||||||
|
* ```
|
||||||
|
* [
|
||||||
|
* 'Days' => 'D',
|
||||||
|
* 'Weeks' => 'W',
|
||||||
|
* 'Months' => 'M',
|
||||||
|
* 'Years' => 'Y'
|
||||||
|
* ]
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* You can remove one or more entries:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* $builder
|
||||||
|
* ->add('duration', DateIntervalType::class, array(
|
||||||
|
* 'unit_choices' => [
|
||||||
|
* 'Years' => 'Y',
|
||||||
|
* 'Months' => 'M',
|
||||||
|
* ]
|
||||||
|
* ));
|
||||||
|
* ```
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DateIntervalType extends AbstractType
|
class DateIntervalType extends AbstractType
|
||||||
@ -42,16 +71,39 @@ class DateIntervalType extends AbstractType
|
|||||||
]
|
]
|
||||||
])
|
])
|
||||||
->add('unit', ChoiceType::class, [
|
->add('unit', ChoiceType::class, [
|
||||||
'choices' => [
|
'choices' => $options['unit_choices'],
|
||||||
'Days' => 'D',
|
|
||||||
'Weeks' => 'W',
|
|
||||||
'Months' => 'M',
|
|
||||||
'Years' => 'Y'
|
|
||||||
],
|
|
||||||
'choices_as_values' => true
|
'choices_as_values' => true
|
||||||
])
|
])
|
||||||
;
|
;
|
||||||
|
|
||||||
$builder->addModelTransformer(new DateIntervalTransformer());
|
$builder->addModelTransformer(new DateIntervalTransformer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver
|
||||||
|
->setDefined('unit_choices')
|
||||||
|
->setDefault('unit_choices', [
|
||||||
|
'Days' => 'D',
|
||||||
|
'Weeks' => 'W',
|
||||||
|
'Months' => 'M',
|
||||||
|
'Years' => 'Y'
|
||||||
|
])
|
||||||
|
->setAllowedValues('unit_choices', function($values) {
|
||||||
|
if (FALSE === is_array($values)) {
|
||||||
|
throw new InvalidOptionsException("The value `unit_choice` should be an array");
|
||||||
|
}
|
||||||
|
|
||||||
|
$diff = \array_diff(\array_values($values), ['D', 'W', 'M', 'Y']);
|
||||||
|
if (count($diff) == 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new InvalidOptionsException(sprintf("The values of the "
|
||||||
|
. "units should be 'D', 'W', 'M', 'Y', those are invalid: %s",
|
||||||
|
\implode(', ', $diff)));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@ Edit: Modifier
|
|||||||
Update: Mettre à jour
|
Update: Mettre à jour
|
||||||
Back to the list: Retour à la liste
|
Back to the list: Retour à la liste
|
||||||
|
|
||||||
|
#interval
|
||||||
|
Years: Années
|
||||||
|
|
||||||
#elements used in software
|
#elements used in software
|
||||||
centers: centres
|
centers: centres
|
||||||
Centers: Centres
|
Centers: Centres
|
||||||
|
Loading…
x
Reference in New Issue
Block a user