@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | $context['class'] = get_class($throwable); |
56 | 56 | $context['trace'] = $throwable->getTrace(); |
57 | 57 | |
58 | - if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
59 | - (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
|
60 | - elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
61 | - (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
|
62 | - else |
|
58 | + if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') { |
|
59 | + (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
|
60 | + } elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') { |
|
61 | + (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
|
62 | + } else |
|
63 | 63 | { |
64 | 64 | die('This Throwable is not an Error or an Exception. This is unfortunate.'); |
65 | 65 | } |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | error_log($display_error); |
94 | 94 | $display_error.= self::format_trace($context['trace'], false); |
95 | 95 | self::HTTP_500($display_error); |
96 | - } |
|
97 | - elseif($this->system_halted($level)) // analyses error level |
|
96 | + } elseif($this->system_halted($level)) { |
|
97 | + // analyses error level |
|
98 | 98 | { |
99 | 99 | $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, self::format_file($context['file']), $context['line'], $message); |
100 | + } |
|
100 | 101 | error_log($display_error); |
101 | 102 | $display_error.= self::format_trace($context['trace'], true); |
102 | 103 | self::HTTP_500($display_error); |
103 | - } |
|
104 | - else |
|
104 | + } else |
|
105 | 105 | {// --- Handles user messages, through SESSION storage |
106 | 106 | $this->report_to_user($level, $message, $context); |
107 | 107 | } |
@@ -128,11 +128,13 @@ discard block |
||
128 | 128 | // ----------------------------------------------------------- User messages:add one |
129 | 129 | public function report_to_user($level, $message, $context = []) |
130 | 130 | { |
131 | - if(!isset($_SESSION[self::REPORTING_USER])) |
|
132 | - $_SESSION[self::REPORTING_USER] = []; |
|
131 | + if(!isset($_SESSION[self::REPORTING_USER])) { |
|
132 | + $_SESSION[self::REPORTING_USER] = []; |
|
133 | + } |
|
133 | 134 | |
134 | - if(!isset($_SESSION[self::REPORTING_USER][$level])) |
|
135 | - $_SESSION[self::REPORTING_USER][$level] = []; |
|
135 | + if(!isset($_SESSION[self::REPORTING_USER][$level])) { |
|
136 | + $_SESSION[self::REPORTING_USER][$level] = []; |
|
137 | + } |
|
136 | 138 | |
137 | 139 | $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
138 | 140 | } |
@@ -177,8 +179,9 @@ discard block |
||
177 | 179 | $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
178 | 180 | $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
179 | 181 | |
180 | - if(isset($m[$level])) |
|
181 | - return $m[$level]; |
|
182 | + if(isset($m[$level])) { |
|
183 | + return $m[$level]; |
|
184 | + } |
|
182 | 185 | |
183 | 186 | throw new \Exception(__FUNCTION__."($level): $level is unknown"); |
184 | 187 | } |
@@ -26,8 +26,7 @@ discard block |
||
26 | 26 | self::create_file($locale_path, $lang); |
27 | 27 | |
28 | 28 | $this->logger()->nice(L('KADRO_SYSTEM_FILE_UPDATED')); |
29 | - } |
|
30 | - catch(\Exception $e) |
|
29 | + } catch(\Exception $e) |
|
31 | 30 | { |
32 | 31 | $this->logger()->notice(L('KADRO_SYSTEM_FILE_UPDATED')); |
33 | 32 | } |
@@ -40,10 +39,12 @@ discard block |
||
40 | 39 | $assoc = []; |
41 | 40 | foreach($res as $id => $trad) |
42 | 41 | { |
43 | - if(!isset($assoc[$trad->kategorio])) |
|
44 | - $assoc[$trad->kategorio] = []; |
|
45 | - if(!isset($assoc[$trad->kategorio][$trad->sekcio])) |
|
46 | - $assoc[$trad->kategorio][$trad->sekcio] = []; |
|
42 | + if(!isset($assoc[$trad->kategorio])) { |
|
43 | + $assoc[$trad->kategorio] = []; |
|
44 | + } |
|
45 | + if(!isset($assoc[$trad->kategorio][$trad->sekcio])) { |
|
46 | + $assoc[$trad->kategorio][$trad->sekcio] = []; |
|
47 | + } |
|
47 | 48 | |
48 | 49 | $assoc[$trad->kategorio][$trad->sekcio][$trad->referenco] = $trad->$lang; |
49 | 50 | } |
@@ -57,8 +58,9 @@ discard block |
||
57 | 58 | public static function init($locale_path) |
58 | 59 | { |
59 | 60 | $languages = array_keys(array_slice(Traduko::inspect(Traduko::table_name())->columns(), 4)); |
60 | - foreach($languages as $l) |
|
61 | - self::create_file($locale_path,$l); |
|
61 | + foreach($languages as $l) { |
|
62 | + self::create_file($locale_path,$l); |
|
63 | + } |
|
62 | 64 | |
63 | 65 | return $languages; |
64 | 66 | } |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | parent::edit(); |
24 | 24 | |
25 | 25 | // do we create? or do we edit someone else ? must be admin |
26 | - if(is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) |
|
27 | - $this->authorize('group_admin'); |
|
26 | + if(is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) { |
|
27 | + $this->authorize('group_admin'); |
|
28 | + } |
|
28 | 29 | |
29 | 30 | } |
30 | 31 | |
@@ -35,8 +36,9 @@ discard block |
||
35 | 36 | |
36 | 37 | public function save() |
37 | 38 | { |
38 | - if($this->operator()->operator_id() !== $this->form_model->operator_id()) |
|
39 | - $this->authorize('group_admin'); |
|
39 | + if($this->operator()->operator_id() !== $this->form_model->operator_id()) { |
|
40 | + $this->authorize('group_admin'); |
|
41 | + } |
|
40 | 42 | |
41 | 43 | parent::save(); |
42 | 44 | } |
@@ -71,15 +73,15 @@ discard block |
||
71 | 73 | parent::authorize('group_admin'); |
72 | 74 | |
73 | 75 | $operator = Operator::one($this->router()->params()); |
74 | - if($operator->username() == $this->operator()->username()) |
|
75 | - throw new AccessRefusedException(); |
|
76 | + if($operator->username() == $this->operator()->username()) { |
|
77 | + throw new AccessRefusedException(); |
|
78 | + } |
|
76 | 79 | |
77 | 80 | if(Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) |
78 | 81 | { |
79 | 82 | $confirmation_message = $operator->is_active() ? 'KADRO_operator_DISABLED' : 'KADRO_operator_ENABLED'; |
80 | 83 | $this->logger()->nice(L($confirmation_message, [$operator->name()])); |
81 | - } |
|
82 | - else |
|
84 | + } else |
|
83 | 85 | { |
84 | 86 | $this->logger()->warning(L('CRUDITES_ERR_QUERY_FAILED')); |
85 | 87 | } |
@@ -92,8 +94,9 @@ discard block |
||
92 | 94 | parent::authorize('group_admin'); |
93 | 95 | |
94 | 96 | $operator = Operator::one(['username' => $this->router()->params('username')]); |
95 | - if($operator->username() == $this->operator()->username()) |
|
96 | - throw new AccessRefusedException(); |
|
97 | + if($operator->username() == $this->operator()->username()) { |
|
98 | + throw new AccessRefusedException(); |
|
99 | + } |
|
97 | 100 | |
98 | 101 | $permission_id = $this->router()->params('permission_id'); |
99 | 102 | |
@@ -103,8 +106,7 @@ discard block |
||
103 | 106 | { |
104 | 107 | $row = ACL::table()->produce($row_data); |
105 | 108 | $res = $row->persist(); |
106 | - } |
|
107 | - else |
|
109 | + } else |
|
108 | 110 | { |
109 | 111 | $row->wipe(); |
110 | 112 | } |
@@ -34,9 +34,12 @@ discard block |
||
34 | 34 | { |
35 | 35 | $res = $this->$chainling(); |
36 | 36 | |
37 | - if($this->logger()->has_halting_messages()) // logger handled a critical error during the chailing execution |
|
37 | + if($this->logger()->has_halting_messages()) { |
|
38 | + // logger handled a critical error during the chailing execution |
|
38 | 39 | { |
39 | - break; // dont go on with other |
|
40 | + break; |
|
41 | + } |
|
42 | + // dont go on with other |
|
40 | 43 | } |
41 | 44 | |
42 | 45 | if($chainling === $method) |
@@ -47,19 +50,23 @@ discard block |
||
47 | 50 | } |
48 | 51 | } |
49 | 52 | |
50 | - if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages |
|
53 | + if(method_exists($this, 'conclude')) { |
|
54 | + // conclude always executed, even with has_halting_messages |
|
51 | 55 | $this->conclude(); |
56 | + } |
|
52 | 57 | |
53 | - if(method_exists($this, 'display')) |
|
54 | - $template = $this->display($custom_template); |
|
58 | + if(method_exists($this, 'display')) { |
|
59 | + $template = $this->display($custom_template); |
|
60 | + } |
|
55 | 61 | } |
56 | 62 | |
57 | 63 | public function prepare() |
58 | 64 | { |
59 | 65 | parent::prepare(); |
60 | 66 | |
61 | - if(!class_exists($this->model_class_name = $this->class_name())) |
|
62 | - throw new \Exception("!class_exists($this->model_class_name)"); |
|
67 | + if(!class_exists($this->model_class_name = $this->class_name())) { |
|
68 | + throw new \Exception("!class_exists($this->model_class_name)"); |
|
69 | + } |
|
63 | 70 | |
64 | 71 | $this->model_type = $this->model_class_name::model_type(); |
65 | 72 | |
@@ -74,17 +81,18 @@ discard block |
||
74 | 81 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->submitted()); |
75 | 82 | |
76 | 83 | $this->load_model = $this->model_class_name::exists($pk_values); |
77 | - } |
|
78 | - elseif($this->router()->requests()) |
|
84 | + } elseif($this->router()->requests()) |
|
79 | 85 | { |
80 | 86 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->params()); |
81 | 87 | |
82 | - if(!is_null($this->load_model = $this->model_class_name::exists($pk_values))) |
|
83 | - $this->form_model = clone $this->load_model; |
|
88 | + if(!is_null($this->load_model = $this->model_class_name::exists($pk_values))) { |
|
89 | + $this->form_model = clone $this->load_model; |
|
90 | + } |
|
84 | 91 | } |
85 | 92 | |
86 | - if(!is_null($this->load_model) && is_subclass_of($this->load_model, '\HexMakina\Crudites\Interfaces\TraceableInterface') && $this->load_model->traceable()) |
|
87 | - $this->viewport('load_model_history', $this->tracer()->traces_by_model($this->load_model)); |
|
93 | + if(!is_null($this->load_model) && is_subclass_of($this->load_model, '\HexMakina\Crudites\Interfaces\TraceableInterface') && $this->load_model->traceable()) { |
|
94 | + $this->viewport('load_model_history', $this->tracer()->traces_by_model($this->load_model)); |
|
95 | + } |
|
88 | 96 | } |
89 | 97 | |
90 | 98 | public function has_load_model() |
@@ -112,8 +120,9 @@ discard block |
||
112 | 120 | $this->logger()->nice(L('CRUDITES_INSTANCE_ALTERED', ['MODEL_'.get_class($model)::model_type().'_INSTANCE'])); |
113 | 121 | return $model; |
114 | 122 | } |
115 | - foreach($this->errors() as $field => $error_msg) |
|
116 | - $this->logger()->warning(L($error_msg, [$field])); |
|
123 | + foreach($this->errors() as $field => $error_msg) { |
|
124 | + $this->logger()->warning(L($error_msg, [$field])); |
|
125 | + } |
|
117 | 126 | |
118 | 127 | return null; |
119 | 128 | } |
@@ -127,8 +136,12 @@ discard block |
||
127 | 136 | { |
128 | 137 | $class_name = is_null($model) ? $this->model_class_name : get_class($model); |
129 | 138 | |
130 | - if(!isset($filters['date_start'])) $filters['date_start'] = $this->box('StateAgent')->filters('date_start'); |
|
131 | - if(!isset($filters['date_stop'])) $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop'); |
|
139 | + if(!isset($filters['date_start'])) { |
|
140 | + $filters['date_start'] = $this->box('StateAgent')->filters('date_start'); |
|
141 | + } |
|
142 | + if(!isset($filters['date_stop'])) { |
|
143 | + $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop'); |
|
144 | + } |
|
132 | 145 | |
133 | 146 | // dd($filters); |
134 | 147 | $listing = $class_name::filter($filters); |
@@ -144,15 +157,16 @@ discard block |
||
144 | 157 | foreach($class_name::table()->columns() as $column) |
145 | 158 | { |
146 | 159 | |
147 | - if(!$column->is_auto_incremented() && !$column->is_hidden()) |
|
148 | - $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name())); |
|
160 | + if(!$column->is_auto_incremented() && !$column->is_hidden()) { |
|
161 | + $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name())); |
|
162 | + } |
|
149 | 163 | } |
150 | - } |
|
151 | - else |
|
164 | + } else |
|
152 | 165 | { |
153 | 166 | $current = current($listing); |
154 | - if(is_object($current)) |
|
155 | - $current = get_object_vars($current); |
|
167 | + if(is_object($current)) { |
|
168 | + $current = get_object_vars($current); |
|
169 | + } |
|
156 | 170 | |
157 | 171 | foreach(array_keys($current) as $field) |
158 | 172 | { |
@@ -184,9 +198,9 @@ discard block |
||
184 | 198 | { |
185 | 199 | $model = $this->persist_model($this->form_model); |
186 | 200 | |
187 | - if(empty($this->errors())) |
|
188 | - $this->route_back($model); |
|
189 | - else |
|
201 | + if(empty($this->errors())) { |
|
202 | + $this->route_back($model); |
|
203 | + } else |
|
190 | 204 | { |
191 | 205 | $this->edit(); |
192 | 206 | return 'edit'; |
@@ -226,8 +240,7 @@ discard block |
||
226 | 240 | { |
227 | 241 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE'])); |
228 | 242 | $this->router()->hop($this->model_type); |
229 | - } |
|
230 | - elseif($this->load_model->immortal()) |
|
243 | + } elseif($this->load_model->immortal()) |
|
231 | 244 | { |
232 | 245 | |
233 | 246 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_IS_IMMORTAL', ['MODEL_'.$this->model_type.'_INSTANCE'])); |
@@ -237,15 +250,15 @@ discard block |
||
237 | 250 | |
238 | 251 | public function destroy() |
239 | 252 | { |
240 | - if(!$this->router()->submits()) |
|
241 | - throw new \Exception('KADRO_ROUTER_MUST_SUBMIT'); |
|
253 | + if(!$this->router()->submits()) { |
|
254 | + throw new \Exception('KADRO_ROUTER_MUST_SUBMIT'); |
|
255 | + } |
|
242 | 256 | |
243 | 257 | if($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
244 | 258 | { |
245 | 259 | $this->logger()->info(L('CRUDITES_ERR_INSTANCE_IS_UNDELETABLE', [''.$this->load_model])); |
246 | 260 | $this->route_back($this->load_model); |
247 | - } |
|
248 | - else |
|
261 | + } else |
|
249 | 262 | { |
250 | 263 | $this->logger()->nice(L('CRUDITES_INSTANCE_DESTROYED', ['MODEL_'.$this->model_type.'_INSTANCE'])); |
251 | 264 | $this->route_back($this->model_type); |
@@ -263,11 +276,13 @@ discard block |
||
263 | 276 | |
264 | 277 | $this->viewport('form_model_type', $this->model_type); |
265 | 278 | |
266 | - if(isset($this->load_model)) |
|
267 | - $this->viewport('load_model', $this->load_model); |
|
279 | + if(isset($this->load_model)) { |
|
280 | + $this->viewport('load_model', $this->load_model); |
|
281 | + } |
|
268 | 282 | |
269 | - if(isset($this->form_model)) |
|
270 | - $this->viewport('form_model', $this->form_model); |
|
283 | + if(isset($this->form_model)) { |
|
284 | + $this->viewport('form_model', $this->form_model); |
|
285 | + } |
|
271 | 286 | } |
272 | 287 | |
273 | 288 | public function collection_to_csv($collection, $filename) |
@@ -325,9 +340,9 @@ discard block |
||
325 | 340 | $route_params = []; |
326 | 341 | |
327 | 342 | $route_name = get_class($model)::model_type().'_'; |
328 | - if($model->is_new()) |
|
329 | - $route_name.= 'new'; |
|
330 | - else |
|
343 | + if($model->is_new()) { |
|
344 | + $route_name.= 'new'; |
|
345 | + } else |
|
331 | 346 | { |
332 | 347 | $route_name.= 'default'; |
333 | 348 | $route_params = ['id' => $model->get_id()]; |
@@ -338,11 +353,13 @@ discard block |
||
338 | 353 | |
339 | 354 | public function route_factory($route=null, $route_params=[]) : string |
340 | 355 | { |
341 | - if(is_null($route) && $this->router()->submits()) |
|
342 | - $route = $this->form_model; |
|
356 | + if(is_null($route) && $this->router()->submits()) { |
|
357 | + $route = $this->form_model; |
|
358 | + } |
|
343 | 359 | |
344 | - if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
345 | - $route = $this->route_model($route); |
|
360 | + if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) { |
|
361 | + $route = $this->route_model($route); |
|
362 | + } |
|
346 | 363 | |
347 | 364 | return parent::route_factory($route, $route_params); |
348 | 365 | } |
@@ -18,8 +18,9 @@ discard block |
||
18 | 18 | public function welcome(OperatorInterface $operator) |
19 | 19 | { |
20 | 20 | |
21 | - if($this->router()->name() === 'identify') |
|
22 | - $this->identify($operator); |
|
21 | + if($this->router()->name() === 'identify') { |
|
22 | + $this->identify($operator); |
|
23 | + } |
|
23 | 24 | |
24 | 25 | $Controller = $this->router()->target_controller(); |
25 | 26 | $Controller = $this->box($Controller); |
@@ -27,8 +28,9 @@ discard block |
||
27 | 28 | |
28 | 29 | if($Controller->requires_operator()) |
29 | 30 | { |
30 | - if(is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) |
|
31 | - $this->router()->hop('checkin'); |
|
31 | + if(is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) { |
|
32 | + $this->router()->hop('checkin'); |
|
33 | + } |
|
32 | 34 | |
33 | 35 | if(!$operator->is_active()) |
34 | 36 | { |
@@ -62,11 +64,13 @@ discard block |
||
62 | 64 | |
63 | 65 | $operator = get_class($op)::exists(['username' => $username]); |
64 | 66 | |
65 | - if(is_null($operator) || !$operator->is_active()) |
|
66 | - throw new \Exception('ERR_DISABLED'); |
|
67 | + if(is_null($operator) || !$operator->is_active()) { |
|
68 | + throw new \Exception('ERR_DISABLED'); |
|
69 | + } |
|
67 | 70 | |
68 | - if(!$operator->password_verify($password)) |
|
69 | - throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
|
71 | + if(!$operator->password_verify($password)) { |
|
72 | + throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
|
73 | + } |
|
70 | 74 | |
71 | 75 | $this->box('StateAgent')->operator_id($operator->get_id()); |
72 | 76 | $this->logger()->nice(L('PAGE_CHECKIN_WELCOME', [$operator->name()])); |
@@ -92,8 +92,9 @@ discard block |
||
92 | 92 | //--------------------------------------------------------------- ŝablonoj |
93 | 93 | require_once 'smarty/smarty/libs/Smarty.class.php'; |
94 | 94 | // Load smarty template parser |
95 | - if(is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path'))) |
|
96 | - throw new \Exception("SMARTY CONFIG ERROR: missing parameters"); |
|
95 | + if(is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path'))) { |
|
96 | + throw new \Exception("SMARTY CONFIG ERROR: missing parameters"); |
|
97 | + } |
|
97 | 98 | |
98 | 99 | $smarty=new \Smarty(); |
99 | 100 | $box->register('template_engine', $smarty); |
@@ -124,7 +125,8 @@ discard block |
||
124 | 125 | $lezer->init(); |
125 | 126 | |
126 | 127 | $smarty->assign('language', $language); |
127 | - if($cookies_enabled === true) |
|
128 | - setcookie('lang', $language, time()+(365 * 24 * 60 * 60), "/", ""); |
|
128 | + if($cookies_enabled === true) { |
|
129 | + setcookie('lang', $language, time()+(365 * 24 * 60 * 60), "/", ""); |
|
130 | + } |
|
129 | 131 | |
130 | 132 | } |
@@ -11,18 +11,16 @@ discard block |
||
11 | 11 | if(property_exists($this, 'permission_names')) |
12 | 12 | { |
13 | 13 | return explode(',', $this->permission_names); |
14 | - } |
|
15 | - elseif(property_exists($this, 'permission_ids')) |
|
14 | + } elseif(property_exists($this, 'permission_ids')) |
|
16 | 15 | { |
17 | 16 | $ids = explode(',', $this->permission_ids); |
18 | 17 | $ret = []; |
19 | 18 | $permissions = Permission::get_many_by_AIPK($ids); |
20 | - foreach($permissions as $id => $p) |
|
21 | - $ret[]="$p"; |
|
19 | + foreach($permissions as $id => $p) { |
|
20 | + $ret[]="$p"; |
|
21 | + } |
|
22 | 22 | return $ret; |
23 | - } |
|
24 | - |
|
25 | - else |
|
23 | + } else |
|
26 | 24 | { |
27 | 25 | return ACL::permissions_names_for($this); |
28 | 26 | } |
@@ -31,21 +29,20 @@ discard block |
||
31 | 29 | public function permissions() |
32 | 30 | { |
33 | 31 | |
34 | - if(!is_null($this->permissions)) |
|
35 | - return $this->permissions; |
|
32 | + if(!is_null($this->permissions)) { |
|
33 | + return $this->permissions; |
|
34 | + } |
|
36 | 35 | $permission_unique_keys = null; |
37 | 36 | if(property_exists($this, 'permission_names')) |
38 | 37 | { |
39 | 38 | $permission_unique_keys = explode(',', $this->permission_names); |
40 | 39 | // vd(Permission::table()->select()); |
41 | 40 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_string_in('name', $permission_unique_keys)); |
42 | - } |
|
43 | - elseif(property_exists($this, 'permission_ids')) |
|
41 | + } elseif(property_exists($this, 'permission_ids')) |
|
44 | 42 | { |
45 | 43 | $permission_unique_keys = explode(',', $this->permission_ids); |
46 | 44 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_numeric_in('id', $permission_unique_keys)); |
47 | - } |
|
48 | - else |
|
45 | + } else |
|
49 | 46 | { |
50 | 47 | $this->permissions = ACL::permissions_for($this); |
51 | 48 | } |
@@ -56,39 +53,36 @@ discard block |
||
56 | 53 | public function has_permission($p) : bool |
57 | 54 | { |
58 | 55 | // new instances or inactive operators, none shall pass |
59 | - if($this->is_new() === true || $this->is_active() === false) |
|
60 | - return false; |
|
56 | + if($this->is_new() === true || $this->is_active() === false) { |
|
57 | + return false; |
|
58 | + } |
|
61 | 59 | |
62 | 60 | $permission_name = $permission_id = null; |
63 | 61 | if(is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
64 | 62 | { |
65 | 63 | $permission_name = $p->get('name'); |
66 | 64 | $permission_id = $p->get_id(); |
65 | + } elseif(preg_match('/[0-9]+/', $p)) { |
|
66 | + $permission_id = $p; |
|
67 | + } else { |
|
68 | + $permission_name = $p; |
|
67 | 69 | } |
68 | - elseif(preg_match('/[0-9]+/', $p)) |
|
69 | - $permission_id = $p; |
|
70 | - else |
|
71 | - $permission_name = $p; |
|
72 | 70 | |
73 | 71 | if(!is_null($this->get('permission_names')) && !is_null($permission_name)) |
74 | 72 | { |
75 | 73 | return strpos($this->get('permission_names'), $permission_name) !== false; |
76 | - } |
|
77 | - elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
74 | + } elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
78 | 75 | { |
79 | 76 | return strpos($this->get('permission_ids'), $permission_id) !== false; |
80 | - } |
|
81 | - elseif(!is_null($permission_name)) |
|
77 | + } elseif(!is_null($permission_name)) |
|
82 | 78 | { |
83 | 79 | if(method_exists($this, $permission_name) && $this->$permission_name() == true) |
84 | 80 | { |
85 | 81 | return true; |
86 | - } |
|
87 | - elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
82 | + } elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
88 | 83 | { |
89 | 84 | return true; |
90 | - } |
|
91 | - elseif(ACL::match($this, $permission_name) === true) |
|
85 | + } elseif(ACL::match($this, $permission_name) === true) |
|
92 | 86 | { |
93 | 87 | return true; |
94 | 88 | } |