|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Action; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Action\Responder\ListResponder; |
|
6
|
|
|
use LAG\AdminBundle\Filter\Factory\FilterFormBuilder; |
|
7
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
|
|
11
|
|
|
class ListAction extends Action |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var ListResponder |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $responder; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var FilterFormBuilder |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $filterFormBuilder; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Action constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $name |
|
27
|
|
|
* @param FormFactoryInterface $formFactory |
|
28
|
|
|
* @param ListResponder $responder |
|
29
|
|
|
* @param FilterFormBuilder $filterFormBuilder |
|
30
|
|
|
*/ |
|
31
|
1 |
|
public function __construct( |
|
32
|
|
|
$name, |
|
33
|
|
|
FormFactoryInterface $formFactory, |
|
34
|
|
|
ListResponder $responder, |
|
35
|
|
|
FilterFormBuilder $filterFormBuilder |
|
36
|
|
|
) { |
|
37
|
1 |
|
$this->name = $name; |
|
38
|
1 |
|
$this->formFactory = $formFactory; |
|
39
|
1 |
|
$this->responder = $responder; |
|
40
|
1 |
|
$this->filterFormBuilder = $filterFormBuilder; |
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param Request $request |
|
45
|
|
|
* |
|
46
|
|
|
* @return Response |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function __invoke(Request $request) |
|
49
|
|
|
{ |
|
50
|
|
|
// build the filters form |
|
51
|
|
|
$filterForm = $this |
|
52
|
1 |
|
->filterFormBuilder |
|
53
|
1 |
|
->build($this->configuration) |
|
54
|
|
|
; |
|
55
|
1 |
|
$filters = []; |
|
56
|
|
|
|
|
57
|
|
|
// load the filters |
|
58
|
1 |
|
if (null !== $filterForm) { |
|
59
|
1 |
|
$filterForm->handleRequest($request); |
|
60
|
|
|
|
|
61
|
1 |
|
if ($filterForm->isSubmitted() && $filterForm->isValid()) { |
|
62
|
|
|
$filters = $filterForm->getData(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// load the entities |
|
67
|
|
|
$this |
|
68
|
1 |
|
->admin |
|
69
|
1 |
|
->handleRequest($request, $filters) |
|
70
|
|
|
; |
|
71
|
|
|
|
|
72
|
|
|
$form = $this |
|
73
|
1 |
|
->formFactory |
|
74
|
1 |
|
->create( |
|
75
|
1 |
|
$this->configuration->getParameter('form'), |
|
76
|
1 |
|
$this->admin->getEntities(), |
|
77
|
1 |
|
$this->configuration->getParameter('form_options') |
|
78
|
|
|
) |
|
79
|
|
|
; |
|
80
|
1 |
|
$form->handleRequest($request); |
|
81
|
|
|
|
|
82
|
1 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
|
|
83
|
|
|
// TODO do something with the selected entities |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this |
|
87
|
1 |
|
->responder |
|
88
|
1 |
|
->respond($this->configuration, $this->admin, $form, $filterForm) |
|
89
|
|
|
; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
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.