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 0.1.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
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* class DefaultController. |
24
|
|
|
* |
25
|
|
|
* @category Controller |
26
|
|
|
* |
27
|
|
|
* @Route("/") |
28
|
|
|
*/ |
29
|
|
|
class DefaultController extends Controller |
30
|
|
|
{ |
31
|
|
|
private $entities; |
32
|
|
|
|
33
|
|
|
public function __construct() { |
34
|
|
|
// Tableau des entitées |
35
|
|
|
$this->entities = array( |
36
|
|
|
'AppBundle:User', |
37
|
|
|
'AppBundle:Company', |
38
|
|
|
'AppBundle:Settings', |
39
|
|
|
'AppBundle:FamilyLog', |
40
|
|
|
'AppBundle:SubFamilyLog', |
41
|
|
|
'AppBundle:ZoneStorage', |
42
|
|
|
'AppBundle:UnitStorage', |
43
|
|
|
'AppBundle:Tva', |
44
|
|
|
'AppBundle:Supplier', |
45
|
|
|
'AppBundle:Article', |
46
|
|
|
'AppBundle:Settings'); |
47
|
|
|
|
48
|
|
|
} |
49
|
|
|
/** |
50
|
|
|
* @Route("/", name="_home") |
51
|
|
|
* @Method("GET") |
52
|
|
|
* @Template() |
53
|
|
|
*/ |
54
|
|
|
public function indexAction() |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Test d'installation |
58
|
|
|
*/ |
59
|
|
|
$url = $this->testEntities(); |
60
|
|
|
if (empty($url)) { |
61
|
|
|
$url = $this->render('default/index.html.twig'); |
62
|
|
|
} else { |
63
|
|
|
$url = $this->redirect($this->generateUrl($url)); |
64
|
|
|
} |
65
|
|
|
// replace this example code with whatever you need |
66
|
|
|
return $url; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Test des entités |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
private function testEntities() |
75
|
|
|
{ |
76
|
|
|
$url = null; |
77
|
|
|
$etm = $this->getDoctrine()->getManager(); |
78
|
|
|
// vérifie que les Entitées ne sont pas vides |
79
|
|
|
$nbEntities = count($this->entities); |
80
|
|
|
|
81
|
|
|
for ($index = 0; $index < $nbEntities; $index++) { |
82
|
|
|
$entity = $etm->getRepository( |
83
|
|
|
$this->entities[$index] |
84
|
|
|
); |
85
|
|
|
$entityData = $entity->find(1); |
86
|
|
|
|
87
|
|
|
if (empty($entityData)) { |
88
|
|
|
$message = 'gestock.install.none'; |
89
|
|
|
// $url = 'gs_install'; break; |
|
|
|
|
90
|
|
|
} elseif ($index === 10 && $entityData->getFirstInventory() === null) { |
91
|
|
|
$message = 'gestock.settings.application.first_inventory.none'; |
92
|
|
|
$url = 'gestock_inventory_prepare'; break; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
if (isset($message)) { |
96
|
|
|
$this->container->get('session')->getFlashBag()->add('warning', $message); |
97
|
|
|
} |
98
|
|
|
return $url; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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.