mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 04:53:49 +00:00
Prepare for moving into monorepo
This commit is contained in:
124
src/Bundle/ChillBudgetBundle/Form/ChargeType.php
Normal file
124
src/Bundle/ChillBudgetBundle/Form/ChargeType.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\AMLI\BudgetBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\AMLI\BudgetBundle\Config\ConfigRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\AMLI\BudgetBundle\Entity\Charge;
|
||||
|
||||
class ChargeType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ConfigRepository
|
||||
*/
|
||||
protected $configRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
) {
|
||||
$this->configRepository = $configRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('type', ChoiceType::class, [
|
||||
'choices' => $this->getTypes(),
|
||||
'placeholder' => 'Choose a charge type'
|
||||
])
|
||||
->add('amount', MoneyType::class)
|
||||
->add('comment', TextAreaType::class, [
|
||||
'required' => false
|
||||
])
|
||||
;
|
||||
|
||||
if ($options['show_start_date']) {
|
||||
$builder->add('startDate', ChillDateType::class, [
|
||||
'label' => 'Start of validity period'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($options['show_end_date']) {
|
||||
$builder->add('endDate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
'label' => 'End of validity period'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($options['show_help']) {
|
||||
$builder->add('help', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'charge.help.running' => Charge::HELP_ASKED,
|
||||
'charge.help.no' => Charge::HELP_NO,
|
||||
'charge.help.yes' => Charge::HELP_YES,
|
||||
'charge.help.not-concerned' => Charge::HELP_NOT_RELEVANT
|
||||
],
|
||||
'placeholder' => 'Choose a status',
|
||||
'required' => false,
|
||||
'label' => 'Help to pay charges'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getTypes()
|
||||
{
|
||||
$charges = $this->configRepository
|
||||
->getChargesLabels();
|
||||
|
||||
// rewrite labels to filter in language
|
||||
foreach ($charges as $key => $labels) {
|
||||
$charges[$key] = $this->translatableStringHelper->localize($labels);
|
||||
}
|
||||
|
||||
\asort($charges);
|
||||
|
||||
return \array_flip($charges);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\AMLI\BudgetBundle\Entity\Charge',
|
||||
'show_start_date' => true,
|
||||
'show_end_date' => true,
|
||||
'show_help' => true
|
||||
));
|
||||
|
||||
$resolver
|
||||
->setAllowedTypes('show_start_date', 'boolean')
|
||||
->setAllowedTypes('show_end_date', 'boolean')
|
||||
->setAllowedTypes('show_help', 'boolean')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'chill_amli_budgetbundle_charge';
|
||||
}
|
||||
|
||||
|
||||
}
|
108
src/Bundle/ChillBudgetBundle/Form/ResourceType.php
Normal file
108
src/Bundle/ChillBudgetBundle/Form/ResourceType.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\AMLI\BudgetBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\AMLI\BudgetBundle\Entity\Resource;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\AMLI\BudgetBundle\Config\ConfigRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
|
||||
class ResourceType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ConfigRepository
|
||||
*/
|
||||
protected $configRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
) {
|
||||
$this->configRepository = $configRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('type', ChoiceType::class, [
|
||||
'choices' => $this->getTypes(),
|
||||
'placeholder' => 'Choose a resource type',
|
||||
'label' => 'Resource element type'
|
||||
])
|
||||
->add('amount', MoneyType::class)
|
||||
->add('comment', TextAreaType::class, [
|
||||
'required' => false
|
||||
])
|
||||
;
|
||||
|
||||
if ($options['show_start_date']) {
|
||||
$builder->add('startDate', ChillDateType::class, [
|
||||
'label' => 'Start of validity period'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($options['show_end_date']) {
|
||||
$builder->add('endDate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
'label' => 'End of validity period'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getTypes()
|
||||
{
|
||||
$resources = $this->configRepository
|
||||
->getResourcesLabels();
|
||||
|
||||
// rewrite labels to filter in language
|
||||
foreach ($resources as $key => $labels) {
|
||||
$resources[$key] = $this->translatableStringHelper->localize($labels);
|
||||
}
|
||||
|
||||
asort($resources);
|
||||
|
||||
return \array_flip($resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => Resource::class,
|
||||
'show_start_date' => true,
|
||||
'show_end_date' => true
|
||||
));
|
||||
|
||||
$resolver
|
||||
->setAllowedTypes('show_start_date', 'boolean')
|
||||
->setAllowedTypes('show_end_date', 'boolean')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'chill_amli_budgetbundle_resource';
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user