Completed
Push — Projets ( a98de7...4109c3 )
by Hugo
02:43
created

ProjetsController::usecasesAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 58
Code Lines 35

Duplication

Lines 7
Ratio 12.07 %
Metric Value
dl 7
loc 58
rs 9.6391
cc 3
eloc 35
nc 3
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
use Phalcon\Mvc\View;
3
use Phalcon\Mvc\Url;
4
5
class ProjetsController extends \ControllerBase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
8
    protected $model;
9
    protected $title;
10
    protected $controller;
11
12
    public function initialize()
13
    {
14
        $this->model = "Projet";
15
        $this->title = "Projets";
16
        $this->controller = "Projets";
17
    }
18
19
    public function indexAction($message = null)
20
    {
21
        $projets = Projet::find();
22
        $this->view->setVar("projets", $projets);
23
24
        $dialog = $this->jquery->bootstrap()->htmlModal("modal", "Ajouter un nouveau projet", "test");
25
        $buttonFrm = $this->jquery->bootstrap()->htmlButton("btFrm", "Nouveau");
26
        $dialog->addCancelButton();
27
        $clients = User::find();
28
        $dialog->renderContent($this->view, "projets", "frm", array("clients" => $clients));
29
30
        $buttonFrm->onClick($dialog->jsShow());
31
32
        $this->jquery->compile($this->view);
33
    }
34
35
    public function updateAction()
36
    {
37
        parent::updateAction();
38
        //Retrouve l'id du dernier projet créer (En theorie celui qui vient d'être créé)
39
        $projet = Projet::findFirst(array(
40
            "order" => "id DESC"
41
        ));
42
        $idproj = $projet->getId();
43
        $this->response->redirect("Projets/read/$idproj");
44
    }
45
46
    public function readAction($id = null, $redirect = null)
47
    {
48
        $projet = Projet::findFirst($id);
49
        $usecases = Usecase::find("idProjet = $id");
50
        $messages = Message::find("idProjet = $id");
51
        $colorTexte = "black";
52
53
        $color = array();
54
55
        $color["r"] = 245;
56
        $color["g"] = 245;
57
        $color["b"] = 247;
58
59
        $avancementReel = $this->avancementReel($usecases);
60
61
        //Passage des différentes variables
62
        $this->view->setVar("colorTexte", $colorTexte);
63
        $this->view->setVar("color", $color);
64
        $this->view->setVar("projet", $projet);
65
        $this->view->setVar("messages", $messages);
66
        $this->view->setVar("usecases", $usecases);
67
        $this->view->setVar("avancement", $avancementReel);
68
69
        //Création de la progressbar
70
        $progress = $this->jquery->bootstrap()->htmlProgressbar("progress", "info", $avancementReel);
71
        $progress->showcaption(true);
72
        $this->jquery->get("Projets/resume/$id", "#contentProjet");
73
        //Creation des évenements onClick et des éléments sur le menu
74
        $this->jquery->getOnClick("#menu1", "Projets/resume/$id", "#contentProjet");
75
        $this->jquery->getOnClick("#menu2", "Projets/contributors/$id", "#contentProjet");
76
        $this->jquery->getOnClick("#menu3", "Projets/usecases/$id", "#contentProjet");
77
        $this->jquery->getOnClick("#menu5", "Projets/messages/$id", "#contentProjet");
78
79
        if ($redirect != null) {
80
            switch ($redirect) {
81
                case(1):
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
82
                    $this->jquery->get("Projets/contributors/$id", "#contentProjet");
83
                    break;
84
                case(2):
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
85
                    $this->jquery->get("Projets/usecases/$id", "#contentProjet");
86
                    break;
87
                case(3):
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
88
                    $this->jquery->get("Projets/messages/$id", "#contentProjet");
89
                    break;
90
            }
91
        }
92
93
94
        //Xeditable
95
        $this->jquery->exec("$('#nom').editable()", true);
96
        $this->jquery->exec("$('#image').editable()", true);
97
98
        //Compilation de Jquery dans la vue
99
        $this->jquery->compile($this->view);
100
    }
101
102
    public function messagesAction($id = null)
103
    {
104
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
105
        $messages = Message::find("idProjet = $id");
106
        $this->jquery->postFormOnClick("#submitMsg", "Messages/update", "newMsgForm", null, array("jsCallback" => $this->jquery->getDeferred("Projets/messages/$id", "#contentProjet")));
107
        $this->jquery->compile($this->view);
108
109
        $this->view->setVar("msg", $messages);
110
        $this->view->setVar("idProj", $id);
111
112
        $this->view->render("projets", "messages");
113
    }
114
115
    public function resumeAction($id = null)
