|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Seb\Questions; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
7
|
|
|
use Seb\Questions\HTMLForm\CreateForm; |
|
8
|
|
|
use Seb\Answers\HTMLForm\CreateAnswersForm; |
|
9
|
|
|
use Seb\Answers\Answers; |
|
10
|
|
|
use Seb\QuestionComments\QuestionComments; |
|
11
|
|
|
use Seb\QuestionComments\HTMLForm\CreateQuestionCommentsForm; |
|
12
|
|
|
use Seb\AnswerComments\AnswerComments; |
|
13
|
|
|
use Seb\AnswerComments\HTMLForm\CreateAnswerCommentsForm; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* A sample controller to show how a controller class can be implemented. |
|
17
|
|
|
*/ |
|
18
|
|
|
class QuestionsController implements ContainerInjectableInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use ContainerInjectableTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Show all items. |
|
24
|
|
|
* |
|
25
|
|
|
* @return object as a response object |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function indexActionGet() : object |
|
28
|
|
|
{ |
|
29
|
1 |
|
$page = $this->di->get("page"); |
|
30
|
1 |
|
$question = new Questions(); |
|
31
|
1 |
|
$question->setDb($this->di->get("dbqb")); |
|
32
|
|
|
|
|
33
|
1 |
|
$session = $this->di->get("session"); |
|
34
|
1 |
|
if (!$session->get("acronym")) { |
|
35
|
1 |
|
$page->add("user/please"); |
|
36
|
1 |
|
return $page->render(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
$page->add("forum/questions", [ |
|
40
|
1 |
|
"questions" => $question->findAll(), |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
1 |
|
return $page->render([ |
|
44
|
1 |
|
"title" => "Forum", |
|
45
|
|
|
]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Handler with form to create a new item. |
|
50
|
|
|
* |
|
51
|
|
|
* @return object as a response object |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function createAction() : object |
|
54
|
|
|
{ |
|
55
|
1 |
|
$page = $this->di->get("page"); |
|
56
|
1 |
|
$form = new CreateForm($this->di); |
|
57
|
1 |
|
$form->check(); |
|
58
|
|
|
|
|
59
|
1 |
|
$page->add("forum/createQuestions", [ |
|
60
|
1 |
|
"form" => $form->getHTML(), |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
1 |
|
return $page->render([ |
|
64
|
1 |
|
"title" => "New Topic", |
|
65
|
|
|
]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Handler with form to create a new item. |
|
70
|
|
|
* |
|
71
|
|
|
* @return object as a response object |
|
72
|
|
|
*/ |
|
73
|
1 |
|
public function topicAction(int $id) : object |
|
74
|
|
|
{ |
|
75
|
1 |
|
$page = $this->di->get("page"); |
|
76
|
1 |
|
$topic = new Questions(); |
|
77
|
1 |
|
$topic->setDb($this->di->get("dbqb")); |
|
78
|
1 |
|
$answers = new Answers(); |
|
79
|
1 |
|
$answers->setDb($this->di->get("dbqb")); |
|
80
|
1 |
|
$questioncomments = new QuestionComments(); |
|
81
|
1 |
|
$questioncomments->setDb($this->di->get("dbqb")); |
|
82
|
1 |
|
$answercomments = new AnswerComments(); |
|
83
|
1 |
|
$answercomments->setDb($this->di->get("dbqb")); |
|
84
|
|
|
|
|
85
|
1 |
|
$page->add("forum/topic", [ |
|
86
|
1 |
|
"topic" => $topic->findAll(), |
|
87
|
1 |
|
"answers" => $answers->findAll(), |
|
88
|
1 |
|
"questioncomments" => $questioncomments->findAll(), |
|
89
|
1 |
|
"answercomments" => $answercomments->findAll(), |
|
90
|
1 |
|
"curid" => $id |
|
91
|
|
|
]); |
|
92
|
|
|
|
|
93
|
1 |
|
return $page->render([ |
|
94
|
1 |
|
"title" => "Topic", |
|
95
|
|
|
]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Handler with form to create a new item. |
|
100
|
|
|
* |
|
101
|
|
|
* @return object as a response object |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function answerAction(int $id) : object |
|
104
|
|
|
{ |
|
105
|
1 |
|
$page = $this->di->get("page"); |
|
106
|
1 |
|
$form = new CreateAnswersForm($this->di, $id); |
|
107
|
1 |
|
$form->check(); |
|
108
|
|
|
|
|
109
|
1 |
|
$page->add("forum/createAnswers", [ |
|
110
|
1 |
|
"form" => $form->getHTML() |
|
111
|
|
|
]); |
|
112
|
|
|
|
|
113
|
1 |
|
return $page->render([ |
|
114
|
1 |
|
"title" => "New Answer", |
|
115
|
|
|
]); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Handler with form to create a new item. |
|
120
|
|
|
* |
|
121
|
|
|
* @return object as a response object |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function questioncommentAction(int $id) : object |
|
124
|
|
|
{ |
|
125
|
1 |
|
$page = $this->di->get("page"); |
|
126
|
1 |
|
$form = new CreateQuestionCommentsForm($this->di, $id); |
|
127
|
1 |
|
$form->check(); |
|
128
|
|
|
|
|
129
|
1 |
|
$page->add("forum/createQuestionComments", [ |
|
130
|
1 |
|
"form" => $form->getHTML() |
|
131
|
|
|
]); |
|
132
|
|
|
|
|
133
|
1 |
|
return $page->render([ |
|
134
|
1 |
|
"title" => "New Answer", |
|
135
|
|
|
]); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Handler with form to create a new item. |
|
140
|
|
|
* |
|
141
|
|
|
* @return object as a response object |
|
142
|
|
|
*/ |
|
143
|
1 |
|
public function answercommentAction(int $qid, int $aid) : object |
|
144
|
|
|
{ |
|
145
|
1 |
|
$page = $this->di->get("page"); |
|
146
|
1 |
|
$form = new CreateAnswerCommentsForm($this->di, $qid, $aid); |
|
147
|
1 |
|
$form->check(); |
|
148
|
|
|
|
|
149
|
1 |
|
$page->add("forum/createAnswerComments", [ |
|
150
|
1 |
|
"form" => $form->getHTML() |
|
151
|
|
|
]); |
|
152
|
|
|
|
|
153
|
1 |
|
return $page->render([ |
|
154
|
1 |
|
"title" => "New Answer", |
|
155
|
|
|
]); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|