Completed
Push — Projets ( ff735a...d3b7e5 )
by Hugo
02:25
created

ProjetsController::resumeAction()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 43
Code Lines 24

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 43
rs 8.8571
cc 3
eloc 24
nc 3
nop 1
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 = $projet->getDominantColor();
54
55
        //Si jamais la couleur retournée est noire, alors change sa couleur en gris clair
56
        if ($color["r"] == 0 && $color["g"] == 0 && $color["b"] == 0) {
57
            $color["r"] = 240;
58
            $color["g"] = 240;
59
            $color["b"] = 240;
60
            //Sinon si la couleur est trop sombre change l'écriture en blanc pour qu'elle sois visible
61
        } elseif ($color["r"] < 120 || $color["g"] < 120 || $color["b"] < 120) {
62
            $colorTexte = "white";
63
            $color["r"] += 70;
64
            $color["g"] += 70;
65
            $color["b"] += 70;
66
        }
67
68
        $avancementReel = $this->avancementReel($usecases);
69
70
        //Passage des différentes variables
71
        $this->view->setVar("colorTexte", $colorTexte);
72
        $this->view->setVar("color", $color);
73
        $this->view->setVar("projet", $projet);
74
        $this->view->setVar("messages", $messages);
75
        $this->view->setVar("usecases", $usecases);
76
        $this->view->setVar("avancement", $avancementReel);
77
78
        //Création de la progressbar
79
        $progress = $this->jquery->bootstrap()->htmlProgressbar("progress", "info", $avancementReel);
80
        $progress->showcaption(true);
81
        $this->jquery->get("Projets/resume/$id", "#contentProjet");
82
        //Creation des évenements onClick et des éléments sur le menu
83
        $this->jquery->getOnClick("#menu1", "Projets/resume/$id", "#contentProjet");
84
        $this->jquery->getOnClick("#menu2", "Projets/contributors/$id", "#contentProjet");
85
        $this->jquery->getOnClick("#menu3", "Projets/usecases/$id", "#contentProjet");
86
        $this->jquery->getOnClick("#menu5", "Projets/messages/$id", "#contentProjet");
87
88
        if($redirect != null){
89
            switch($redirect){
90
                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...
91
                    $this->jquery->get("Projets/contributors/$id", "#contentProjet");
92
                    break;
93
                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...
94
                    $this->jquery->get("Projets/usecases/$id", "#contentProjet");
95
                    break;
96
                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...
97
                    $this->jquery->get("Projets/messages/$id", "#contentProjet");
98
                    break;
99
            }
100
        }
101
102
103
        //Xeditable
104
        $this->jquery->exec("$('#nom').editable()", true);
105
        $this->jquery->exec("$('#image').editable()", true);
106
107
        //Compilation de Jquery dans la vue
108
        $this->jquery->compile($this->view);
109
    }
110
111
    public function messagesAction($id = null)
112
    {
113
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
114
        $messages = Message::find("idProjet = $id");
115
        $this->jquery->postFormOnClick("#submitMsg", "Messages/update", "newMsgForm", null, array("jsCallback" => $this->jquery->getDeferred("Projets/messages/$id", "#contentProjet")));
116
        $this->jquery->compile($this->view);
117
118
        $this->view->setVar("msg", $messages);
119
        $this->view->setVar("idProj", $id);
120
121
        $this->view->render("projets", "messages");
122
    }
123
124
    public function resumeAction($id = null)
125
    {
126
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
127
        $projet = Projet::findFirst($id);
128
        $usecases = Usecase::find("idProjet = $id");
129
        $messages = Message::find("idProjet = $id");
130
131
        //Créer un array en javascript contenant la liste des utilisateurs pour la liste des clients sur Xeditable
132
        $client = '[';
133
        $i = 0;
134
        foreach (User::find() as $c) {
135
            $i += 1;
136
            if ($id != 1) {
137
                $client .= ',';
138
            }
139
            $client .= '{value: ' . $c->getId() . ', text:"' . $c->getIdentite() . '"}';
140
        }
141
142
        $client .= ']';
143
144
        //Select Xeditable
145
        $this->jquery->exec("$('#idClient').editable({
146
                                type: 'select',
147
                                pk: $id,
148
                                title: 'Enter username',
149
                                source: $client
150
151
        })", true);
152
153
        //Xeditable
154
        $this->jquery->exec("$('#description').editable()", true);
155
        $this->jquery->exec("$('#dateLancement').editable()", true);
156
        $this->jquery->exec("$('#dateFinPrevue').editable()", true);
157
158
        //Passage des variables à la vue
159
        $this->view->setVar("projet", $projet);
160
        $this->view->setVar("messages", $messages);
161
        $this->view->setVar("usecases", $usecases);
162
163
        //Compilation de Jquery dans la vue
164
        $this->jquery->compile($this->view);
165
166
    }
167
168
    public function usecasesAction($id = null)
169
    {
170
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
171
        $taches = Tache::find();
172
        $usecases = Usecase::find(array(
173
            "idProjet = '$id'",
174
            "order" => "poids DESC"
175
        ));
176
177
        $this->view->setVar("usecases", $usecases);
178
        $this->view->setVar("taches", $taches);
179
180
        $dialog = $this->jquery->bootstrap()->htmlModal("modal", "Ajouter un nouveau projet", "test");
181
        $buttonFrm = $this->jquery->bootstrap()->htmlButton("btFrm", "Nouveau");
182
        $dialog->addCancelButton();
183
        $users = User::find();
184
        $dialog->renderContent($this->view, "usecases", "frm", array("users" => $users,"id"=> $id));
185
186
        $buttonFrm->onClick($dialog->jsShow());
187
188
        $this->jquery->compile($this->view);
189
190
        //$this->jquery->exec("$('#poids').editable()", true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
191
        $this->jquery->compile($this->view);
192
    }
193
194
    public function contributorsAction($id = null)
195
    {
196
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
197
        $contributor = [];
198
199
        $usecases = Usecase::find("idProjet = $id");
200
201
        foreach ($usecases as $uc) {
202
            $contributor[] = $uc->getUser();
203
        }
204
205
        $contributor = array_unique($contributor, SORT_REGULAR);
206
207
        $this->view->setVar("contributors", $contributor);
208
        $this->view->setVar("usecases", $usecases);;
209
210
    }
211
212
    //Calcule le taux d'avancement total d'un projet
213
    public function avancementReel($usecases)
214
    {
215
        //Calcul le taux de finition du projet en fonction du nombre d'usecases total et du taux d'avancement sur chaque usecases.
216
        $countUsecases = count($usecases);
217
        $totalAvancementFini = $countUsecases * 100;
218
        $totalAvancementReel = 0;
219
220
        foreach ($usecases as $u) {
221
            $totalAvancementReel = $totalAvancementReel + $u->getAvancement();
222
        }
223
224
        $avancementReel = ($totalAvancementReel / $totalAvancementFini) * 100;
225
        return number_format($avancementReel, 1);
226
    }
227
228
}
229