1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* DefaultController controller 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; |
16
|
|
|
|
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
18
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
20
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
23
|
|
|
|
24
|
|
|
use AppBundle\Form\Type\SubFamilyLogType; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Default controller. |
28
|
|
|
* |
29
|
|
|
* @category Controller |
30
|
|
|
* |
31
|
|
|
* @Route("/") |
32
|
|
|
*/ |
33
|
|
|
class DefaultController extends Controller |
34
|
|
|
{ |
35
|
|
|
private $entities; |
36
|
|
|
|
37
|
|
|
public function __construct() |
38
|
|
|
{ |
39
|
|
|
// Tableau des entitées |
40
|
|
|
$this->entities = array( |
41
|
|
|
'AppBundle:User', |
42
|
|
|
'AppBundle:Company', |
43
|
|
|
'AppBundle:Settings', |
44
|
|
|
'AppBundle:FamilyLog', |
45
|
|
|
'AppBundle:SubFamilyLog', |
46
|
|
|
'AppBundle:ZoneStorage', |
47
|
|
|
'AppBundle:UnitStorage', |
48
|
|
|
'AppBundle:Tva', |
49
|
|
|
'AppBundle:Supplier', |
50
|
|
|
'AppBundle:Article', |
51
|
|
|
'AppBundle:Settings'); |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @Route("/", name="_home") |
57
|
|
|
* @Method("GET") |
58
|
|
|
* @Template() |
59
|
|
|
*/ |
60
|
|
|
public function indexAction() |
61
|
|
|
{ |
62
|
|
|
$url = ""; |
63
|
|
|
/** |
64
|
|
|
* Test d'installation |
65
|
|
|
*/ |
66
|
|
|
// $url = $this->testEntities(); |
|
|
|
|
67
|
|
|
if (empty($url)) { |
68
|
|
|
$url = $this->render('default/index.html.twig'); |
69
|
|
|
} else { |
70
|
|
|
$url = $this->redirectToRoute($url); |
71
|
|
|
} |
72
|
|
|
// replace this example code with whatever you need |
73
|
|
|
return $url; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Test des entités |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
private function testEntities() |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$url = null; |
84
|
|
|
$etm = $this->getDoctrine()->getManager(); |
85
|
|
|
// vérifie que les Entitées ne sont pas vides |
86
|
|
|
$nbEntities = count($this->entities); |
87
|
|
|
for ($index = 0; $index < $nbEntities; $index++) { |
88
|
|
|
$entity = $etm->getRepository( |
89
|
|
|
$this->entities[$index] |
90
|
|
|
); |
91
|
|
|
$entityData = $entity->find(1); |
92
|
|
|
|
93
|
|
|
if (empty($entityData)) { |
94
|
|
|
$message = 'gestock.install.none'; |
95
|
|
|
// $url = 'gs_install'; break; |
|
|
|
|
96
|
|
|
$url = '_home'; |
97
|
|
|
break; |
98
|
|
|
} elseif ($index === 10 && $entityData->getFirstInventory() === null) { |
99
|
|
|
$message = 'gestock.settings.application.first_inventory.none'; |
100
|
|
|
// $url = 'gestock_inventory_prepare'; break; |
|
|
|
|
101
|
|
|
$url = '_home'; |
102
|
|
|
break; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
if (isset($message)) { |
106
|
|
|
$this->addFlash('warning', $message); |
107
|
|
|
} |
108
|
|
|
return $url; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Récupère les subFamilyLog de la FamilyLog sélectionnée. |
113
|
|
|
* |
114
|
|
|
* @Route("/fill_subfamilylog", name="fill_subfamilylog") |
115
|
|
|
* @Method("POST") |
116
|
|
|
* @return Response |
117
|
|
|
*/ |
118
|
|
|
public function fillSubFamilyLogAction() |
119
|
|
|
{ |
120
|
|
|
$request = $this->getRequest(); |
|
|
|
|
121
|
|
|
$etm = $this->getDoctrine()->getManager(); |
122
|
|
|
if ($request->isXmlHttpRequest()) { |
123
|
|
|
$famLogId = ''; |
|
|
|
|
124
|
|
|
$subFamId = ''; |
|
|
|
|
125
|
|
|
$famLogId = $request->get('id'); |
126
|
|
|
$subFamId = $request->get('id2'); |
127
|
|
|
if ($famLogId != '') { |
128
|
|
|
$subFamilyLogs = $etm |
129
|
|
|
->getRepository('AppBundle:subFamilyLog') |
130
|
|
|
->getFromFamilyLog($famLogId); |
131
|
|
|
$familyLog = $etm |
132
|
|
|
->getRepository('AppBundle:familyLog') |
133
|
|
|
->find($famLogId); |
134
|
|
|
$tabSubFamilyLog = array(); |
135
|
|
|
$tabSubFamilyLog[0]['idOption'] = ''; |
136
|
|
|
$tabSubFamilyLog[0]['nameOption'] |
137
|
|
|
= 'Choice the Sub Family: '.$familyLog->getName(); |
138
|
|
|
$iterator = 1; |
139
|
|
|
foreach ($subFamilyLogs as $subFamilyLog) { |
140
|
|
|
$tabSubFamilyLog[$iterator]['idOption'] |
141
|
|
|
= $subFamilyLog->getId(); |
142
|
|
|
$tabSubFamilyLog[$iterator]['nameOption'] |
143
|
|
|
= $subFamilyLog->getName(); |
144
|
|
|
if ($subFamId != '') { |
145
|
|
|
$tabSubFamilyLog[$iterator]['optionOption'] |
146
|
|
|
= 'selected="selected"'; |
147
|
|
|
} else { |
148
|
|
|
$tabSubFamilyLog[$iterator]['optionOption'] = null; |
149
|
|
|
} |
150
|
|
|
$iterator++; |
151
|
|
|
} |
152
|
|
|
$response = new Response(); |
153
|
|
|
$data = json_encode($tabSubFamilyLog); |
154
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
155
|
|
|
$response->setContent($data); |
156
|
|
|
return $response; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
return new Response('Error'); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Récupère les FamilyLog de la requête post. |
164
|
|
|
* |
165
|
|
|
* @Route("/getfamilylog", name="getfamilylog") |
166
|
|
|
* @Method("GET") |
167
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
168
|
|
|
*/ |
169
|
|
|
public function getFamilyLogAction() |
170
|
|
|
{ |
171
|
|
|
$request = $this->getRequest(); |
|
|
|
|
172
|
|
|
$etm = $this->getDoctrine()->getManager(); |
173
|
|
|
if ($request->isXmlHttpRequest()) { |
174
|
|
|
$id = ''; |
|
|
|
|
175
|
|
|
$id = $request->get('id'); |
176
|
|
|
if ($id != '') { |
177
|
|
|
$supplier = $etm |
178
|
|
|
->getRepository('AppBundle:Supplier') |
179
|
|
|
->find($id); |
180
|
|
|
$familyLog['familylog'] = $supplier->getFamilyLog()->getId(); |
|
|
|
|
181
|
|
|
if (null !== $supplier->getSubFamilyLog()) { |
182
|
|
|
$familyLog['subfamilylog'] |
183
|
|
|
= $supplier->getSubFamilyLog()->getId(); |
184
|
|
|
} |
185
|
|
|
$response = new Response(); |
186
|
|
|
$data = json_encode($familyLog); |
187
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
188
|
|
|
$response->setContent($data); |
189
|
|
|
return $response; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
return new Response('Error'); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @Route("/chose-device", name="choseDevice") |
197
|
|
|
* @Template() |
198
|
|
|
*/ |
199
|
|
|
public function choseTablet2Action() |
200
|
|
|
{ |
201
|
|
|
$form = $this->createForm(new SubFamilyLogType()); |
202
|
|
|
$familylog = $this->getDoctrine()->getRepository('AppBundle:FamilyLog')->findAll(); |
203
|
|
|
|
204
|
|
|
return array( |
205
|
|
|
'form' => $form->createView(), |
206
|
|
|
'devices' => json_encode($familylog), |
207
|
|
|
); |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.