Completed
Push — Projets ( 098438...291da2 )
by Hugo
04:19
created

ProjetsController::resumeAction()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 37
Code Lines 20

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 37
rs 8.8571
cc 2
eloc 20
nc 2
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
        //Retrouve l'id du dernier projet créer (En theorie celui qui vient d'être créé)
38
        $projet = Projet::findFirst(array(
39
            "order" => "id DESC"
40
        ));
41
        $idproj = $projet->getId();
42
        $this->response->redirect("Projets/read/$idproj");
43
    }
44
45
    public function readAction($id = null)
46
    {
47
        $url = new Url();
0 ignored issues
show
Unused Code introduced by
$url 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...
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
        //Xeditable
89
        $this->jquery->exec("$('#nom').editable()", true);
90
        $this->jquery->exec("$('#image').editable()", true);
91
92
        //Compilation de Jquery dans la vue
93
        $this->jquery->compile($this->view);
94
    }
95
96
    public function messagesAction($id = null)
97
    {
98
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
99
        $messages = Message::find("idProjet = $id");
100
        $this->jquery->postFormOnClick("#submitMsg", "Messages/update", "newMsgForm", null, array("jsCallback" => $this->jquery->getDeferred("Projets/messages/$id", "#contentProjet")));
101
        $this->jquery->compile($this->view);
102
103
        $this->view->setVar("msg", $messages);
104
        $this->view->setVar("idProj", $id);
105
106
        $this->view->render("projets", "messages");
107
    }
108
109
    public function resumeAction($id = null)
110
    {
111
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
112
        $projet = Projet::findFirst($id);
113
        $usecases = Usecase::find("idProjet = $id");
114
        $messages = Message::find("idProjet = $id");
115
116
117
        $this->view->setVar("projet", $projet);
118
        $this->view->setVar("messages", $messages);
119
        $this->view->setVar("usecases", $usecases);
120
121
        $this->jquery->exec("$('#description').editable()", true);
122
        $this->jquery->exec("$('#dateLancement').editable()", true);
123
        $this->jquery->exec("$('#dateFinPrevue').editable()", true);
124
125
        $client = '[';
126
127
        foreach (User::find() as $c) {
128
            $client .= '{value: ' . $c->getId() . ', text: "' . $c->getIdentite() . '"}';
129
130
        }
131
132
        $client .= ']';
133
134
        $this->jquery->exec("$('#idClient').editable({
135
                                type: 'select',
136
                                pk: $id,
137
                                title: 'Enter username',
138
                                source: $client
139
140
        })", true);
141
142
        //Compilation de Jquery dans la vue
143
        $this->jquery->compile($this->view);
144
145
    }
146
147
148
    public function usecasesAction($id = null)
149
    {
150
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
151
        $taches = Tache::find();
152
        $usecases = Usecase::find(array(
153
            "idProjet = '$id'",
154
            "order" => "poids DESC"
155
        ));
156
157
        $this->view->setVar("usecases", $usecases);
158
        $this->view->setVar("taches", $taches);
159
    }
160
161
    public function contributorsAction($id = null)
162
    {
163
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
164
        $contributor = [];
165
166
        $usecases = Usecase::find("idProjet = $id");
167
168
        foreach ($usecases as $uc) {
169
            $contributor[] = $uc->getUser();
170
        }
171
172
        $contributor = array_unique($contributor, SORT_REGULAR);
173
174
        $this->view->setVar("contributors", $contributor);
175
        $this->view->setVar("usecases", $usecases);
176
177
178
    }
179
180
    //Calcule le taux d'avancement total d'un projet
181
    public function avancementReel($usecases)
182
    {
183
        //Calcul le taux de finition du projet en fonction du nombre d'usecases total et du taux d'avancement sur chaque usecases.
184
        $countUsecases = count($usecases);
185
        $totalAvancementFini = $countUsecases * 100;
186
        $totalAvancementReel = 0;
187
188
        foreach ($usecases as $u) {
189
            $totalAvancementReel = $totalAvancementReel + $u->getAvancement();
190
        }
191
192
        $avancementReel = ($totalAvancementReel / $totalAvancementFini) * 100;
193
        return number_format($avancementReel, 1);
194
195
    }
196
197
}
198