Completed
Branch master (3028d7)
by Markus
06:24 queued 03:12
created

ForumController::anscommentAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Anax\Forum;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\Forum\HTMLForm\AnswerForm;
8
use Anax\Forum\HTMLForm\CreatePostForm;
9
use Anax\Forum\HTMLForm\CommentForm;
10
use Anax\Forum\HTMLForm\CommentAnswerForm;
11
12
class ForumController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
    public function indexAction()
17
    {
18
        $title = "The forum";
19
        $forum = new Forum();
20
        $forum->setDb($this->di->get("dbqb"));
21
22
        $page = $this->di->get("page");
23
24
        $page->add("forum/index", [
25
            "items" => $forum->findAll(),
26
        ]);
27
28
        return $page->render([
29
            "title" => $title,
30
        ]);
31
    }
32
33
    public function createAction() : object
34
    {
35
        $page = $this->di->get("page");
36
        $form = new CreatePostForm($this->di);
37
        $form->check();
38
39
        $page->add("anax/v2/article/default", [
40
            "content" => $form->getHTML(),
41
        ]);
42
43
        return $page->render([
44
            "title" => "Create a new post",
45
        ]);
46
    }
47
48
    public function questionAction(int $id) : object
49
    {
50
        $page = $this->di->get("page");
51
        $forum = new Forum();
52
        $answer = new Answer();
53
        $comment = new Comment();
54
        $anscomment = new AnswerComment();
55
        $user = new \Anax\User\User();
56
        $forum->setDb($this->di->get("dbqb"));
57
        $answer->setDb($this->di->get("dbqb"));
58
        $user->setDb($this->di->get("dbqb"));
59
        $comment->setDb($this->di->get("dbqb"));
60
        $anscomment->setDb($this->di->get("dbqb"));
61
        $session = $this->di->get("session");
62
        $login = $session->get("login");
63
64
        $page->add("forum/specific", [
65
            "content" => $forum->findAllWhere("id = ?", $id),
66
            "answers" => $answer->findAllWhere("question_id = ?", $id),
67
            "users" => $user->findAllWhere("id = ?", $login),
68
            "comments" => $comment->findAllWhere("question_id = ?", $id),
69
            "anscomments" => $anscomment->findAll(),
70
        ]);
71
72
        return $page->render([
73
            "title" => "Question",
74
        ]);
75
    }
76
77
    public function answerAction(int $id) : object
78
    {
79
        $page = $this->di->get("page");
80
        $form = new AnswerForm($this->di, $id);
81
        $form->check();
82
83
        $page->add("anax/v2/article/default", [
84
            "content" => $form->getHTML(),
85
        ]);
86
87
        return $page->render([
88
            "title" => "Create a new answer",
89
        ]);
90
    }
91
92
    public function commentAction(int $id) : object
93
    {
94
        $page = $this->di->get("page");
95
        $form = new CommentForm($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" => "Create a new comment",
104
        ]);
105
    }
106
107
    public function anscommentAction(int $id) : object
108
    {
109
        $page = $this->di->get("page");
110
        $form = new CommentAnswerForm($this->di, $id);
111
        $form->check();
112
113
        $page->add("anax/v2/article/default", [
114
            "content" => $form->getHTML(),
115
        ]);
116
117
        return $page->render([
118
            "title" => "Create a new comment",
119
        ]);
120
    }
121
}
122