1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FSi\Bundle\AdminBundle\Admin\CRUD; |
11
|
|
|
|
12
|
|
|
use FSi\Bundle\AdminBundle\Admin\AbstractElement; |
13
|
|
|
use FSi\Bundle\AdminBundle\Exception\RuntimeException; |
14
|
|
|
use FSi\Component\DataGrid\DataGridFactoryInterface; |
15
|
|
|
use FSi\Component\DataGrid\DataGridInterface; |
16
|
|
|
use FSi\Component\DataSource\DataSourceFactoryInterface; |
17
|
|
|
use FSi\Component\DataSource\DataSourceInterface; |
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
19
|
|
|
|
20
|
|
|
abstract class GenericListElement extends AbstractElement implements ListElement |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var \FSi\Component\DataSource\DataSourceFactoryInterface |
24
|
|
|
*/ |
25
|
|
|
protected $datasourceFactory; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \FSi\Component\DataGrid\DataGridFactoryInterface |
29
|
|
|
*/ |
30
|
|
|
protected $datagridFactory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function getRoute() |
36
|
|
|
{ |
37
|
|
|
return 'fsi_admin_list'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function configureOptions(OptionsResolver $resolver) |
44
|
|
|
{ |
45
|
|
|
$resolver->setDefaults([ |
46
|
|
|
'template_list' => null, |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$resolver->setAllowedTypes('template_list', ['null', 'string']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function setDataGridFactory(DataGridFactoryInterface $factory) |
56
|
|
|
{ |
57
|
|
|
$this->datagridFactory = $factory; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function setDataSourceFactory(DataSourceFactoryInterface $factory) |
64
|
|
|
{ |
65
|
|
|
$this->datasourceFactory = $factory; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function createDataGrid() |
72
|
|
|
{ |
73
|
|
|
$datagrid = $this->initDataGrid($this->datagridFactory); |
74
|
|
|
|
75
|
|
|
if (!is_object($datagrid) || !$datagrid instanceof DataGridInterface) { |
76
|
|
|
throw new RuntimeException('initDataGrid should return instanceof FSi\\Component\\DataGrid\\DataGridInterface'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $datagrid; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function createDataSource() |
86
|
|
|
{ |
87
|
|
|
$datasource = $this->initDataSource($this->datasourceFactory); |
88
|
|
|
|
89
|
|
|
if (!is_object($datasource) || !$datasource instanceof DataSourceInterface) { |
90
|
|
|
throw new RuntimeException('initDataSource should return instanceof FSi\\Component\\DataSource\\DataSourceInterface'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $datasource; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Initialize DataGrid. |
98
|
|
|
* |
99
|
|
|
* @param \FSi\Component\DataGrid\DataGridFactoryInterface $factory |
100
|
|
|
* @return \FSi\Component\DataGrid\DataGridInterface |
101
|
|
|
*/ |
102
|
|
|
abstract protected function initDataGrid(DataGridFactoryInterface $factory); |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Initialize DataSource. |
106
|
|
|
* |
107
|
|
|
* @param \FSi\Component\DataSource\DataSourceFactoryInterface $factory |
108
|
|
|
* @return \FSi\Component\DataSource\DataSourceInterface |
109
|
|
|
*/ |
110
|
|
|
abstract protected function initDataSource(DataSourceFactoryInterface $factory); |
111
|
|
|
} |
112
|
|
|
|