1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Admin; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\Venue; |
6
|
|
|
use Sonata\AdminBundle\Admin\Admin; |
7
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
8
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
9
|
|
|
use Sonata\AdminBundle\Exception\ModelManagerException; |
10
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
11
|
|
|
|
12
|
|
|
class VenueAdmin extends Admin |
13
|
|
|
{ |
14
|
|
|
protected $baseRouteName = 'AppBundle\Entity\Venue'; |
15
|
|
|
protected $baseRoutePattern = 'Venue'; |
16
|
|
|
protected $datagridValues = [ |
17
|
|
|
'_sort_order' => 'DESC', |
18
|
|
|
'_sort_by' => 'id', |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param \Sonata\AdminBundle\Form\FormMapper $formMapper |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
protected function configureFormFields(FormMapper $formMapper) |
27
|
|
|
{ |
28
|
|
|
$formMapper |
29
|
|
|
->with('Venue', ['class'=>'col-lg-12']) |
30
|
|
|
->add('title') |
31
|
|
|
->add('address') |
32
|
|
|
->add('hallTemplate') |
33
|
|
|
->end() |
34
|
|
|
; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
protected function configureListFields(ListMapper $listMapper) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$listMapper |
45
|
|
|
->add('title') |
46
|
|
|
->add('_action', 'actions', [ |
47
|
|
|
'actions' => [ |
48
|
|
|
'edit' => [], |
49
|
|
|
'delete' => [], |
50
|
|
|
], |
51
|
|
|
]) |
52
|
|
|
; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
61
|
|
|
{ |
62
|
|
|
$datagridMapper |
63
|
|
|
->add('title') |
64
|
|
|
; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param mixed $object |
69
|
|
|
* @return bool |
70
|
|
|
* @throws ModelManagerException |
71
|
|
|
*/ |
72
|
|
|
public function preRemove($object) |
73
|
|
|
{ |
74
|
|
|
$em = $this->getConfigurationPool()->getContainer()->get('Doctrine')->getManager(); |
75
|
|
|
if (count($object->getPerformanceEvents()) != 0) { |
76
|
|
|
$message = sprintf('An Error has occurred during deletion of item "%s".', $object->getTitle()); |
77
|
|
|
$em->detach($object); |
78
|
|
|
throw new ModelManagerException($message, 200); |
79
|
|
|
} |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function toString($object) |
84
|
|
|
{ |
85
|
|
|
return $object instanceof Venue |
86
|
|
|
? $object->getTitle() |
87
|
|
|
: 'Venue'; // shown in the breadcrumb on the create views |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.