|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Forum\Question; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
7
|
|
|
use Forum\Answer\Answer; |
|
8
|
|
|
use Forum\Comment\Comment; |
|
9
|
|
|
use Forum\Question\HTMLForm\CreateForm; |
|
10
|
|
|
use Forum\Forum\HTMLForm\DeleteForm; |
|
11
|
|
|
use Forum\Forum\HTMLForm\UpdateForm; |
|
12
|
|
|
use Forum\Tag\Tag; |
|
13
|
|
|
|
|
14
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
|
15
|
|
|
// use Anax\Route\Exception\NotFoundException; |
|
16
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* A sample controller to show how a controller class can be implemented. |
|
20
|
|
|
*/ |
|
21
|
|
|
class QuestionController implements ContainerInjectableInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use ContainerInjectableTrait; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var $data description |
|
28
|
|
|
*/ |
|
29
|
|
|
//private $data; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
// /** |
|
33
|
|
|
// * The initialize method is optional and will always be called before the |
|
34
|
|
|
// * target method/action. This is a convienient method where you could |
|
35
|
|
|
// * setup internal properties that are commonly used by several methods. |
|
36
|
|
|
// * |
|
37
|
|
|
// * @return void |
|
38
|
|
|
// */ |
|
39
|
|
|
// public function initialize() : void |
|
40
|
|
|
// { |
|
41
|
|
|
// ; |
|
42
|
|
|
// } |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Description. |
|
47
|
|
|
* |
|
48
|
|
|
* @param datatype $variable Description |
|
|
|
|
|
|
49
|
|
|
* |
|
50
|
|
|
* @return object as a response object |
|
51
|
|
|
* @throws Exception |
|
52
|
|
|
* |
|
53
|
|
|
*/ |
|
54
|
|
|
public function indexActionGet(): object |
|
55
|
|
|
{ |
|
56
|
|
|
$page = $this->di->get("page"); |
|
57
|
|
|
$question = new Question(); |
|
58
|
|
|
$user_id = $this->di->get("session")->get("user_id"); |
|
59
|
|
|
if (!$user_id) { |
|
60
|
|
|
$this->di->get("response")->redirect("user/login"); |
|
61
|
|
|
} |
|
62
|
|
|
$params = $this->di->get("request")->getGet(); |
|
63
|
|
|
$answer = new Answer; |
|
64
|
|
|
$comment = new Comment; |
|
65
|
|
|
$answer->setDb($this->di->get("dbqb")); |
|
66
|
|
|
$comment->setDb($this->di->get("dbqb")); |
|
67
|
|
|
$question->setDb($this->di->get("dbqb")); |
|
68
|
|
|
if (isset($params["user_id"])) { |
|
69
|
|
|
$questions = $question->findAllWhere("user_id = ?", $params["user_id"]); |
|
70
|
|
|
} else { |
|
71
|
|
|
$questions = $question->findAll(); |
|
72
|
|
|
} |
|
73
|
|
|
$data = [ |
|
74
|
|
|
"questions" => $questions, |
|
75
|
|
|
"title" => "A index page" |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
$page->add("forum/question", $data); |
|
79
|
|
|
return $page->render($data); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function readAction($questionId) { |
|
83
|
|
|
$page = $this->di->get("page"); |
|
84
|
|
|
$question = new Question(); |
|
85
|
|
|
$question->setDb($this->di->get("dbqb")); |
|
86
|
|
|
$questionText = $question->findById($questionId); |
|
87
|
|
|
$answer = new Answer; |
|
88
|
|
|
$comment = new Comment; |
|
89
|
|
|
$tag = new Tag; |
|
90
|
|
|
$answer->setDb($this->di->get("dbqb")); |
|
91
|
|
|
$comment->setDb($this->di->get("dbqb")); |
|
92
|
|
|
$tag->setDb($this->di->get("dbqb")); |
|
93
|
|
|
$tags = $tag->findAllWhere("id in (select tag_id from TagQuestion where question_id = ?)", $questionId); |
|
94
|
|
|
$answerComments = $comment->findAllWhere( |
|
95
|
|
|
"answer_id in (select id from Answer where question_id = ?)", |
|
96
|
|
|
$questionId); |
|
97
|
|
|
$data = [ |
|
98
|
|
|
"question" => $questionText, |
|
99
|
|
|
"answers" => $answer->findAllWhere("question_id = ?", $questionId), |
|
100
|
|
|
"comments" => $comment->findAllWhere("question_id = ?", $questionId), |
|
101
|
|
|
"tags" => $tags, |
|
102
|
|
|
"answerComments" => $answerComments, |
|
103
|
|
|
"title" => "read questions" |
|
104
|
|
|
]; |
|
105
|
|
|
$page->add("forum/read_question", $data); |
|
106
|
|
|
return $page->render($data); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Handler with form to create a new item. |
|
111
|
|
|
* |
|
112
|
|
|
* @return object as a response object |
|
113
|
|
|
*/ |
|
114
|
|
|
public function createAction() : object |
|
115
|
|
|
{ |
|
116
|
|
|
$page = $this->di->get("page"); |
|
117
|
|
|
$form = new CreateForm($this->di); |
|
118
|
|
|
$form->check(); |
|
119
|
|
|
|
|
120
|
|
|
$page->add("forum/create_question", [ |
|
121
|
|
|
"form" => $form->getHTML() |
|
122
|
|
|
]); |
|
123
|
|
|
|
|
124
|
|
|
return $page->render([ |
|
125
|
|
|
"title" => "Create a item", |
|
126
|
|
|
]); |
|
127
|
|
|
} |
|
128
|
|
|
// public function answerAction() |
|
129
|
|
|
// { |
|
130
|
|
|
// $page = $this->di->get("page"); |
|
131
|
|
|
// $form = new CreateForm($this->di); |
|
132
|
|
|
// $form->check(); |
|
133
|
|
|
// $answer = new Answer(); |
|
134
|
|
|
// $answer->setDb($this->di->get("dbqb")); |
|
135
|
|
|
// $page->add("forum/create_answer", [ |
|
136
|
|
|
// "form" => $form->getHTML() |
|
137
|
|
|
// ]); |
|
138
|
|
|
// |
|
139
|
|
|
// return $page->render([ |
|
140
|
|
|
// "title" => "Delete an item", |
|
141
|
|
|
// ]); |
|
142
|
|
|
// } |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.