Completed
Push — Projets ( 6c7eb1...098438 )
by Hugo
02:57
created

ProjetsController::soloUpdateAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
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
    }
36
37
    public function updateAction($id = null)
38
    {
39
        if ($id = null) {
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...
40
            //Retrouve l'id du dernier projet créer (En theorie celui qui vient d'être créé)
41
            $projet = Projet::findFirst(array(
42
                "order" => "id DESC"
43
            ));
44
            $idproj = $projet->getId();
45
            $this->response->redirect("Projets/read/$idproj");
46
        }
47
    }
48
49
    public function soloUpdateAction()
0 ignored issues
show
Coding Style introduced by
soloUpdateAction uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
50
    {
51
        //Créer la fonction variable 'set' en fonction du name en POST
52
        $func = 'set' . ucfirst($_POST['name']);
53
        $projet = Projet::findFirst($_POST['pk']);
54
        $projet->$func($_POST['value']);
55
        $projet->save();
56
57
        /*$value = $_POST['value'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
58
        $pk = $_POST['pk'];
59
        $name = $_POST['name'];
60
        $this->modelsManager->createQuery("UPDATE Projet SET $name = '$value' WHERE id = $pk")->execute();*/
61
    }
62
63
    public function readAction($id = null)
64
    {
65
        $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...
66
        $projet = Projet::findFirst($id);
67
        $usecases = Usecase::find("idProjet = $id");
68
        $messages = Message::find("idProjet = $id");
69
        $colorTexte = "black";
70
71
        $color = $projet->getDominantColor();
72
73
        //Si jamais la couleur retournée est noire, alors change sa couleur en gris clair
74
        if ($color["r"] == 0 && $color["g"] == 0 && $color["b"] == 0) {
75
            $color["r"] = 240;
76
            $color["g"] = 240;
77
            $color["b"] = 240;
78
            //Sinon si la couleur est trop sombre change l'écriture en blanc pour qu'elle sois visible
79
        } elseif ($color["r"] < 120 || $color["g"] < 120 || $color["b"] < 120) {
80
            $colorTexte = "white";
81
            $color["r"] += 70;
82
            $color["g"] += 70;
83
            $color["b"] += 70;
84
        }
85
86
        $avancementReel = $this->avancementReel($usecases);
87
88
        //Passage des différentes variables
89
        $this->view->setVar("colorTexte", $colorTexte);
90
        $this->view->setVar("color", $color);
91
        $this->view->setVar("projet", $projet);
92
        $this->view->setVar("messages", $messages);
93
        $this->view->setVar("usecases", $usecases);
94
        $this->view->setVar("avancement", $avancementReel);
95
96
        //Création de la progressbar
97
        $progress = $this->jquery->bootstrap()->htmlProgressbar("progress", "info", $avancementReel);
98
        $progress->showcaption(true);
99
        $this->jquery->get("Projets/resume/$id", "#contentProjet");
100
        //Creation des évenements onClick et des éléments sur le menu
101
        $this->jquery->getOnClick("#menu1", "Projets/resume/$id", "#contentProjet");
102
        $this->jquery->getOnClick("#menu2", "Projets/contributors/$id", "#contentProjet");
103
        $this->jquery->getOnClick("#menu3", "Projets/usecases/$id", "#contentProjet");
104
        $this->jquery->getOnClick("#menu5", "Projets/messages/$id", "#contentProjet");
105
106
        $this->jquery->exec("$('#nom').editable()", true);
107
108
        //Compilation de Jquery dans la vue
109
        $this->jquery->compile($this->view);
110
    }
111
112
    public function messagesAction($id = null)
113
    {
114
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
115
        $messages = Message::find("idProjet = $id");
116
        $this->jquery->postFormOnClick("#submitMsg", "Messages/update", "newMsgForm", null, array("jsCallback" => $this->jquery->getDeferred("Projets/messages/$id", "#contentProjet")));
117
        $this->jquery->compile($this->view);
118
119
        $this->view->setVar("msg", $messages);
120
        $this->view->setVar("idProj", $id);
121
122
        $this->view->render("projets", "messages");
123
    }
124
125
    public function resumeAction($id = null)
126
    {
127
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
128
        $projet = Projet::findFirst($id);
129
        $usecases = Usecase::find("idProjet = $id");
130
        $messages = Message::find("idProjet = $id");
131
132
        $this->view->setVar("projet", $projet);
133
        $this->view->setVar("messages", $messages);
134
        $this->view->setVar("usecases", $usecases);
135
    }
136
137
    public function usecasesAction($id = null)
138
    {
139
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
140
        $taches = Tache::find();
141
        $usecases = Usecase::find(array(
142
            "idProjet = '$id'",
143
            "order" => "poids DESC"
144
        ));
145
146
        $this->view->setVar("usecases", $usecases);
147
        $this->view->setVar("taches", $taches);
148
    }
149
150
    public function contributorsAction($id = null)
151
    {
152
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
153
        $contributor = [];
154
155
        $usecases = Usecase::find("idProjet = $id");
156
157
        foreach ($usecases as $uc) {
158
            $contributor[] = $uc->getUser();
159
        }
160
161
        $contributor = array_unique($contributor, SORT_REGULAR);
162
163
        $this->view->setVar("contributors", $contributor);
164
        $this->view->setVar("usecases", $usecases);
165
166
167
    }
168
169
    //Calcule le taux d'avancement total d'un projet
170
    public function avancementReel($usecases)
171
    {
172
        //Calcul le taux de finition du projet en fonction du nombre d'usecases total et du taux d'avancement sur chaque usecases.
173
        $countUsecases = count($usecases);
174
        $totalAvancementFini = $countUsecases * 100;
175
        $totalAvancementReel = 0;
176
177
        foreach ($usecases as $u) {
178
            $totalAvancementReel = $totalAvancementReel + $u->getAvancement();
179
        }
180
181
        $avancementReel = ($totalAvancementReel / $totalAvancementFini) * 100;
182
        return number_format($avancementReel, 1);
183
    }
184
185
}
186