Completed
Push — sf2.7 ( fa1c69...713b85 )
by Laurent
03:29
created

DefaultController::choseTablet2Action()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
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();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
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;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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();
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
121
        $etm = $this->getDoctrine()->getManager();
122
        if ($request->isXmlHttpRequest()) {
123
            $famLogId = '';
0 ignored issues
show
Unused Code introduced by
$famLogId is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
124
            $subFamId = '';
0 ignored issues
show
Unused Code introduced by
$subFamId is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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();
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
172
        $etm = $this->getDoctrine()->getManager();
173
        if ($request->isXmlHttpRequest()) {
174
            $id = '';
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
175
            $id = $request->get('id');
176
            if ($id != '') {
177
                $supplier = $etm
178
                    ->getRepository('AppBundle:Supplier')
179
                    ->find($id);
180
                $familyLog['familylog'] = $supplier->getFamilyLog()->getId();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$familyLog was never initialized. Although not strictly required by PHP, it is generally a good practice to add $familyLog = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
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