1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alvo\User; |
4
|
|
|
|
5
|
|
|
use \Anax\Configure\ConfigureInterface; |
6
|
|
|
use \Anax\Configure\ConfigureTrait; |
7
|
|
|
use \Anax\DI\InjectionAwareInterface; |
8
|
|
|
use \Anax\Di\InjectionAwareTrait; |
9
|
|
|
// use \Alvo\User\HTMLForm\UserLoginForm; |
10
|
|
|
// use \Alvo\User\HTMLForm\CreateUserForm; |
11
|
|
|
use \Alvo\User\HTMLForm\UpdateUserForm; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A controller class. |
15
|
|
|
*/ |
16
|
|
|
class AdminController implements InjectionAwareInterface |
17
|
|
|
{ |
18
|
|
|
use InjectionAwareTrait; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Init module |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function init() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->session = $this->di->get("session"); |
|
|
|
|
28
|
|
|
$this->response = $this->di->get("response"); |
|
|
|
|
29
|
|
|
$this->user = $this->di->get("user"); |
|
|
|
|
30
|
|
|
$this->view = $this->di->get("view"); |
|
|
|
|
31
|
|
|
$this->pageRender = $this->di->get("pageRender"); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function isAdmin() |
37
|
|
|
{ |
38
|
|
|
$admin = $this->user->getUser()->admin; |
39
|
|
|
if (!$admin) { |
40
|
|
|
$this->response->redirect("user"); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Description. |
48
|
|
|
* |
49
|
|
|
* @param datatype $variable Description |
|
|
|
|
50
|
|
|
* |
51
|
|
|
* @throws Exception |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function getIndex() |
56
|
|
|
{ |
57
|
|
|
$title = "Admin | All users"; |
58
|
|
|
|
59
|
|
|
$data = $this->user->getAllUsers('email', $this->session->get('user')) ?: []; |
60
|
|
|
|
61
|
|
|
$this->view->add("admin/index", ["users" => $data]); |
62
|
|
|
$this->pageRender->renderPage(["title" => $title]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
View Code Duplication |
public function editUser($id) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$title = "Admin | Edit user"; |
70
|
|
|
|
71
|
|
|
$user = $this->user->getUser("id", $id); |
72
|
|
|
|
73
|
|
|
$form = new UpdateUserForm($this->di, $user); |
74
|
|
|
$form->check(); |
75
|
|
|
|
76
|
|
|
$data = $this->user->getUser('id', $id); |
77
|
|
|
|
78
|
|
|
$this->view->add("user/profile", ["user" => $data, "form" => $form->getHTML()]); |
79
|
|
|
$this->pageRender->renderPage(["title" => $title]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function deleteUser($id) |
85
|
|
|
{ |
86
|
|
|
$this->user->delete($id); |
87
|
|
|
$this->response->redirect("admin"); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.