1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
6
|
|
|
* |
7
|
|
|
* This file is licenced under the GNU LGPL v3. |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Blast\Bundle\CoreBundle\Admin\Traits; |
13
|
|
|
|
14
|
|
|
use Blast\Bundle\CoreBundle\Admin\CoreAdmin; |
15
|
|
|
use Blast\Bundle\CoreBundle\DataSource\Iterator; |
16
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
17
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
18
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
19
|
|
|
use Sonata\AdminBundle\Show\ShowMapper; |
20
|
|
|
|
21
|
|
|
trait Base |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $exportFields = []; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param DatagridMapper $mapper |
30
|
|
|
*/ |
31
|
|
|
protected function configureDatagridFilters(DatagridMapper $mapper) |
32
|
|
|
{ |
33
|
|
|
CoreAdmin::configureDatagridFilters($mapper); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param ListMapper $mapper |
38
|
|
|
*/ |
39
|
|
|
protected function configureListFields(ListMapper $mapper) |
40
|
|
|
{ |
41
|
|
|
CoreAdmin::configureListFields($mapper); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param FormMapper $mapper |
46
|
|
|
*/ |
47
|
|
|
protected function configureFormFields(FormMapper $mapper) |
48
|
|
|
{ |
49
|
|
|
CoreAdmin::configureFormFields($mapper); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param ShowMapper $mapper |
54
|
|
|
*/ |
55
|
|
|
protected function configureShowFields(ShowMapper $mapper) |
56
|
|
|
{ |
57
|
|
|
CoreAdmin::configureShowFields($mapper); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
**/ |
63
|
|
|
public function getBatchActions() |
64
|
|
|
{ |
65
|
|
|
$actions = []; |
66
|
|
|
|
67
|
|
|
if ($this->isGranted('DELETE')) { |
|
|
|
|
68
|
|
|
$actions['delete'] = array( |
69
|
|
|
'label' => 'action_delete', |
70
|
|
|
'translation_domain' => 'SonataAdminBundle', |
71
|
|
|
'ask_confirmation' => true, |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $this->handleBatchActions($actions); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
**/ |
81
|
|
|
public function getExportFormats() |
82
|
|
|
{ |
83
|
|
|
$formats = []; |
84
|
|
|
foreach (parent::getExportFormats() as $format) { |
85
|
|
|
$formats[$format] = []; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return array_keys($this->addPresetExportFormats($formats)); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getExportFields() |
95
|
|
|
{ |
96
|
|
|
// prerequisites |
97
|
|
|
$fields = parent::getExportFields(); |
|
|
|
|
98
|
|
|
$this->getExportFormats(); |
99
|
|
|
|
100
|
|
|
// nothing to add |
101
|
|
|
if (!$this->exportFields) { |
102
|
|
|
return parent::getExportFields(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$request = $this->getConfigurationPool()->getContainer()->get('request_stack')->getMasterRequest(); |
|
|
|
|
106
|
|
|
|
107
|
|
|
// nothing specific to add |
108
|
|
|
if (!($request->get('format') |
109
|
|
|
&& isset($this->exportFields[$request->get('format')]))) { |
110
|
|
|
return parent::getExportFields(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
// specificities for this format |
114
|
|
|
return $this->exportFields[$request->get('format')]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// /** |
118
|
|
|
// * {@inheritdoc} |
119
|
|
|
// */ |
120
|
|
|
// public function getDataSourceIterator() |
|
|
|
|
121
|
|
|
// { |
122
|
|
|
// $datagrid = $this->getDatagrid(); |
|
|
|
|
123
|
|
|
// $datagrid->buildPager(); |
|
|
|
|
124
|
|
|
// |
125
|
|
|
// return $this->getModelManager()->getDataSourceIterator($datagrid, $this->getExportFields()); |
|
|
|
|
126
|
|
|
// // return new Iterator($datagrid->getQuery()->getQuery(), $this->getExportFields()); |
127
|
|
|
// } |
128
|
|
|
} |
129
|
|
|
|
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.