1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AdminUserController |
5
|
|
|
* @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua) |
6
|
|
|
* @author Aleksandr Torosh <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Admin\Controller; |
10
|
|
|
|
11
|
|
|
use Application\Mvc\Controller; |
12
|
|
|
use Admin\Form\AdminUserForm; |
13
|
|
|
use Admin\Model\AdminUser; |
14
|
|
|
|
15
|
|
|
class AdminUserController extends Controller |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
public function initialize() |
19
|
|
|
{ |
20
|
|
|
$this->setAdminEnvironment(); |
21
|
|
|
$this->helper->activeMenu()->setActive('admin-user'); |
22
|
|
|
|
23
|
|
|
$this->view->languages_disabled = true; |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function indexAction() |
27
|
|
|
{ |
28
|
|
|
$this->view->entries = AdminUser::find([ |
|
|
|
|
29
|
|
|
"order" => "id DESC" |
30
|
|
|
]); |
31
|
|
|
|
32
|
|
|
$this->helper->title($this->helper->at('Manage Users'), true); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function addAction() |
36
|
|
|
{ |
37
|
|
|
$this->view->pick(['admin-user/edit']); |
38
|
|
|
|
39
|
|
|
$model = new AdminUser(); |
40
|
|
|
$form = new AdminUserForm(); |
41
|
|
|
$form->initAdding(); |
42
|
|
|
|
43
|
|
|
if ($this->request->isPost()) { |
44
|
|
|
$model = new AdminUser(); |
45
|
|
|
$post = $this->request->getPost(); |
46
|
|
|
$form->bind($post, $model); |
47
|
|
|
if ($form->isValid()) { |
48
|
|
|
$model->setCheckboxes($post); |
49
|
|
|
if ($model->save()) { |
50
|
|
|
$this->flash->success($this->helper->at('User created', ['name' => $model->getLogin()])); |
51
|
|
|
$this->redirect($this->url->get() . 'admin/admin-user'); |
52
|
|
|
} else { |
53
|
|
|
$this->flashErrors($model); |
54
|
|
|
} |
55
|
|
|
} else { |
56
|
|
|
$this->flashErrors($form); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->view->form = $form; |
|
|
|
|
61
|
|
|
$this->view->model = $model; |
|
|
|
|
62
|
|
|
$this->view->submitButton = $this->helper->at('Add New'); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$this->helper->title($this->helper->at('Administrator'), true); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function editAction($id) |
68
|
|
|
{ |
69
|
|
|
$model = AdminUser::findFirst($id); |
|
|
|
|
70
|
|
|
if (!$model) { |
71
|
|
|
$this->redirect($this->url->get() . 'admin/admin-user'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$form = new AdminUserForm(); |
75
|
|
|
|
76
|
|
|
if ($this->request->isPost()) { |
77
|
|
|
$post = $this->request->getPost(); |
78
|
|
|
$form->bind($post, $model); |
79
|
|
|
if ($form->isValid()) { |
80
|
|
|
$model->setCheckboxes($post); |
|
|
|
|
81
|
|
|
if ($model->save() == true) { |
|
|
|
|
82
|
|
|
$this->flash->success('User [' . $model->getLogin() . '] has been saved'); |
|
|
|
|
83
|
|
|
return $this->redirect($this->url->get() . 'admin/admin-user'); |
84
|
|
|
} else { |
85
|
|
|
$this->flashErrors($model); |
86
|
|
|
} |
87
|
|
|
} else { |
88
|
|
|
$this->flashErrors($form); |
89
|
|
|
} |
90
|
|
|
} else { |
91
|
|
|
$form->setEntity($model); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->view->submitButton = $this->helper->at('Save'); |
|
|
|
|
95
|
|
|
$this->view->form = $form; |
|
|
|
|
96
|
|
|
$this->view->model = $model; |
|
|
|
|
97
|
|
|
|
98
|
|
|
$this->helper->title($this->helper->at('Manage Users'), true); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function deleteAction($id) |
102
|
|
|
{ |
103
|
|
|
$model = AdminUser::findFirst($id); |
|
|
|
|
104
|
|
|
if (!$model) { |
105
|
|
|
return $this->redirect($this->url->get() . 'admin/admin-user'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($model->getLogin() == 'admin') { |
109
|
|
|
$this->flash->error('Admin user cannot be deleted'); |
110
|
|
|
return $this->redirect($this->url->get() . 'admin/admin-user'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($this->request->isPost()) { |
114
|
|
|
$model->delete(); |
115
|
|
|
$this->flash->warning('Deleting user [' . $model->getLogin() . ']'); |
116
|
|
|
return $this->redirect($this->url->get() . 'admin/admin-user'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$this->view->model = $model; |
|
|
|
|
120
|
|
|
|
121
|
|
|
$this->helper->title($this->helper->at('Delete User'), true); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: