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

TachesController::soloUpdateAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 9.3143
cc 2
eloc 14
nc 2
nop 0
1
<?php
2
3
class TachesController 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...
4
{
5
6
    protected $model;
7
    protected $title;
8
    protected $controller;
9
10
    public function initialize()
11
    {
12
        $this->model = "Tache";
13
        $this->title = "Taches";
14
        $this->controller = "Taches";
15
    }
16
17
    public function updateAction($id = null)
18
    {
19
        parent::updateAction();
20
        $this->response->redirect("Projets/read/$id/2");
21
22
    }
23
24
    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...
25
    {
26
27
        $name = $this->request->getPost('name', 'string');
28
        //Cr�er la fonction variable 'set' en fonction du name en POST
29
        $func = 'set' . ucfirst($name);
30
        $projet = call_user_func($this->model . '::findFirst', $_POST['pk']);
31
        $projet->$func($_POST['value']);
32
        $projet->save();
33
34
        //Update l'avancement de la usecase lors de changements sur une usecase
35
        $avancementTotal = 0;
36
        $usecase = Usecase::findFirst("code='" . $projet->getCodeUseCase() . "'");
37
        $taches = Tache::find("codeUseCase LIKE '" . $projet->getCodeUseCase() . "'");
38
        foreach ($taches as $tache) {
39
            $avancementTotal += $tache->getAvancement();
40
        }
41
        $avancementTotal = $avancementTotal / count($taches);
42
        $usecase->setAvancement($avancementTotal);
43
        $usecase->save();
44
    }
45
}
46
47