ProfilDeCotisationAdmin.php 2.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

namespace App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\Form\Type\DateTimeRangePickerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
11 12
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use App\Enum\CurrencyEnum;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

/**
 * Administration des profils de cotisation.
 *
 * KOHINOS : Outil de gestion de Monnaie Locale Complémentaire
 */
class ProfilDeCotisationAdmin extends AbstractAdmin
{
    protected $baseRouteName = 'profilcotisation';
    protected $baseRoutePattern = 'profilcotisation';

    protected $datagridValues = [
        '_sort_order' => 'DESC',
        '_sort_by' => 'createdAt',
    ];

    /**
     * {@inheritdoc}
     */
    protected function configureFormFields(FormMapper $formMapper): void
    {
        $formMapper
            ->with('Profil', ['class' => 'col-md-12'])
36 37 38
                ->add('montant', NumberType::class, [
                    'label' => 'Montant'
                ])
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
                ->add('tauxCotisation', NumberType::class, [
                    'label' => 'Taux de cotisation'
                ])
            ->end()
        ;

        parent::configureFormFields($formMapper);
    }

    /**
     * {@inheritdoc}
     */
    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
    {
        $datagridMapper
            ->add('createdAt', 'doctrine_orm_datetime_range', [
                'field_type' => DateTimeRangePickerType::class,
                'label' => 'Date de création',
            ])
            ->add('updatedAt', 'doctrine_orm_datetime_range', [
                'field_type' => DateTimeRangePickerType::class,
                'label' => 'Date de mise à jour',
            ])
        ;
    }

    protected function configureListFields(ListMapper $listMapper): void
    {
        $listMapper
68 69 70
            ->addIdentifier('montant', FieldDescriptionInterface::TYPE_CURRENCY, [
                'label' => 'Montant',
                'currency' => CurrencyEnum::getCode(CurrencyEnum::CURRENCY_EURO),
71 72
                'sortable' => true
            ])
73 74
            ->addIdentifier('tauxCotisation', null, [
                'label' => 'Taux de cotisation',
75 76 77
                'sortable' => true
            ])
            ->add('createdAt', 'date', [
78 79 80
                'pattern' => 'dd/MM/YYYY HH:mm',
                'label' => 'Crée le',
            ])
81
            ->add('updatedAt', 'date', [
82 83 84 85 86 87 88 89 90
                'pattern' => 'dd/MM/YYYY HH:mm',
                'label' => 'Mis à jour le',
            ])
            ->add('_action', null, [
                'actions' => ['edit' => []],
            ])
        ;
    }
}