ProfileController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 60
dl 0
loc 95
ccs 0
cts 62
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A profilesAction() 0 27 1
A editAction() 0 13 1
A indexAction() 0 28 1
A allAction() 0 14 1
1
<?php
2
3
namespace Anax\Profile;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\User\HTMLForm\EditUserForm;
8
9
class ProfileController implements ContainerInjectableInterface
10
{
11
    use ContainerInjectableTrait;
12
13
    public function indexAction()
14
    {
15
        $title = "Your profile";
16
        $user = new \Anax\User\User();
17
        $forum = new \Anax\Forum\Forum();
18
        $answer = new \Anax\Forum\Answer();
19
        $comments = new \Anax\Forum\Comment();
20
        $anscomments = new \Anax\Forum\AnswerComment();
21
        $user->setDb($this->di->get("dbqb"));
22
        $forum->setDb($this->di->get("dbqb"));
23
        $answer->setDb($this->di->get("dbqb"));
24
        $comments->setDb($this->di->get("dbqb"));
25
        $anscomments->setDb($this->di->get("dbqb"));
26
        $session = $this->di->get("session");
27
        $loginId = $session->get("login");
28
29
        $page = $this->di->get("page");
30
31
        $page->add("profile/index", [
32
            "items" => $user->findAllWhere("id = ?", $loginId),
33
            "posts" => $forum->findAllWhere("user = ?", $loginId),
34
            "answers" => $answer->findAllWhere("user = ?", $loginId),
35
            "comments" => $comments->findAllWhere("user = ?", $loginId),
36
            "anscomments" => $anscomments->findAllWhere("user = ?", $loginId),
37
        ]);
38
39
        return $page->render([
40
            "title" => $title,
41
        ]);
42
    }
43
44
    public function allAction()
45
    {
46
        $title = "All users";
47
        $user = new \Anax\User\User();
48
        $user->setDb($this->di->get("dbqb"));
49
50
        $page = $this->di->get("page");
51
52
        $page->add("profile/all", [
53
            "users" => $user->findAll(),
54
        ]);
55
56
        return $page->render([
57
            "title" => $title,
58
        ]);
59
    }
60
61
    public function profilesAction(int $id)
62
    {
63
        $title = "Specific user";
64
        $user = new \Anax\User\User();
65
        $forum = new \Anax\Forum\Forum();
66
        $answer = new \Anax\Forum\Answer();
67
        $comments = new \Anax\Forum\Comment();
68
        $anscomments = new \Anax\Forum\AnswerComment();
69
70
        $user->setDb($this->di->get("dbqb"));
71
        $forum->setDb($this->di->get("dbqb"));
72
        $answer->setDb($this->di->get("dbqb"));
73
        $comments->setDb($this->di->get("dbqb"));
74
        $anscomments->setDb($this->di->get("dbqb"));
75
76
        $page = $this->di->get("page");
77
78
        $page->add("profile/specific", [
79
            "users" => $user->findAllWhere("id = ?", $id),
80
            "questions" => $forum->findAllWhere("user = ?", $id),
81
            "answers" => $answer->findAllWhere("user = ?", $id),
82
            "comments" => $comments->findAllWhere("user = ?", $id),
83
            "anscomments" => $anscomments->findAllWhere("user = ?", $id),
84
        ]);
85
86
        return $page->render([
87
            "title" => $title,
88
        ]);
89
    }
90
91
    public function editAction(int $id)
92
    {
93
        $title = "Edit user";
94
        $page = $this->di->get("page");
95
        $form = new EditUserForm($this->di, $id);
96
        $form->check();
97
98
        $page->add("anax/v2/article/default", [
99
            "content" => $form->getHTML(),
100
        ]);
101
102
        return $page->render([
103
            "title" => $title,
104
        ]);
105
    }
106
}
107