mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-10 08:44:58 +00:00
Feature: allow to administrate budget resources and charges from the admin
This commit is contained in:
42
src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php
Normal file
42
src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\BudgetBundle\Form\Admin;
|
||||
|
||||
use Chill\BudgetBundle\Entity\ChargeKind;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ChargeKindType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom',
|
||||
])
|
||||
->add('ordering', NumberType::class)
|
||||
->add('isActive', CheckboxType::class, [
|
||||
'label' => 'Actif ?',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', ChargeKind::class);
|
||||
}
|
||||
}
|
42
src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php
Normal file
42
src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\BudgetBundle\Form\Admin;
|
||||
|
||||
use Chill\BudgetBundle\Entity\ResourceKind;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ResourceKindType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom',
|
||||
])
|
||||
->add('ordering', NumberType::class)
|
||||
->add('isActive', CheckboxType::class, [
|
||||
'label' => 'Actif ?',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', ResourceKind::class);
|
||||
}
|
||||
}
|
@@ -13,15 +13,18 @@ namespace Chill\BudgetBundle\Form;
|
||||
|
||||
use Chill\BudgetBundle\Config\ConfigRepository;
|
||||
use Chill\BudgetBundle\Entity\Charge;
|
||||
use Chill\BudgetBundle\Entity\ChargeKind;
|
||||
use Chill\BudgetBundle\Repository\ChargeKindRepository;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_flip;
|
||||
use function asort;
|
||||
|
||||
@@ -31,21 +34,35 @@ class ChargeType extends AbstractType
|
||||
|
||||
protected TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
private ChargeKindRepository $repository;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
TranslatableStringHelperInterface $translatableStringHelper,
|
||||
ChargeKindRepository $repository,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->configRepository = $configRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->repository = $repository;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('type', ChoiceType::class, [
|
||||
'choices' => $this->getTypes(),
|
||||
'placeholder' => 'Choose a charge type',
|
||||
'attr' => ['class' => ' select2 '],
|
||||
->add('charge', EntityType::class, [
|
||||
'class' => ChargeKind::class,
|
||||
'choices' => $this->repository->findAllActive(),
|
||||
'label' => 'Charge type',
|
||||
'required' => true,
|
||||
'placeholder' => $this->translator->trans('admin.form.Choose the type of charge'),
|
||||
'choice_label' => function (ChargeKind $resource) {
|
||||
return $this->translatableStringHelper->localize($resource->getName());
|
||||
},
|
||||
'attr' => ['class' => 'select2'],
|
||||
])
|
||||
->add('amount', MoneyType::class)
|
||||
->add('comment', TextareaType::class, [
|
||||
|
@@ -13,15 +13,17 @@ namespace Chill\BudgetBundle\Form;
|
||||
|
||||
use Chill\BudgetBundle\Config\ConfigRepository;
|
||||
use Chill\BudgetBundle\Entity\Resource;
|
||||
use Chill\BudgetBundle\Entity\ResourceKind;
|
||||
use Chill\BudgetBundle\Repository\ResourceKindRepository;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_flip;
|
||||
|
||||
class ResourceType extends AbstractType
|
||||
@@ -30,22 +32,35 @@ class ResourceType extends AbstractType
|
||||
|
||||
protected TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
private ResourceKindRepository $repository;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
TranslatableStringHelperInterface $translatableStringHelper,
|
||||
ResourceKindRepository $repository,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->configRepository = $configRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->repository = $repository;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('type', ChoiceType::class, [
|
||||
'choices' => $this->getTypes(),
|
||||
'placeholder' => 'Choose a resource type',
|
||||
'label' => 'Resource element type',
|
||||
'attr' => ['class' => ' select2 '],
|
||||
->add('resource', EntityType::class, [
|
||||
'class' => ResourceKind::class,
|
||||
'choices' => $this->repository->findAllActive(),
|
||||
'label' => 'Resource type',
|
||||
'required' => true,
|
||||
'placeholder' => $this->translator->trans('admin.form.Choose the type of resource'),
|
||||
'choice_label' => function (ResourceKind $resource) {
|
||||
return $this->translatableStringHelper->localize($resource->getName());
|
||||
},
|
||||
'attr' => ['class' => 'select2'],
|
||||
])
|
||||
->add('amount', MoneyType::class)
|
||||
->add('comment', TextareaType::class, [
|
||||
|
Reference in New Issue
Block a user