FragorController::indexActionGet()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
nc 4
nop 0
dl 0
loc 36
c 0
b 0
f 0
cc 3
rs 9.536
1
<?php
2
3
namespace KW\Inlagg;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class FragorController implements ContainerInjectableInterface
9
{
10
    use ContainerInjectableTrait;
11
12
    public function indexActionGet()
13
    {
14
        $fragehamtaren = new Fragehamtaren($this->di);
15
        $sort   = $this->di->get("request")->getGet("sortfr");
16
        $res    = $fragehamtaren->allaInlagg($sort);
17
18
        $taggar     = [];
19
        $antalsvar  = [];
20
21
        foreach ($res as $rad) {
22
            $tags = $fragehamtaren->hamtaTaggar($rad->id);
23
            array_push($taggar, $tags);
24
            $nrsvar = $fragehamtaren->raknaSvar($rad->id);
25
            array_push($antalsvar, $nrsvar);
26
        }
27
28
        $alltags = $fragehamtaren->allaTaggar();
29
30
        $page = $this->di->get("page");
31
        $page->add("anax/v2/fragor/allafragor", [
32
            "res"       => $res,
33
            "taggar"    => $taggar,
34
            "alltags"   => $alltags,
35
            "antalsvar" => $antalsvar
36
            ]);
37
38
        if ($this->di->session->get("anvandarid")!=null) {
0 ignored issues
show
Bug introduced by
Accessing session on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39
            $page->add("anax/v2/fragor/nyfraga", [
40
                "res"       => $res,
41
                "taggar"    => $taggar,
42
                "alltags"   => $alltags
43
            ]);
44
        }
45
46
        return $page->render([
47
            "title"=>"Frågor",
48
        ]);
49
    }
50
51
    public function taggActionGet($tagg)
52
    {
53
        $fragehamtaren = new \KW\Inlagg\Fragehamtaren($this->di);
54
        $sort = $this->di->get("request")->getGet("sortfr");
55
56
        $res = $fragehamtaren->fragorMedTaggen($tagg, $sort);
57
        $taggar     = [];
58
        $antalsvar  = [];
59
60
        foreach ($res as $rad) {
61
            $tags = $fragehamtaren->hamtaTaggar($rad->id);
62
            array_push($taggar, $tags);
63
            $nrsvar = $fragehamtaren->raknaSvar($rad->id);
64
            array_push($antalsvar, $nrsvar);
65
        }
66
67
        $alltags = $fragehamtaren->allaTaggar();
68
        $page = $this->di->get("page");
69
        $page->add("anax/v2/fragor/allafragor", [
70
            "res"       => $res,
71
            "taggar"    => $taggar,
72
            "alltags"   => $alltags,
73
            "antalsvar" => $antalsvar,
74
            "tagg"      => $tagg
75
            ]);
76
77
        if ($this->di->session->get("anvandarid")!=null) {
0 ignored issues
show
Bug introduced by
Accessing session on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
78
            $page->add("anax/v2/fragor/nyfraga", [
79
                "res"       => $res,
80
                "taggar"    => $taggar,
81
                "alltags"   => $alltags
82
            ]);
83
        }
84
85
        return $page->render([
86
            "title"=>"Frågor",
87
        ]);
88
    }
89
}
90