1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin; |
4
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\Role; |
6
|
|
|
use Apps\Model\Admin\User\FormUserGroupUpdate; |
7
|
|
|
use Apps\Model\Admin\User\FormUserSettings; |
8
|
|
|
use Extend\Core\Arch\AdminController; |
9
|
|
|
use Ffcms\Core\App; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class User. Admin controller of user application. |
13
|
|
|
* @package Apps\Controller\Admin |
14
|
|
|
*/ |
15
|
|
|
class User extends AdminController |
16
|
|
|
{ |
17
|
|
|
const VERSION = '1.0.0'; |
18
|
|
|
const ITEM_PER_PAGE = 10; |
19
|
|
|
|
20
|
|
|
public $type = 'app'; |
21
|
|
|
|
22
|
|
|
use User\ActionIndex { |
23
|
|
|
index as actionIndex; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
use User\ActionUpdate { |
27
|
|
|
update as actionUpdate; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
use User\ActionDelete { |
31
|
|
|
delete as actionDelete; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
use User\ActionInvite { |
35
|
|
|
invite as actionInvite; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Show all role groups |
40
|
|
|
* @return string |
41
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
42
|
|
|
*/ |
43
|
|
|
public function actionGrouplist() |
44
|
|
|
{ |
45
|
|
|
// get all roles |
46
|
|
|
$roles = Role::all(); |
47
|
|
|
|
48
|
|
|
return $this->view->render('group_list', [ |
49
|
|
|
'records' => $roles |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Edit and add groups |
55
|
|
|
* @param int $id |
56
|
|
|
* @return string |
57
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
58
|
|
|
*/ |
59
|
|
|
public function actionGroupUpdate($id) |
60
|
|
|
{ |
61
|
|
|
// find role or create new object |
62
|
|
|
$role = Role::findOrNew($id); |
63
|
|
|
|
64
|
|
|
$model = new FormUserGroupUpdate($role); |
65
|
|
|
if ($model->send()) { // work with post request |
66
|
|
|
if ($model->validate()) { |
67
|
|
|
$model->save(); |
68
|
|
|
App::$Session->getFlashBag()->add('success', __('Data was successful updated')); |
69
|
|
|
} else { |
70
|
|
|
App::$Session->getFlashBag()->add('error', __('Form validation is failed')); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// render view |
75
|
|
|
return $this->view->render('group_update', [ |
76
|
|
|
'model' => $model |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* User identity settings |
82
|
|
|
* @return string |
83
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function actionSettings() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
// load model and pass property's as argument |
88
|
|
|
$model = new FormUserSettings($this->getConfigs()); |
89
|
|
|
|
90
|
|
|
if ($model->send()) { |
91
|
|
|
if ($model->validate()) { |
92
|
|
|
$this->setConfigs($model->getAllProperties()); |
93
|
|
|
App::$Session->getFlashBag()->add('success', __('Settings is successful updated')); |
94
|
|
|
$this->response->redirect('user/index'); |
95
|
|
|
} else { |
96
|
|
|
App::$Session->getFlashBag()->add('error', __('Form validation is failed')); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// render view |
101
|
|
|
return $this->view->render('settings', [ |
102
|
|
|
'model' => $model |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.