1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Users\Roles;
13
14 class PermissionsOperation extends \ICanBoogie\Operation
15 {
16 protected function get_controls()
17 {
18 return array
19 (
20 self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER
21 )
22
23 + parent::get_controls();
24 }
25
26 protected function validate(\ICanboogie\Errors $errors)
27 {
28 return true;
29 }
30
31 protected function process()
32 {
33 global $core;
34
35 $request = $this->request;
36 $model = $this->module->model;
37
38 foreach ($request['roles'] as $rid => $perms)
39 {
40 $role = $model[$rid];
41
42 $p = array();
43
44 foreach ($perms as $perm => $name)
45 {
46 if ($name === 'inherit')
47 {
48 continue;
49 }
50
51 if ($name === 'on')
52 {
53 if (isset($core->modules->descriptors[$perm]))
54 {
55
56
57
58
59 $p[$perm] = $core->modules->descriptors[$perm][Module::T_PERMISSION];
60
61 continue;
62 }
63 else
64 {
65
66
67
68
69 $p[$perm] = true;
70
71 continue;
72 }
73 }
74
75 $p[$perm] = is_numeric($name) ? $name : Role::$permission_levels[$name];
76 }
77
78 $role->perms = $p;
79 $role->save();
80 }
81
82 $this->response->message = 'Permissions have been saved.';
83
84 return true;
85 }
86 }