116
    {
117
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
118
        $projet = Projet::findFirst($id);
119
        $usecases = Usecase::find("idProjet = $id");
120
        $messages = Message::find("idProjet = $id");
121
122
        //Créer un array en javascript contenant la liste des utilisateurs pour la liste des clients sur Xeditable
123
        $client = '[';
124
        $i = 0;
125 View Code Duplication
        foreach (User::find() as $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
126
            $i += 1;
127
            if ($id != 1) {
128
                $client .= ',';
129
            }
130
            $client .= '{value: ' . $c->getId() . ', text:"' . $c->getIdentite() . '"}';
131
        }
132
133
        $client .= ']';
134
135
        //Select Xeditable
136
        $this->jquery->exec("$('#idClient').editable({
137
                                type: 'select',
138
                                pk: $id,
139
                                title: 'Enter username',
140
                                source: $client
141
        })", true);
142
143
        //Xeditable
144
145
        $this->jquery->exec("$('#description').editable()", true);
146
        $this->jquery->exec("$('#dateLancement').editable()", true);
147
        $this->jquery->exec("$('#dateFinPrevue').editable()", true);
148
149
        //Passage des variables à la vue
150
        $this->view->setVar("projet", $projet);
151
        $this->view->setVar("messages", $messages);
152
        $this->view->setVar("usecases", $usecases);
153
154
        //Compilation de Jquery dans la vue
155
        $this->jquery->compile($this->view);
156
157
    }
158
159
    public function usecasesAction($id = null)
160
    {
161
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
162
        $taches = Tache::find();
163
        $usecases = Usecase::find(array(
164
            "idProjet = '$id'",
165
            "order" => "poids DESC"
166
        ));
167
168
        $this->view->setVar("usecases", $usecases);
169
        $this->view->setVar("taches", $taches);
170
171
        //Création du modal pour la création d'une UseCase.
172
        $dialog = $this->jquery->bootstrap()->htmlModal("modal", "Ajouter une Usecase", "test");
173
        $buttonFrm = $this->jquery->bootstrap()->htmlButton("btFrm", "Nouvelle UseCase");
174
        $dialog->addCancelButton();
175
        $users = User::find();
176
        $dialog->renderContent($this->view, "usecases", "frm", array("users" => $users, "id" => $id));
177
178
        $buttonFrm->onClick($dialog->jsShow());
179
180
        //Création du modal pour les taches.
181
        $dialogTaches = $this->jquery->bootstrap()->htmlModal("modalTache", "Ajouter une Tache", "test");
182
        $buttonFrmEdit = $this->jquery->bootstrap()->htmlButton("btFrmTache", "Nouvelle Tache");
183
        $usecases = Usecase::find();
184
        $dialogTaches->addCancelButton();
185
        $dialogTaches->renderContent($this->view, "taches", "frm", array("usecases" => $usecases, "id" => $id));
186
        $buttonFrmEdit->onClick($dialogTaches->jsShow());
187
188
189
        //Créer un array en javascript contenant la liste des utilisateurs pour la liste des développeurs sur Xeditable
190
        $dev = '[';
191
        $i = 0;
192 View Code Duplication
        foreach (User::find() as $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
193
            $i += 1;
194
            if ($id != 1) {
195
                $dev .= ',';
196
            }
197
            $dev .= '{value: ' . $c->getId() . ', text:"' . $c->getIdentite() . '"}';
198
        }
199
200
        $dev .= ']';
201
202
        //Select Xeditable
203
        $this->jquery->exec("$('.idDev').editable({
204
                                type: 'select',
205
                                title: 'Enter username',
206
                                source: $dev
207
        })", true);
208
209
210
        // Xeditable
211
        $this->jquery->exec("$('.nom').editable()", true);
212
        $this->jquery->exec("$('.poids').editable()", true);
213
        $this->jquery->exec("$('.avancement').editable()", true);
214
215
        $this->jquery->compile($this->view);
216
    }
217
218
    public function contributorsAction($id = null)
219
    {
220
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
221
        $contributor = [];
222
223
        $usecases = Usecase::find("idProjet = $id");
224
225
        foreach ($usecases as $uc) {
226
            $contributor[] = $uc->getUser();
227
        }
228
229
        $contributor = array_unique($contributor, SORT_REGULAR);
230
231
        $this->view->setVar("contributors", $contributor);
232
        $this->view->setVar("usecases", $usecases);;
233
234
    }
235
236
    //Calcule le taux d'avancement total d'un projet
237
    public function avancementReel($usecases)
238
    {
239
        //Calcul le taux de finition du projet en fonction du nombre d'usecases total et du taux d'avancement sur chaque usecases.
240
241
        $taches = Tache::find();
0 ignored issues
show
Unused Code introduced by
$taches 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...
242
        $countUsecases = count($usecases);
243
        $totalAvancementFini = $countUsecases * 100;
244
        $totalAvancementReel = 0;
245
246
        foreach ($usecases as $u) {
247
            $taches = Tache::find("codeUseCase = '" . $u->getCode() . "'");
0 ignored issues
show
Unused Code introduced by
$taches 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...
248
249
            $totalAvancementReel = $totalAvancementReel + $u->getAvancement();
250
        }
251
252
        $avancementReel = ($totalAvancementReel / $totalAvancementFini) * 100;
253
        return number_format($avancementReel, 1);
254
255
256
    }
257
258
}
259