Completed
Branch Projets (f4ac88)
by Hugo
02:59
created

ProjetsController::usecasesAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4286
cc 1
eloc 8
nc 1
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
25
    public function readAction($id = null)
26
    {
27
        $projet = Projet::findFirst($id);
28
        $usecases = Usecase::find("idProjet = $id");
29
        $messages = Message::find("idProjet = $id");
30
        $colorTexte = "black";
31
32
        $color = $projet->getDominantColor();
33
        //Si jamais la couleur retournée est noire, alors change sa couleur en gris clair
34
        if ($color["r"] == 0 && $color["g"] == 0 && $color["b"] == 0) {
35
            $color["r"] = 240;
36
            $color["g"] = 240;
37
            $color["b"] = 240;
38
            //Sinon si la couleur est trop sombre change l'écriture en blanc pour qu'elle sois visible
39
        } elseif ($color["r"] < 120 || $color["g"] < 120 || $color["b"] < 120) {
40
            $colorTexte = "white";
41
            $color["r"] += 70;
42
            $color["g"] += 70;
43
            $color["b"] += 70;
44
        }
45
46
        $avancementReel = $this->avancementReel($usecases);
47
48
49
        $this->jquery->postFormOnClick("#submitMsg", "Messages/update", "#newMsgForm");
50
51
        //Passage des différentes variables
52
        $this->view->setVar("colorTexte", $colorTexte);
53
        $this->view->setVar("color", $color);
54
        $this->view->setVar("projet", $projet);
55
        $this->view->setVar("messages", $messages);
56
        $this->view->setVar("usecases", $usecases);
57
        $this->view->setVar("avancement", $avancementReel);
58
59
        //Création de la progressbar
60
        $progress = $this->jquery->bootstrap()->htmlProgressbar("progress", "info", $avancementReel);
61
        $progress->showcaption(true);
62
        $this->jquery->get("Projets/resume/$id", "#contentProjet");
63
        //Creation des évenements onClick et des éléments sur le menu
64
        $this->jquery->getOnClick("#menu1", "Projets/resume/$id", "#contentProjet");
65
        $this->jquery->getOnClick("#menu2", "Projets/contributors/$id", "#contentProjet");
66
        $this->jquery->getOnClick("#menu3", "Projets/usecases/$id", "#contentProjet");
67
        $this->jquery->getOnClick("#menu5", "Projets/messages/$id", "#contentProjet");
68
69
        //Compilation de Jquery dans la vue
70
        $this->jquery->compile($this->view);
71
    }
72
73
    public function messagesAction($id = null)
74
    {
75
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
76
        $messages = Message::find("idProjet = $id");
77
        $this->jquery->postFormOnClick("#submitMsg", "Messages/update", "newMsgForm", null, array("jsCallback" => $this->jquery->getDeferred("Projets/messages/$id", "#contentProjet")));
78
        $this->jquery->compile($this->view);
79
80
        $this->view->setVar("msg", $messages);
81
        $this->view->setVar("idProj", $id);
82
83
        $this->view->render("projets", "messages");
84
    }
85
86
    public function resumeAction($id = null)
87
    {
88
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
89
        $projet = Projet::findFirst($id);
90
        $usecases = Usecase::find("idProjet = $id");
91
        $messages = Message::find("idProjet = $id");
92
93
        $this->view->setVar("projet", $projet);
94
        $this->view->setVar("messages", $messages);
95
        $this->view->setVar("usecases", $usecases);
96
    }
97
98
    public function usecasesAction($id = null)
99
    {
100
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
101
        $taches = Tache::find();
102
        $usecases = Usecase::find(array(
103
            "idProjet = '$id'",
104
            "order" => "poids DESC"
105
        ));
106
107
        $this->view->setVar("usecases", $usecases);
108
        $this->view->setVar("taches", $taches);
109
    }
110
111
    public function contributorsAction($id = null)
112
    {
113
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
114
        $contributor = [];
115
116
        $usecases = Usecase::find("idProjet = $id");
117
118
        foreach ($usecases as $uc) {
119
            $contributor[] = $uc->getUser();
120
        }
121
122
        $contributor = array_unique($contributor, SORT_REGULAR);
123
124
        $this->view->setVar("contributors", $contributor);
125
        $this->view->setVar("usecases", $usecases);
126
127
128
    }
129
130
    //Calcule le taux d'avancement total d'un projet
131
    public function avancementReel($usecases)
132
    {
133
        //Calcul le taux de finition du projet en fonction du nombre d'usecases total et du taux d'avancement sur chaque usecases.
134
        $countUsecases = count($usecases);
135
        $totalAvancementFini = $countUsecases * 100;
136
        $totalAvancementReel = 0;
137
138
        foreach ($usecases as $u) {
139
            $totalAvancementReel = $totalAvancementReel + $u->getAvancement();
140
        }
141
142
        $avancementReel = ($totalAvancementReel / $totalAvancementFini) * 100;
143
        return number_format($avancementReel, 1);
144
    }
145
146
}
147