1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace App\Admin;
use App\Entity\Prestataire;
use App\Enum\MoyenEnum;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
class CotisationAdmin extends AbstractAdmin
{
protected $baseRouteName = 'cotisation';
protected $baseRoutePattern = 'cotisation';
/**
* {@inheritdoc}
*/
protected function configureShowFields(ShowMapper $showMapper)
{
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('cotisationInfos.annee', null, array('label' => 'Année'))
->add('montant', null, array('label' => 'Montant'))
->add('cotisationInfos.recu', null, array('label' => 'Recu ?'))
->add('operateur.username', null, array('label' => 'Login'))
->add('operateur.email', null, array('label' => 'Email'))
;
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$cotisation = $this->getSubject();
$now = new \DateTime();
$formMapper
->with('Cotisation', ['class' => 'col-md-8'])
->add('cotisationInfos.annee', null, array('label' => 'Année', 'data' => $now->format('Y')))
->add('montant', null, array('label' => 'Montant'))
->add('moyen', ChoiceType::class, array(
'required' => true,
'choices' => MoyenEnum::getAvailableTypes(),
'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice);
},
))
->add('cotisationInfos.recu', CheckboxType::class, array('label' => 'Reçu'))
->end()
->with('Date', ['class' => 'col-md-4'])
->add('cotisationInfos.debut', DateType::class, array(
'label' => 'Date de début',
'data' => new \DateTime(),
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'js-datepicker'],
))
->add('cotisationInfos.fin', DateType::class, array(
'label' => 'Date de fin',
'data' => new \DateTime('+ 1 year'),
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'js-datepicker'],
))
->end()
;
}
protected function configureRoutes(RouteCollection $collection)
{
// $collection->remove('edit');
$collection->remove('delete');
}
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
unset($this->listModes['mosaic']);
$listMapper
// ->addIdentifier('user')
->addIdentifier('cotisationInfos.annee')
->addIdentifier('cotisationInfos.debut')
->addIdentifier('cotisationInfos.fin')
->addIdentifier('montant')
->addIdentifier('moyen')
->addIdentifier('createdAt')
;
}
}