|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* InstallController controller d'installation de l'application GLSR. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Quétier Laurent <[email protected]> |
|
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
10
|
|
|
* |
|
11
|
|
|
* @version since 1.0.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace AppBundle\Controller\Install; |
|
16
|
|
|
|
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use AppBundle\Controller\Install\AbstractInstallController; |
|
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
20
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
21
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
22
|
|
|
|
|
23
|
|
|
use AppBundle\Entity\User; |
|
24
|
|
|
use AppBundle\Form\Type\UserType; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* class InstallController |
|
28
|
|
|
* |
|
29
|
|
|
* @category Controller |
|
30
|
|
|
* |
|
31
|
|
|
* @Route("/install") |
|
32
|
|
|
*/ |
|
33
|
|
|
class InstallController extends AbstractInstallController |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Page d'accueil de l'installation. |
|
37
|
|
|
* |
|
38
|
|
|
* @Route("/", name="gs_install") |
|
39
|
|
|
* |
|
40
|
|
|
* @return \Symfony\Component\HttpFoundation\Response Rendue de la page |
|
41
|
|
|
*/ |
|
42
|
|
|
public function indexAction() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->render('AppBundle:install:index.html.twig'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Etape 1 de l'installation. |
|
49
|
|
|
* Création des utilisateurs. |
|
50
|
|
|
* |
|
51
|
|
|
* @Route("/step1", name="gs_install_st1") |
|
52
|
|
|
* @Method({"POST","GET"}) |
|
53
|
|
|
* @Template("AppBundle:install:step1.html.twig") |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
56
|
|
|
* |
|
57
|
|
|
* @return array|\Symfony\Component\HttpFoundation\Response Rendue de la page |
|
58
|
|
|
*/ |
|
59
|
|
|
public function step1Action(Request $request) |
|
60
|
|
|
{ |
|
61
|
|
|
$etm = $this->getDoctrine()->getManager(); |
|
62
|
|
|
$ctUser = count($etm->getRepository('AppBundle:User')->findAll()); |
|
63
|
|
|
$user = new User(); |
|
64
|
|
|
$message = null; |
|
65
|
|
|
|
|
66
|
|
|
if ($ctUser > 0 && $request->getMethod() == 'GET') { |
|
67
|
|
|
$message = 'gestock.install.st1.yet_exist'; |
|
68
|
|
|
} |
|
69
|
|
|
$form = $this->createForm(new UserType(), $user, array( |
|
70
|
|
|
'action' => $this->generateUrl('gs_install_st1'), |
|
71
|
|
|
)); |
|
72
|
|
|
|
|
73
|
|
View Code Duplication |
if ($form->handleRequest($request)->isValid()) { |
|
|
|
|
|
|
74
|
|
|
$user->setEnabled(true); |
|
75
|
|
|
$userManager = $this->get('fos_user.user_manager'); |
|
76
|
|
|
$userManager->updateUser($user); |
|
77
|
|
|
$this->addFlash('info', 'gestock.install.st1.flash'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return array( |
|
81
|
|
|
'message' => $message, |
|
82
|
|
|
'form' => $form->createView() |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Etape 2 de l'installation. |
|
88
|
|
|
* Création de l'entreprise. |
|
89
|
|
|
* |
|
90
|
|
|
* @Route("/step2", name="gs_install_st2") |
|
91
|
|
|
* @Method({"POST","GET"}) |
|
92
|
|
|
* @Template("AppBundle:install:step2.html.twig") |
|
93
|
|
|
* |
|
94
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
95
|
|
|
* |
|
96
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|array Rendue de la page |
|
97
|
|
|
*/ |
|
98
|
|
|
public function step2Action(Request $request) |
|
99
|
|
|
{ |
|
100
|
|
|
$return = $this->stepAction( |
|
101
|
|
|
$request, |
|
102
|
|
|
'Company', |
|
103
|
|
|
'\AppBundle\Entity\Company', |
|
104
|
|
|
'\AppBundle\Form\Type\CompanyType', |
|
105
|
|
|
2 |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
return $return; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Etape 3 de l'installation. |
|
113
|
|
|
* Création de la configuration. |
|
114
|
|
|
* |
|
115
|
|
|
* @Route("/step3", name="gs_install_st3") |
|
116
|
|
|
* @Method({"POST","GET"}) |
|
117
|
|
|
* @Template("AppBundle:install:step3.html.twig") |
|
118
|
|
|
* |
|
119
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
120
|
|
|
* |
|
121
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse| |
|
122
|
|
|
* array<string,string|null|Settings|\Symfony\Component\Form\FormView> Rendue de la page |
|
123
|
|
|
*/ |
|
124
|
|
|
public function step3Action(Request $request) |
|
125
|
|
|
{ |
|
126
|
|
|
$return = $this->stepAction( |
|
127
|
|
|
$request, |
|
128
|
|
|
'Settings', |
|
129
|
|
|
'\AppBundle\Entity\Settings', |
|
130
|
|
|
'\AppBundle\Form\Type\SettingsType', |
|
131
|
|
|
3 |
|
132
|
|
|
); |
|
133
|
|
|
|
|
134
|
|
|
return $return; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Etape 4 de l'installation. |
|
139
|
|
|
* Cronfiguration de l'application. |
|
140
|
|
|
* |
|
141
|
|
|
* @Route("/step4", name="gs_install_st4") |
|
142
|
|
|
* @Method({"GET"}) |
|
143
|
|
|
* @Template("AppBundle:install:step4.html.twig") |
|
144
|
|
|
* |
|
145
|
|
|
* @return \Symfony\Component\HttpFoundation\Response Rendue de la page |
|
146
|
|
|
*/ |
|
147
|
|
|
public function step4Action() |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->render('AppBundle:install:step4.html.twig'); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Etape 5 de l'installation. |
|
154
|
|
|
* Création des fournisseurs. |
|
155
|
|
|
* |
|
156
|
|
|
* @Route("/step5", name="gs_install_st5") |
|
157
|
|
|
* @Method({"POST","GET"}) |
|
158
|
|
|
* @Template("AppBundle:install:step5.html.twig") |
|
159
|
|
|
* |
|
160
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
161
|
|
|
* |
|
162
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse| |
|
163
|
|
|
* array<string,string|null|Supplier|\Symfony\Component\Form\FormView> Rendue de la page |
|
164
|
|
|
*/ |
|
165
|
|
|
public function step5Action(Request $request) |
|
166
|
|
|
{ |
|
167
|
|
|
$return = $this->stepAction( |
|
168
|
|
|
$request, |
|
169
|
|
|
'Supplier', |
|
170
|
|
|
'\AppBundle\Entity\Supplier', |
|
171
|
|
|
'\AppBundle\Form\Type\SupplierType', |
|
172
|
|
|
5 |
|
173
|
|
|
); |
|
174
|
|
|
|
|
175
|
|
|
return $return; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Etape 6 de l'installation. |
|
180
|
|
|
* Création des articles. |
|
181
|
|
|
* |
|
182
|
|
|
* @Route("/step6", name="gs_install_st6") |
|
183
|
|
|
* @Method({"POST","GET"}) |
|
184
|
|
|
* @Template("AppBundle:install:step6.html.twig") |
|
185
|
|
|
* |
|
186
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
187
|
|
|
* |
|
188
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse| |
|
189
|
|
|
* array<string,string|null|Article|\Symfony\Component\Form\FormView> Rendue de la page |
|
190
|
|
|
*/ |
|
191
|
|
|
public function step6Action(Request $request) |
|
192
|
|
|
{ |
|
193
|
|
|
$return = $this->stepAction( |
|
194
|
|
|
$request, |
|
195
|
|
|
'Article', |
|
196
|
|
|
'\AppBundle\Entity\Article', |
|
197
|
|
|
'\AppBundle\Form\Type\ArticleType', |
|
198
|
|
|
6 |
|
199
|
|
|
); |
|
200
|
|
|
|
|
201
|
|
|
return $return; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Etape 7 de l'installation. |
|
206
|
|
|
* Inventaire d'installation. |
|
207
|
|
|
* |
|
208
|
|
|
* @Route("/step7", name="gs_install_st7") |
|
209
|
|
|
* @Method({"GET"}) |
|
210
|
|
|
* @Template("AppBundle:install:step7.html.twig") |
|
211
|
|
|
* |
|
212
|
|
|
* @return array Rendue de la page |
|
213
|
|
|
*/ |
|
214
|
|
|
public function step7Action() |
|
215
|
|
|
{ |
|
216
|
|
|
$etm = $this->getDoctrine()->getManager(); |
|
217
|
|
|
$settings = $etm->getRepository('AppBundle:Settings')->find(1); |
|
218
|
|
|
$message = null; |
|
219
|
|
|
|
|
220
|
|
|
if ($settings->getFirstInventory() === null) { |
|
221
|
|
|
$message = 'gestock.install.st7.yet_exist'; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
return array('message' => $message); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|
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.