|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Action\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Action\Action; |
|
6
|
|
|
use LAG\AdminBundle\Admin\AdminInterface; |
|
7
|
|
|
use LAG\AdminBundle\Admin\Factory\FilterFactory; |
|
8
|
|
|
use LAG\AdminBundle\Configuration\Factory\ConfigurationFactory; |
|
9
|
|
|
use LAG\AdminBundle\Field\Factory\FieldFactory; |
|
10
|
|
|
|
|
11
|
|
|
class ActionFactory |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var FieldFactory |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $fieldFactory; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var FilterFactory |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $filterFactory; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var ConfigurationFactory |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $configurationFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* ActionFactory constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param FieldFactory $fieldFactory |
|
32
|
|
|
* @param FilterFactory $filterFactory |
|
33
|
|
|
* @param ConfigurationFactory $configurationFactory |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function __construct( |
|
36
|
|
|
FieldFactory $fieldFactory, |
|
37
|
|
|
FilterFactory $filterFactory, |
|
38
|
|
|
ConfigurationFactory $configurationFactory |
|
39
|
|
|
) { |
|
40
|
1 |
|
$this->fieldFactory = $fieldFactory; |
|
41
|
1 |
|
$this->filterFactory = $filterFactory; |
|
42
|
1 |
|
$this->configurationFactory = $configurationFactory; |
|
43
|
1 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Create an Action from configuration values. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $actionName |
|
49
|
|
|
* @param array $configuration |
|
50
|
|
|
* @param AdminInterface $admin |
|
51
|
|
|
* |
|
52
|
|
|
* @return Action |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function create($actionName, array $configuration, AdminInterface $admin) |
|
55
|
|
|
{ |
|
56
|
|
|
// create action configuration object |
|
57
|
|
|
$actionConfiguration = $this |
|
58
|
1 |
|
->configurationFactory |
|
59
|
1 |
|
->createActionConfiguration($actionName, $admin, $configuration); |
|
60
|
|
|
|
|
61
|
|
|
// create action |
|
62
|
1 |
|
$action = new Action($actionName, $actionConfiguration); |
|
63
|
|
|
|
|
64
|
|
|
// adding fields items to actions |
|
65
|
1 |
|
foreach ($actionConfiguration->getParameter('fields') as $fieldName => $fieldConfiguration) { |
|
66
|
|
|
$field = $this |
|
67
|
1 |
|
->fieldFactory |
|
68
|
1 |
|
->create($fieldName, $fieldConfiguration); |
|
69
|
1 |
|
$action->addField($field); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// adding filters to the action |
|
73
|
1 |
|
foreach ($actionConfiguration->getParameter('filters') as $fieldName => $filterConfiguration) { |
|
74
|
|
|
$filter = $this |
|
75
|
|
|
->filterFactory |
|
76
|
|
|
->create($fieldName, $filterConfiguration); |
|
77
|
|
|
$action->addFilter($filter); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// add batch action |
|
81
|
1 |
|
if (count($action->getConfiguration()->getParameter('batch'))) { |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
return $action; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for the bodies of
ifstatements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
ifbodies can be removed. If you have an empty if but statements in theelsebranch, consider inverting the condition.could be turned into
This is much more concise to read.