Completed
Push — master ( df8ec4...96358d )
by Nazar
04:25
created

users_save::users_users_save()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 7.551
cc 7
eloc 15
nc 5
nop 0
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\Index,
13
	cs\User;
14
15
trait users_save {
16
	static function users_users_save () {
17
		if (!isset($_POST['mode'])) {
18
			return;
19
		}
20
		$Index = Index::instance();
21
		$User  = User::instance();
22
		switch ($_POST['mode']) {
23
			case 'groups':
24
				if (isset($_POST['user'], $_POST['user']['id'], $_POST['user']['groups']) && $_POST['user']['groups']) {
25
					$user_id = (int)$_POST['user']['id'];
26
					if ($_POST['user']['id'] == User::ROOT_ID || in_array(User::BOT_GROUP_ID, (array)$User->get_groups($user_id))) {
27
						break;
28
					}
29
					$groups = _json_decode($_POST['user']['groups']);
30
					$Index->save(
31
						$User->set_groups($groups, $user_id)
32
					);
33
				}
34
				break;
35
		}
36
	}
37
}
38