Completed
Push — master ( 8dbcbc...f734af )
by Nazar
07:14
created

users   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 181
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 19
c 3
b 1
f 0
lcom 0
cbo 9
dl 0
loc 181
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A users_general() 0 7 1
A users_groups() 0 7 1
A users_mail() 0 7 1
A users_permissions() 0 7 1
A users_security() 0 57 1
D users_users() 0 94 14
1
<?php
2
/**
3
 * @package    CleverStyle CMS
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2015, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\admin\Controller;
11
use
12
	cs\Config,
13
	cs\Group,
14
	cs\Index,
15
	cs\Language,
16
	cs\Page,
17
	cs\Route,
18
	cs\User,
19
	h;
20
21
trait users {
22
	static function users_general () {
23
		$Index       = Index::instance();
24
		$Index->form = false;
25
		$Index->content(
26
			h::cs_system_admin_users_general()
27
		);
28
	}
29
	static function users_groups () {
30
		$a       = Index::instance();
31
		$a->form = false;
32
		$a->content(
33
			h::cs_system_admin_groups_list()
34
		);
35
	}
36
	static function users_mail () {
37
		$Index       = Index::instance();
38
		$Index->form = false;
39
		$Index->content(
40
			h::cs_system_admin_mail()
41
		);
42
	}
43
	static function users_permissions () {
44
		$a       = Index::instance();
45
		$a->form = false;
46
		$a->content(
47
			h::cs_system_admin_permissions_list()
48
		);
49
	}
50
	static function users_security () {
51
		$Config = Config::instance();
52
		$Index  = Index::instance();
53
		$L      = Language::instance();
54
		/**
55
		 * @var \cs\_SERVER $_SERVER
56
		 */
57
		$Index->apply_button = true;
58
		$Index->content(
59
			static::vertical_table(
60
				[
61
					[
62
						h::info('key_expire'),
63
						h::{'input[is=cs-input-text][type=number]'}(
64
							[
65
								'name'  => 'core[key_expire]',
66
								'value' => $Config->core['key_expire'],
67
								'min'   => 1
68
							]
69
						).
70
						$L->seconds
71
					],
72
					[
73
						h::info('ip_black_list'),
74
						h::{'textarea[is=cs-textarea][autosize]'}(
75
							$Config->core['ip_black_list'],
76
							[
77
								'name' => 'core[ip_black_list]'
78
							]
79
						)
80
					],
81
					[
82
						h::info('ip_admin_list_only'),
83
						h::radio(
84
							[
85
								'name'    => 'core[ip_admin_list_only]',
86
								'checked' => $Config->core['ip_admin_list_only'],
87
								'value'   => [0, 1],
88
								'in'      => [$L->off, $L->on]
89
							]
90
						)
91
					],
92
					[
93
						h::info('ip_admin_list'),
94
						h::{'textarea[is=cs-textarea][autosize]'}(
95
							$Config->core['ip_admin_list'],
96
							[
97
								'name' => 'core[ip_admin_list]'
98
							]
99
						).
100
						h::br().
101
						$L->current_ip.': '.h::b($_SERVER->ip)
102
					]
103
				]
104
			)
105
		);
106
	}
107
	static function users_users () {
108
		$L    = Language::instance();
109
		$Page = Page::instance();
110
		$User = User::instance();
111
		$a    = Index::instance();
112
		$rc   = Route::instance()->route;
113
		if (isset($rc[2], $rc[3])) {
114
			$is_bot = in_array(3, (array)$User->get_groups($rc[3]));
115
			switch ($rc[2]) {
116
				case 'groups':
117
					if ($is_bot || !isset($rc[3]) || $rc[3] == User::ROOT_ID) {
118
						break;
119
					}
120
					$a->cancel_button_back = true;
121
					$Group                 = Group::instance();
122
					$user_groups           = array_reverse($User->get_groups($rc[3]));
123
					$all_groups            = $Group->get_all();
124
					$groups_selected       = h::{'li.cs-block-primary.cs-text.primary'}(
125
						$L->selected_groups
126
					);
127
					$groups_list           = h::{'li.cs-block-primary.cs-text.primary'}(
128
						$L->other_groups
129
					);
130
					if (is_array($user_groups) && !empty($user_groups)) {
131
						foreach ($user_groups as $group) {
132
							$group = $Group->get($group);
133
							$groups_selected .= h::{'li.cs-block-success.cs-text-success'}(
134
								$group['title'],
135
								[
136
									'data-id' => $group['id'],
137
									'tooltip' => $group['description']
138
								]
139
							);
140
						}
141
					}
142
					if (is_array($all_groups) && !empty($all_groups)) {
143
						foreach ($all_groups as $group) {
144
							if ($group['id'] == User::BOT_GROUP_ID || in_array($group['id'], $user_groups)) {
145
								continue;
146
							}
147
							$groups_list .= h::{'li.cs-block-warning.cs-text-warning'}(
148
								$group['title'],
149
								[
150
									'data-id' => $group['id'],
151
									'tooltip' => $group['description']
152
								]
153
							);
154
						}
155
					}
156
					$Page->title(
157
						$L->user_groups($User->username($rc[3]))
0 ignored issues
show
Documentation Bug introduced by
The method user_groups does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
158
					);
159
					$a->content(
160
						h::{'h2.cs-text-center'}(
161
							$L->user_groups(
0 ignored issues
show
Documentation Bug introduced by
The method user_groups does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
162
								$User->username($rc[3])
163
							),
164
							[
165
								'tooltip' => $L->user_groups_info
166
							]
167
						).
168
						h::{'div'}(
169
							h::{'ul#cs-users-groups-list-selected'}($groups_selected).
170
							h::{'ul#cs-users-groups-list'}($groups_list)
171
						).
172
						h::{'input[type=hidden]'}(
173
							[
174
								'name'  => 'user[id]',
175
								'value' => $rc[3]
176
							]
177
						).
178
						h::{'input#cs-user-groups[type=hidden]'}(
179
							[
180
								'name' => 'user[groups]'
181
							]
182
						)
183
					);
184
					break;
185
			}
186
			$a->content(
187
				h::{'input[type=hidden]'}(
188
					[
189
						'name'  => 'mode',
190
						'value' => $rc[2]
191
					]
192
				)
193
			);
194
		} else {
195
			$a->form = false;
196
			$a->content(
197
				h::{'cs-system-admin-users-list'}()
198
			);
199
		}
200
	}
201
}
202