1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ProjetNormandie\ComptaBundle\Admin; |
4
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
6
|
|
|
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType; |
7
|
|
|
use Sonata\AdminBundle\Route\RouteCollectionInterface; |
8
|
|
|
use Sonata\AdminBundle\Show\ShowMapper; |
9
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
10
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
11
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
12
|
|
|
use Sonata\AdminBundle\Route\RouteCollection; |
13
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter; |
14
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateType; |
16
|
|
|
use Sonata\AdminBundle\Form\Type\ModelListType; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Administration manager for the Compta Bundle. |
20
|
|
|
*/ |
21
|
|
|
class DonationAdmin extends AbstractAdmin |
22
|
|
|
{ |
23
|
|
|
protected $baseRouteName = 'pncomptabundle_admin_donation'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param RouteCollection $collection |
27
|
|
|
*/ |
28
|
|
|
protected function configureRoutes(RouteCollectionInterface $collection): void |
29
|
|
|
{ |
30
|
|
|
$collection |
31
|
|
|
->remove('show') |
32
|
|
|
->remove('export') |
33
|
|
|
->remove('delete'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param FormMapper $form |
38
|
|
|
*/ |
39
|
|
|
protected function configureFormFields(FormMapper $form): void |
40
|
|
|
{ |
41
|
|
|
$form |
42
|
|
|
->add('id', TextType::class, ['label' => 'label.id', 'attr' => ['readonly' => true]]) |
43
|
|
|
->add('user', ModelListType::class, [ |
44
|
|
|
'btn_add' => false, |
45
|
|
|
'btn_list' => true, |
46
|
|
|
'btn_edit' => false, |
47
|
|
|
'btn_delete' => true, |
48
|
|
|
'btn_catalogue' => true, |
49
|
|
|
'label' => 'label.user', |
50
|
|
|
]) |
51
|
|
|
->add('value', null, ['label' => 'label.value']) |
52
|
|
|
->add('dateDonation', DateType::class, [ |
53
|
|
|
'label' => 'label.donatedAt', |
54
|
|
|
'required' => true, |
55
|
|
|
'years' => range(2004, date('Y')) |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param DatagridMapper $filter |
61
|
|
|
*/ |
62
|
|
|
protected function configureDatagridFilters(DatagridMapper $filter): void |
63
|
|
|
{ |
64
|
|
|
$filter |
65
|
|
|
->add('user', ModelFilter::class, [ |
66
|
|
|
'label' => 'label.user', |
67
|
|
|
'field_type' => ModelAutocompleteType::class, |
68
|
|
|
'field_options' => ['property' => 'username'], |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param ListMapper $list |
74
|
|
|
*/ |
75
|
|
|
protected function configureListFields(ListMapper $list): void |
76
|
|
|
{ |
77
|
|
|
$list->addIdentifier('id', null, ['label' => 'label.id']) |
78
|
|
|
->add('user', null, ['label' => 'label.user']) |
79
|
|
|
->add('dateDonation', 'datetime', ['label' => 'label.donatedAt']) |
80
|
|
|
->add('value', null, ['label' => 'label.value']) |
81
|
|
|
->add('_action', 'actions', [ |
82
|
|
|
'actions' => [ |
83
|
|
|
'show' => [], |
84
|
|
|
'edit' => [], |
85
|
|
|
] |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param ShowMapper $show |
91
|
|
|
*/ |
92
|
|
|
protected function configureShowFields(ShowMapper $show): void |
93
|
|
|
{ |
94
|
|
|
$show |
95
|
|
|
->add('id', null, ['label' => 'label.id']) |
96
|
|
|
->add('dateDonation', 'datetime', ['label' => 'label.donatedAt']) |
97
|
|
|
->add('value', null, ['label' => 'label.value']); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|