|
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
|
|
|
|
|
23
|
|
|
$page = $this->di->get("page"); |
|
24
|
|
|
|
|
25
|
|
|
$page->add("forum/index", [ |
|
26
|
|
|
"items" => $forum->findAll(), |
|
27
|
|
|
]); |
|
28
|
|
|
|
|
29
|
|
|
return $page->render([ |
|
30
|
|
|
"title" => $title, |
|
31
|
|
|
]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function createAction() : object |
|
35
|
|
|
{ |
|
36
|
|
|
$page = $this->di->get("page"); |
|
37
|
|
|
$form = new CreatePostForm($this->di); |
|
38
|
|
|
$form->check(); |
|
39
|
|
|
|
|
40
|
|
|
$page->add("anax/v2/article/default", [ |
|
41
|
|
|
"content" => $form->getHTML(), |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
return $page->render([ |
|
45
|
|
|
"title" => "Create a new post", |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function questionAction(int $id) : object |
|
50
|
|
|
{ |
|
51
|
|
|
$page = $this->di->get("page"); |
|
52
|
|
|
$forum = new Forum(); |
|
53
|
|
|
$answer = new Answer(); |
|
54
|
|
|
$comment = new Comment(); |
|
55
|
|
|
$anscomment = new AnswerComment(); |
|
56
|
|
|
$user = new \Anax\User\User(); |
|
57
|
|
|
$forum->setDb($this->di->get("dbqb")); |
|
58
|
|
|
$answer->setDb($this->di->get("dbqb")); |
|
59
|
|
|
$user->setDb($this->di->get("dbqb")); |
|
60
|
|
|
$comment->setDb($this->di->get("dbqb")); |
|
61
|
|
|
$anscomment->setDb($this->di->get("dbqb")); |
|
62
|
|
|
$session = $this->di->get("session"); |
|
63
|
|
|
$login = $session->get("login"); |
|
64
|
|
|
|
|
65
|
|
|
$page->add("forum/specific", [ |
|
66
|
|
|
"content" => $forum->findAllWhere("id = ?", $id), |
|
67
|
|
|
"answers" => $answer->findAllWhere("questionId = ?", $id), |
|
68
|
|
|
"users" => $user->findAllWhere("id = ?", $login), |
|
69
|
|
|
"comments" => $comment->findAllWhere("questionId = ?", $id), |
|
70
|
|
|
"anscomments" => $anscomment->findAll(), |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
|
|
return $page->render([ |
|
74
|
|
|
"title" => "Question", |
|
75
|
|
|
]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function answerAction(int $id) : object |
|
79
|
|
|
{ |
|
80
|
|
|
$page = $this->di->get("page"); |
|
81
|
|
|
$form = new AnswerForm($this->di, $id); |
|
82
|
|
|
$form->check(); |
|
83
|
|
|
|
|
84
|
|
|
$page->add("anax/v2/article/default", [ |
|
85
|
|
|
"content" => $form->getHTML(), |
|
86
|
|
|
]); |
|
87
|
|
|
|
|
88
|
|
|
return $page->render([ |
|
89
|
|
|
"title" => "Create a new answer", |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function commentAction(int $id) : object |
|
94
|
|
|
{ |
|
95
|
|
|
$page = $this->di->get("page"); |
|
96
|
|
|
$form = new CommentForm($this->di, $id); |
|
97
|
|
|
$form->check(); |
|
98
|
|
|
|
|
99
|
|
|
$page->add("anax/v2/article/default", [ |
|
100
|
|
|
"content" => $form->getHTML(), |
|
101
|
|
|
]); |
|
102
|
|
|
|
|
103
|
|
|
return $page->render([ |
|
104
|
|
|
"title" => "Create a new comment", |
|
105
|
|
|
]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function anscommentAction(int $id) : object |
|
109
|
|
|
{ |
|
110
|
|
|
$page = $this->di->get("page"); |
|
111
|
|
|
$form = new CommentAnswerForm($this->di, $id); |
|
112
|
|
|
$form->check(); |
|
113
|
|
|
|
|
114
|
|
|
$page->add("anax/v2/article/default", [ |
|
115
|
|
|
"content" => $form->getHTML(), |
|
116
|
|
|
]); |
|
117
|
|
|
|
|
118
|
|
|
return $page->render([ |
|
119
|
|
|
"title" => "Create a new comment", |
|
120
|
|
|
]); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|