1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Forum\User; |
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\Question; |
10
|
|
|
use Forum\User\HTMLForm\UserLoginForm; |
11
|
|
|
use Forum\User\HTMLForm\CreateUserForm; |
12
|
|
|
use Forum\User\HTMLForm\UpdateForm; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
16
|
|
|
// use Anax\Route\Exception\NotFoundException; |
17
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* A sample controller to show how a controller class can be implemented. |
21
|
|
|
*/ |
22
|
|
|
class UserController implements ContainerInjectableInterface |
23
|
|
|
{ |
24
|
|
|
use ContainerInjectableTrait; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var $data description |
30
|
|
|
*/ |
31
|
|
|
//private $data; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
// /** |
36
|
|
|
// * The initialize method is optional and will always be called before the |
37
|
|
|
// * target method/action. This is a convienient method where you could |
38
|
|
|
// * setup internal properties that are commonly used by several methods. |
39
|
|
|
// * |
40
|
|
|
// * @return void |
41
|
|
|
// */ |
42
|
|
|
// public function initialize() : void |
43
|
|
|
// { |
44
|
|
|
// ; |
45
|
|
|
// } |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Description. |
51
|
|
|
* |
52
|
|
|
* @param datatype $variable Description |
|
|
|
|
53
|
|
|
* |
54
|
|
|
* @throws Exception |
55
|
|
|
* |
56
|
|
|
* @return object as a response object |
57
|
|
|
*/ |
58
|
|
|
public function indexActionGet() : object |
59
|
|
|
{ |
60
|
|
|
$page = $this->di->get("page"); |
61
|
|
|
$user = new User(); |
62
|
|
|
$user->setDb($this->di->get("dbqb")); |
63
|
|
|
$page->add("user/login"); |
64
|
|
|
|
65
|
|
|
return $page->render([ |
66
|
|
|
"title" => "A index page", |
67
|
|
|
]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Description. |
74
|
|
|
* |
75
|
|
|
* @param datatype $variable Description |
|
|
|
|
76
|
|
|
* |
77
|
|
|
* @throws Exception |
78
|
|
|
* |
79
|
|
|
* @return object as a response object |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function loginAction() : object |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$page = $this->di->get("page"); |
84
|
|
|
$form = new UserLoginForm($this->di); |
85
|
|
|
$form->check(); |
86
|
|
|
$data = [ |
87
|
|
|
"form" => $form->getHTML(), |
88
|
|
|
"title" => "A login page", |
89
|
|
|
]; |
90
|
|
|
$page->add("user/login", $data); |
91
|
|
|
return $page->render($data); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Description. |
96
|
|
|
* |
97
|
|
|
* @param datatype $variable Description |
|
|
|
|
98
|
|
|
* |
99
|
|
|
* @throws Exception |
100
|
|
|
* |
101
|
|
|
* @return object as a response object |
102
|
|
|
*/ |
103
|
|
View Code Duplication |
public function createAction() : object |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$page = $this->di->get("page"); |
106
|
|
|
$form = new CreateUserForm($this->di); |
107
|
|
|
$form->check(); |
108
|
|
|
|
109
|
|
|
$data = [ |
110
|
|
|
"form" => $form->getHTML(), |
111
|
|
|
"title" => "Create user" |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
$page->add("user/create", $data); |
115
|
|
|
return $page->render($data); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function viewAction($userId): object |
119
|
|
|
{ |
120
|
|
|
$page = $this->di->get("page"); |
121
|
|
|
$user = new User(); |
122
|
|
|
$question = new Question(); |
123
|
|
|
$answer = new Answer; |
124
|
|
|
$comment = new Comment; |
125
|
|
|
$user->setDb($this->di->get("dbqb")); |
126
|
|
|
$answer->setDb($this->di->get("dbqb")); |
127
|
|
|
$comment->setDb($this->di->get("dbqb")); |
128
|
|
|
$question->setDb($this->di->get("dbqb")); |
129
|
|
|
$user->findById($userId); |
130
|
|
|
$questions = $question->findAllWhere("user_id = ?", $userId); |
131
|
|
|
$comments = $comment->findAllWhere("user_id = ?", $userId); |
132
|
|
|
$answers = $answer->findAllWhere("user_id = ?", $userId); |
133
|
|
|
$data = [ |
134
|
|
|
"title" => $user->acronym, |
135
|
|
|
"user" => $user, |
136
|
|
|
"questions" => $questions, |
137
|
|
|
"comments" => $comments, |
138
|
|
|
"answers" => $answers, |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
$page->add("user/view", $data); |
142
|
|
|
return $page->render($data); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Handler with form to update an item. |
148
|
|
|
* |
149
|
|
|
* @param int $id the id to update. |
150
|
|
|
* |
151
|
|
|
* @return object as a response object |
152
|
|
|
*/ |
153
|
|
View Code Duplication |
public function updateAction(int $id) : object |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
$page = $this->di->get("page"); |
156
|
|
|
$form = new UpdateForm($this->di, $id); |
157
|
|
|
$form->check(); |
158
|
|
|
|
159
|
|
|
$page->add("user/update", [ |
160
|
|
|
"form" => $form->getHTML(), |
161
|
|
|
]); |
162
|
|
|
|
163
|
|
|
return $page->render([ |
164
|
|
|
"title" => "Update an item", |
165
|
|
|
]); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
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
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.