1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Schanihbg\User; |
4
|
|
|
|
5
|
|
|
use \Anax\Configure\ConfigureInterface; |
6
|
|
|
use \Anax\Configure\ConfigureTrait; |
7
|
|
|
use \Anax\DI\InjectionAwareInterface; |
8
|
|
|
use \Anax\Di\InjectionAwareTrait; |
9
|
|
|
use \Schanihbg\User\HTMLForm\UserLoginForm; |
10
|
|
|
use \Schanihbg\User\HTMLForm\CreateUserForm; |
11
|
|
|
use \Schanihbg\User\HTMLForm\UpdateUserForm; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A controller class. |
15
|
|
|
*/ |
16
|
|
|
class UserController implements |
17
|
|
|
ConfigureInterface, |
18
|
|
|
InjectionAwareInterface |
19
|
|
|
{ |
20
|
|
|
use ConfigureTrait, |
21
|
|
|
InjectionAwareTrait; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var $data description |
27
|
|
|
*/ |
28
|
|
|
//private $data; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Description. |
34
|
|
|
* |
35
|
|
|
* @param datatype $variable Description |
|
|
|
|
36
|
|
|
* |
37
|
|
|
* @throws Exception |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
public function getIndex() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$title = "User profile"; |
44
|
|
|
$view = $this->di->get("view"); |
45
|
|
|
$pageRender = $this->di->get("pageRender"); |
46
|
|
|
|
47
|
|
|
$view->add("user/profile"); |
48
|
|
|
|
49
|
|
|
$pageRender->renderPage(["title" => $title]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Description. |
56
|
|
|
* |
57
|
|
|
* @param datatype $variable Description |
|
|
|
|
58
|
|
|
* |
59
|
|
|
* @throws Exception |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function getPostLogin() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$title = "A login page"; |
66
|
|
|
$view = $this->di->get("view"); |
67
|
|
|
$pageRender = $this->di->get("pageRender"); |
68
|
|
|
$form = new UserLoginForm($this->di); |
69
|
|
|
|
70
|
|
|
$form->check(); |
71
|
|
|
|
72
|
|
|
$data = [ |
73
|
|
|
"content" => $form->getHTML(), |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$view->add("default2/article", $data); |
77
|
|
|
|
78
|
|
|
$pageRender->renderPage(["title" => $title]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Description. |
85
|
|
|
* |
86
|
|
|
* @param datatype $variable Description |
|
|
|
|
87
|
|
|
* |
88
|
|
|
* @throws Exception |
89
|
|
|
* |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function getPostCreateUser() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$title = "A create user page"; |
95
|
|
|
$view = $this->di->get("view"); |
96
|
|
|
$pageRender = $this->di->get("pageRender"); |
97
|
|
|
$form = new CreateUserForm($this->di); |
98
|
|
|
|
99
|
|
|
$form->check(); |
100
|
|
|
|
101
|
|
|
$data = [ |
102
|
|
|
"content" => $form->getHTML(), |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
$view->add("default2/article", $data); |
106
|
|
|
|
107
|
|
|
$pageRender->renderPage(["title" => $title]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Handler with form to update a user. |
112
|
|
|
* |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
View Code Duplication |
public function getPostUpdateUser($id) |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
$title = "Update an item"; |
118
|
|
|
$view = $this->di->get("view"); |
119
|
|
|
$pageRender = $this->di->get("pageRender"); |
120
|
|
|
$form = new UpdateUserForm($this->di, $id); |
121
|
|
|
|
122
|
|
|
$form->check(); |
123
|
|
|
|
124
|
|
|
$data = [ |
125
|
|
|
"form" => $form->getHTML(), |
126
|
|
|
"id" => $id, |
127
|
|
|
]; |
128
|
|
|
|
129
|
|
|
$view->add("user/update", $data); |
130
|
|
|
|
131
|
|
|
$pageRender->renderPage(["title" => $title]); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Description. |
136
|
|
|
* |
137
|
|
|
* @param datatype $variable Description |
|
|
|
|
138
|
|
|
* |
139
|
|
|
* @throws Exception |
140
|
|
|
* |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
public function loginUser($input) |
144
|
|
|
{ |
145
|
|
|
$this->di->get("session")->set("userLoggedIn", $input); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Description. |
150
|
|
|
* |
151
|
|
|
* @param datatype $variable Description |
|
|
|
|
152
|
|
|
* |
153
|
|
|
* @throws Exception |
154
|
|
|
* |
155
|
|
|
* @return void |
156
|
|
|
*/ |
157
|
|
View Code Duplication |
public function logoutUser() |
|
|
|
|
158
|
|
|
{ |
159
|
|
|
$title = "Logout page"; |
160
|
|
|
$view = $this->di->get("view"); |
161
|
|
|
$pageRender = $this->di->get("pageRender"); |
162
|
|
|
|
163
|
|
|
$view->add("user/logout"); |
164
|
|
|
|
165
|
|
|
$pageRender->renderPage(["title" => $title]); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Description. |
170
|
|
|
* |
171
|
|
|
* @param datatype $variable Description |
|
|
|
|
172
|
|
|
* |
173
|
|
|
* @throws Exception |
174
|
|
|
* |
175
|
|
|
* @return void |
176
|
|
|
*/ |
177
|
|
View Code Duplication |
public function getIDByUser($userInput) |
|
|
|
|
178
|
|
|
{ |
179
|
|
|
$user = new User(); |
180
|
|
|
$user->setDb($this->di->get("database")); |
181
|
|
|
$user->find("acronym", $userInput); |
182
|
|
|
|
183
|
|
|
return $user; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Description. |
188
|
|
|
* |
189
|
|
|
* @param datatype $variable Description |
|
|
|
|
190
|
|
|
* |
191
|
|
|
* @throws Exception |
192
|
|
|
* |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
public function adminControl() |
196
|
|
|
{ |
197
|
|
|
$title = "Admin Control"; |
198
|
|
|
$view = $this->di->get("view"); |
199
|
|
|
$pageRender = $this->di->get("pageRender"); |
200
|
|
|
|
201
|
|
|
$sql = "SELECT * FROM `User`"; |
202
|
|
|
|
203
|
|
|
$data = $this->di->get("database")->executeFetchAll($sql); |
204
|
|
|
|
205
|
|
|
$view->add("user/admin", ["content" => $data]); |
206
|
|
|
|
207
|
|
|
$pageRender->renderPage(["title" => $title]); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Delete user |
212
|
|
|
* |
213
|
|
|
* @return void |
214
|
|
|
*/ |
215
|
|
|
public function removeUser($id) |
216
|
|
|
{ |
217
|
|
|
$sql = "DELETE FROM `User` WHERE id = ?"; |
218
|
|
|
$this->di->get("database")->execute($sql, [$id]); |
219
|
|
|
$this->di->get("response")->redirect($this->di->get("url")->create("user/admin")); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
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.