|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProjetNormandie\UserBundle\Admin; |
|
6
|
|
|
|
|
7
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
|
8
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
|
9
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
|
10
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
|
11
|
|
|
use Sonata\AdminBundle\Form\Type\ModelListType; |
|
12
|
|
|
use Sonata\AdminBundle\Show\ShowMapper; |
|
13
|
|
|
use Sonata\AdminBundle\Route\RouteCollectionInterface; |
|
14
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
|
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
|
16
|
|
|
|
|
17
|
|
|
class UserBanAdmin extends AbstractAdmin |
|
18
|
|
|
{ |
|
19
|
|
|
protected $baseRouteName = 'pnu_admin_user_ban'; |
|
20
|
|
|
|
|
21
|
|
|
protected function configureRoutes(RouteCollectionInterface $collection): void |
|
22
|
|
|
{ |
|
23
|
|
|
$collection->remove('delete'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function configureFormFields(FormMapper $form): void |
|
27
|
|
|
{ |
|
28
|
|
|
$form |
|
29
|
|
|
->add('user', ModelListType::class, [ |
|
30
|
|
|
'data_class' => null, |
|
31
|
|
|
'btn_add' => false, |
|
32
|
|
|
'btn_list' => $this->isCurrentRoute('create'), |
|
33
|
|
|
'btn_delete' => false, |
|
34
|
|
|
'btn_catalogue' => $this->isCurrentRoute('create'), |
|
35
|
|
|
'label' => 'User', |
|
36
|
|
|
'required' => false |
|
37
|
|
|
]) |
|
38
|
|
|
->add('startDate', null, [ |
|
39
|
|
|
'label' => 'ban.form.start_date', |
|
40
|
|
|
'required' => true, |
|
41
|
|
|
'widget' => 'single_text', |
|
42
|
|
|
'disabled' => !$this->isCurrentRoute('create'), |
|
43
|
|
|
]) |
|
44
|
|
|
->add('endDate', null, [ |
|
45
|
|
|
'label' => 'ban.form.end_date', |
|
46
|
|
|
'required' => false, |
|
47
|
|
|
'widget' => 'single_text', |
|
48
|
|
|
'help' => 'ban.form.end_date_help', |
|
49
|
|
|
]) |
|
50
|
|
|
->add('reason', TextareaType::class, [ |
|
51
|
|
|
'label' => 'ban.form.reason', |
|
52
|
|
|
'required' => false, |
|
53
|
|
|
'attr' => ['rows' => 4], |
|
54
|
|
|
]) |
|
55
|
|
|
->add('active', CheckboxType::class, [ |
|
56
|
|
|
'label' => 'ban.form.active', |
|
57
|
|
|
'required' => false, |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function configureDatagridFilters(DatagridMapper $filter): void |
|
62
|
|
|
{ |
|
63
|
|
|
$filter |
|
64
|
|
|
->add('user.username', null, ['label' => 'ban.filter.username']) |
|
65
|
|
|
->add('active', null, ['label' => 'ban.filter.active']) |
|
66
|
|
|
->add('startDate', null, ['label' => 'ban.filter.start_date']) |
|
67
|
|
|
->add('endDate', null, ['label' => 'ban.filter.end_date']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function configureListFields(ListMapper $list): void |
|
71
|
|
|
{ |
|
72
|
|
|
$list |
|
73
|
|
|
->addIdentifier('id', null, ['label' => 'ban.list.id']) |
|
74
|
|
|
->add('user.username', null, ['label' => 'ban.list.username']) |
|
75
|
|
|
->add('startDate', 'datetime', ['label' => 'ban.list.start_date', 'format' => 'Y-m-d H:i']) |
|
76
|
|
|
->add('endDate', 'datetime', ['label' => 'ban.list.end_date', 'format' => 'Y-m-d H:i']) |
|
77
|
|
|
->add('reason', null, [ |
|
78
|
|
|
'label' => 'ban.list.reason', |
|
79
|
|
|
'template' => '@ProjetNormandieUser/Admin/list/ban_reason.html.twig' |
|
80
|
|
|
]) |
|
81
|
|
|
->add('active', null, ['editable' => true, 'label' => 'ban.list.active']) |
|
82
|
|
|
->add('_action', 'actions', [ |
|
83
|
|
|
'actions' => [ |
|
84
|
|
|
'show' => [], |
|
85
|
|
|
'edit' => [], |
|
86
|
|
|
] |
|
87
|
|
|
]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
protected function configureShowFields(ShowMapper $show): void |
|
91
|
|
|
{ |
|
92
|
|
|
$show |
|
93
|
|
|
->with('Ban Information', ['class' => 'col-md-6']) |
|
94
|
|
|
->add('id', null, ['label' => 'ban.show.id']) |
|
95
|
|
|
->add('user.username', null, ['label' => 'ban.show.username']) |
|
96
|
|
|
->add('user.email', null, ['label' => 'ban.show.email']) |
|
97
|
|
|
->add('startDate', 'datetime', ['label' => 'ban.show.start_date']) |
|
98
|
|
|
->add('endDate', 'datetime', ['label' => 'ban.show.end_date']) |
|
99
|
|
|
->add('active', null, ['label' => 'ban.show.active']) |
|
100
|
|
|
->end() |
|
101
|
|
|
->with('Details', ['class' => 'col-md-6']) |
|
102
|
|
|
->add('reason', null, ['label' => 'ban.show.reason']) |
|
103
|
|
|
->add('createdAt', 'datetime', ['label' => 'ban.show.created_at']) |
|
104
|
|
|
->add('updatedAt', 'datetime', ['label' => 'ban.show.updated_at']) |
|
105
|
|
|
->end(); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|