@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | |
14 | 14 | class LogLaddy implements LoggerInterface |
15 | 15 | { |
16 | - use \Psr\Log\LoggerTrait; // PSR implementation |
|
17 | - use \HexMakina\Debugger\Debugger; // Debugger |
|
16 | + use \Psr\Log\LoggerTrait; // PSR implementation |
|
17 | + use \HexMakina\Debugger\Debugger; // Debugger |
|
18 | 18 | |
19 | 19 | const REPORTING_USER = 'user_messages'; |
20 | 20 | const INTERNAL_ERROR = 'error'; |
@@ -55,9 +55,9 @@ 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') |
|
58 | + if (is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
59 | 59 | (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
60 | - elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
60 | + elseif (is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
61 | 61 | (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
62 | 62 | else |
63 | 63 | { |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | public function system_halted($level) |
70 | 70 | { |
71 | - switch($level) |
|
71 | + switch ($level) |
|
72 | 72 | { |
73 | 73 | case LogLevel::ERROR: |
74 | 74 | case LogLevel::CRITICAL: |
@@ -86,19 +86,19 @@ discard block |
||
86 | 86 | $display_error = null; |
87 | 87 | |
88 | 88 | // --- Handles Throwables (exception_handler()) |
89 | - if($message==self::INTERNAL_ERROR || $message== self::USER_EXCEPTION) |
|
89 | + if ($message == self::INTERNAL_ERROR || $message == self::USER_EXCEPTION) |
|
90 | 90 | { |
91 | 91 | $this->has_halting_messages = true; |
92 | 92 | $display_error = self::format_throwable_message($context['class'], $context['code'], $context['file'], $context['line'], $context['text']); |
93 | 93 | error_log($display_error); |
94 | - $display_error.= self::format_trace($context['trace'], false); |
|
94 | + $display_error .= self::format_trace($context['trace'], false); |
|
95 | 95 | self::HTTP_500($display_error); |
96 | 96 | } |
97 | - elseif($this->system_halted($level)) // analyses error level |
|
97 | + elseif ($this->system_halted($level)) // 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 | error_log($display_error); |
101 | - $display_error.= self::format_trace($context['trace'], true); |
|
101 | + $display_error .= self::format_trace($context['trace'], true); |
|
102 | 102 | self::HTTP_500($display_error); |
103 | 103 | } |
104 | 104 | else |
@@ -128,10 +128,10 @@ 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])) |
|
131 | + if (!isset($_SESSION[self::REPORTING_USER])) |
|
132 | 132 | $_SESSION[self::REPORTING_USER] = []; |
133 | 133 | |
134 | - if(!isset($_SESSION[self::REPORTING_USER][$level])) |
|
134 | + if (!isset($_SESSION[self::REPORTING_USER][$level])) |
|
135 | 135 | $_SESSION[self::REPORTING_USER][$level] = []; |
136 | 136 | |
137 | 137 | $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
@@ -163,21 +163,21 @@ discard block |
||
163 | 163 | private static function map_error_level_to_log_level($level) : string |
164 | 164 | { |
165 | 165 | // http://php.net/manual/en/errorfunc.constants.php |
166 | - $m=[]; |
|
166 | + $m = []; |
|
167 | 167 | |
168 | - $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT; |
|
169 | - $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT; |
|
168 | + $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT; |
|
169 | + $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT; |
|
170 | 170 | |
171 | - $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL; |
|
172 | - $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL; |
|
171 | + $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL; |
|
172 | + $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL; |
|
173 | 173 | |
174 | - $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR; |
|
175 | - $m[8]=$m[1024]=LogLevel::ERROR; |
|
174 | + $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR; |
|
175 | + $m[8] = $m[1024] = LogLevel::ERROR; |
|
176 | 176 | |
177 | - $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
|
178 | - $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
|
177 | + $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG; |
|
178 | + $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG; |
|
179 | 179 | |
180 | - if(isset($m[$level])) |
|
180 | + if (isset($m[$level])) |
|
181 | 181 | return $m[$level]; |
182 | 182 | |
183 | 183 | throw new \Exception(__FUNCTION__."($level): $level is unknown"); |
@@ -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 | } |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | return $this->router()->prehop('traduko'); |
20 | 20 | } |
21 | 21 | |
22 | - public function update_file($lang='fra') |
|
22 | + public function update_file($lang = 'fra') |
|
23 | 23 | { |
24 | - try{ |
|
24 | + try { |
|
25 | 25 | $locale_path = $this->box('settings.locale.directory_path').'/'.$this->box('settings.locale.file_name'); |
26 | 26 | self::create_file($locale_path, $lang); |
27 | 27 | |
28 | 28 | $this->logger()->nice(L('KADRO_SYSTEM_FILE_UPDATED')); |
29 | 29 | } |
30 | - catch(\Exception $e) |
|
30 | + catch (\Exception $e) |
|
31 | 31 | { |
32 | 32 | $this->logger()->notice(L('KADRO_SYSTEM_FILE_UPDATED')); |
33 | 33 | } |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | { |
39 | 39 | $res = Traduko::filter(['lang' => $lang]); |
40 | 40 | $assoc = []; |
41 | - foreach($res as $id => $trad) |
|
41 | + foreach ($res as $id => $trad) |
|
42 | 42 | { |
43 | - if(!isset($assoc[$trad->kategorio])) |
|
43 | + if (!isset($assoc[$trad->kategorio])) |
|
44 | 44 | $assoc[$trad->kategorio] = []; |
45 | - if(!isset($assoc[$trad->kategorio][$trad->sekcio])) |
|
45 | + if (!isset($assoc[$trad->kategorio][$trad->sekcio])) |
|
46 | 46 | $assoc[$trad->kategorio][$trad->sekcio] = []; |
47 | 47 | |
48 | 48 | $assoc[$trad->kategorio][$trad->sekcio][$trad->referenco] = $trad->$lang; |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | public static function init($locale_path) |
58 | 58 | { |
59 | 59 | $languages = array_keys(array_slice(Traduko::inspect(Traduko::table_name())->columns(), 4)); |
60 | - foreach($languages as $l) |
|
61 | - self::create_file($locale_path,$l); |
|
60 | + foreach ($languages as $l) |
|
61 | + self::create_file($locale_path, $l); |
|
62 | 62 | |
63 | 63 | return $languages; |
64 | 64 | } |
@@ -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 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | namespace HexMakina\kadro\Controllers; |
13 | 13 | |
14 | 14 | use \HexMakina\Crudites\Crudites; |
15 | -use \HexMakina\kadro\Auth\{Operator,OperatorInterface,ACL,AccessRefusedException}; |
|
15 | +use \HexMakina\kadro\Auth\{Operator, OperatorInterface, ACL, AccessRefusedException}; |
|
16 | 16 | |
17 | 17 | |
18 | 18 | class OperatorController extends \HexMakina\kadro\Controllers\ORMController |
@@ -23,7 +23,7 @@ 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()) |
|
26 | + if (is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) |
|
27 | 27 | $this->authorize('group_admin'); |
28 | 28 | |
29 | 29 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | public function save() |
37 | 37 | { |
38 | - if($this->operator()->operator_id() !== $this->form_model->operator_id()) |
|
38 | + if ($this->operator()->operator_id() !== $this->form_model->operator_id()) |
|
39 | 39 | $this->authorize('group_admin'); |
40 | 40 | |
41 | 41 | parent::save(); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function before_save() : array |
45 | 45 | { |
46 | 46 | //------------------------------------------------------------- PASSWORDS |
47 | - if($this->form_model->get('password') != $this->form_model->get('password_verification')) |
|
47 | + if ($this->form_model->get('password') != $this->form_model->get('password_verification')) |
|
48 | 48 | { |
49 | 49 | $this->logger()->warning(L('KADRO_operator_ERR_PASSWORDS_MISMATCH')); |
50 | 50 | return $this->edit(); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function dashboard() |
59 | 59 | { |
60 | 60 | $real_operator_class = get_class($this->operator()); |
61 | - $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null,'username', 'ASC']])); |
|
61 | + $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null, 'username', 'ASC']])); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function destroy() |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | parent::authorize('group_admin'); |
72 | 72 | |
73 | 73 | $operator = Operator::one($this->router()->params()); |
74 | - if($operator->username() == $this->operator()->username()) |
|
74 | + if ($operator->username() == $this->operator()->username()) |
|
75 | 75 | throw new AccessRefusedException(); |
76 | 76 | |
77 | - if(Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) |
|
77 | + if (Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) |
|
78 | 78 | { |
79 | 79 | $confirmation_message = $operator->is_active() ? 'KADRO_operator_DISABLED' : 'KADRO_operator_ENABLED'; |
80 | 80 | $this->logger()->nice(L($confirmation_message, [$operator->name()])); |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | parent::authorize('group_admin'); |
93 | 93 | |
94 | 94 | $operator = Operator::one(['username' => $this->router()->params('username')]); |
95 | - if($operator->username() == $this->operator()->username()) |
|
95 | + if ($operator->username() == $this->operator()->username()) |
|
96 | 96 | throw new AccessRefusedException(); |
97 | 97 | |
98 | 98 | $permission_id = $this->router()->params('permission_id'); |
99 | 99 | |
100 | 100 | $row_data = ['operator_id' => $operator->operator_id(), 'permission_id' => $permission_id]; |
101 | 101 | $row = ACL::table()->restore($row_data); |
102 | - if($row->is_new()) |
|
102 | + if ($row->is_new()) |
|
103 | 103 | { |
104 | 104 | $row = ACL::table()->produce($row_data); |
105 | 105 | $res = $row->persist(); |
@@ -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 | } |
@@ -27,19 +27,19 @@ discard block |
||
27 | 27 | $custom_template = null; |
28 | 28 | $method = $this->router()->target_method(); |
29 | 29 | |
30 | - foreach(['prepare', "before_$method", $method, "after_$method"] as $step => $chainling) |
|
30 | + foreach (['prepare', "before_$method", $method, "after_$method"] as $step => $chainling) |
|
31 | 31 | { |
32 | 32 | $this->search_and_execute_trait_methods($chainling); |
33 | - if(method_exists($this, $chainling) && empty($this->errors())) |
|
33 | + if (method_exists($this, $chainling) && empty($this->errors())) |
|
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()) // logger handled a critical error during the chailing execution |
|
38 | 38 | { |
39 | 39 | break; // dont go on with other |
40 | 40 | } |
41 | 41 | |
42 | - if($chainling === $method) |
|
42 | + if ($chainling === $method) |
|
43 | 43 | { |
44 | 44 | |
45 | 45 | $custom_template = $res; |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages |
|
50 | + if (method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages |
|
51 | 51 | $this->conclude(); |
52 | 52 | |
53 | - if(method_exists($this, 'display')) |
|
53 | + if (method_exists($this, 'display')) |
|
54 | 54 | $template = $this->display($custom_template); |
55 | 55 | } |
56 | 56 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | parent::prepare(); |
60 | 60 | |
61 | - if(!class_exists($this->model_class_name = $this->class_name())) |
|
61 | + if (!class_exists($this->model_class_name = $this->class_name())) |
|
62 | 62 | throw new \Exception("!class_exists($this->model_class_name)"); |
63 | 63 | |
64 | 64 | $this->model_type = $this->model_class_name::model_type(); |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | |
69 | 69 | $pk_values = []; |
70 | 70 | |
71 | - if($this->router()->submits()) |
|
71 | + if ($this->router()->submits()) |
|
72 | 72 | { |
73 | 73 | $this->form_model->import($this->sanitize_post_data($this->router()->submitted())); |
74 | 74 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->submitted()); |
75 | 75 | |
76 | 76 | $this->load_model = $this->model_class_name::exists($pk_values); |
77 | 77 | } |
78 | - elseif($this->router()->requests()) |
|
78 | + elseif ($this->router()->requests()) |
|
79 | 79 | { |
80 | 80 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->params()); |
81 | 81 | |
82 | - if(!is_null($this->load_model = $this->model_class_name::exists($pk_values))) |
|
82 | + if (!is_null($this->load_model = $this->model_class_name::exists($pk_values))) |
|
83 | 83 | $this->form_model = clone $this->load_model; |
84 | 84 | } |
85 | 85 | |
86 | - if(!is_null($this->load_model) && is_subclass_of($this->load_model, '\HexMakina\Crudites\Interfaces\TraceableInterface') && $this->load_model->traceable()) |
|
86 | + if (!is_null($this->load_model) && is_subclass_of($this->load_model, '\HexMakina\Crudites\Interfaces\TraceableInterface') && $this->load_model->traceable()) |
|
87 | 87 | $this->viewport('load_model_history', $this->tracer()->traces_by_model($this->load_model)); |
88 | 88 | } |
89 | 89 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | // ----------- META ----------- |
95 | 95 | public function class_name() : string |
96 | 96 | { |
97 | - if(is_null($this->model_class_name)) |
|
97 | + if (is_null($this->model_class_name)) |
|
98 | 98 | { |
99 | 99 | $this->model_class_name = get_called_class(); |
100 | 100 | $this->model_class_name = str_replace('\Controllers\\', '\Models\\', $this->model_class_name); |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | public function persist_model($model) : ?ModelInterface |
108 | 108 | { |
109 | 109 | $this->errors = $model->save($this->operator()->operator_id(), $this->tracer()); // returns [errors] |
110 | - if(empty($this->errors())) |
|
110 | + if (empty($this->errors())) |
|
111 | 111 | { |
112 | 112 | $this->logger()->nice(L('CRUDITES_INSTANCE_ALTERED', ['MODEL_'.get_class($model)::model_type().'_INSTANCE'])); |
113 | 113 | return $model; |
114 | 114 | } |
115 | - foreach($this->errors() as $field => $error_msg) |
|
115 | + foreach ($this->errors() as $field => $error_msg) |
|
116 | 116 | $this->logger()->warning(L($error_msg, [$field])); |
117 | 117 | |
118 | 118 | return null; |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | return $this->listing(); //default dashboard is a listing |
124 | 124 | } |
125 | 125 | |
126 | - public function listing($model=null,$filters=[],$options=[]) |
|
126 | + public function listing($model = null, $filters = [], $options = []) |
|
127 | 127 | { |
128 | 128 | $class_name = is_null($model) ? $this->model_class_name : get_class($model); |
129 | 129 | |
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'); |
|
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'); |
|
132 | 132 | |
133 | 133 | // dd($filters); |
134 | 134 | $listing = $class_name::filter($filters); |
@@ -139,24 +139,24 @@ discard block |
||
139 | 139 | public function viewport_listing($class_name, $listing, $listing_template) |
140 | 140 | { |
141 | 141 | $listing_fields = []; |
142 | - if(empty($listing)) |
|
142 | + if (empty($listing)) |
|
143 | 143 | { |
144 | - foreach($class_name::table()->columns() as $column) |
|
144 | + foreach ($class_name::table()->columns() as $column) |
|
145 | 145 | { |
146 | 146 | |
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())); |
|
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())); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | else |
152 | 152 | { |
153 | 153 | $current = current($listing); |
154 | - if(is_object($current)) |
|
154 | + if (is_object($current)) |
|
155 | 155 | $current = get_object_vars($current); |
156 | 156 | |
157 | - foreach(array_keys($current) as $field) |
|
157 | + foreach (array_keys($current) as $field) |
|
158 | 158 | { |
159 | - $listing_fields[$field]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field)); |
|
159 | + $listing_fields[$field] = L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field)); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | } |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | $this->edit(); |
179 | 179 | } |
180 | 180 | |
181 | - public function edit(){} |
|
181 | + public function edit() {} |
|
182 | 182 | |
183 | 183 | public function save() |
184 | 184 | { |
185 | 185 | $model = $this->persist_model($this->form_model); |
186 | 186 | |
187 | - if(empty($this->errors())) |
|
187 | + if (empty($this->errors())) |
|
188 | 188 | $this->route_back($model); |
189 | 189 | else |
190 | 190 | { |
@@ -195,21 +195,21 @@ discard block |
||
195 | 195 | |
196 | 196 | public function before_edit() |
197 | 197 | { |
198 | - if(!is_null($this->router()->params('id')) && is_null($this->load_model)) |
|
198 | + if (!is_null($this->router()->params('id')) && is_null($this->load_model)) |
|
199 | 199 | { |
200 | 200 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_class_name::model_type().'_INSTANCE'])); |
201 | 201 | $this->router()->hop($this->model_class_name::model_type()); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - public function before_save() : array { return [];} |
|
205 | + public function before_save() : array { return []; } |
|
206 | 206 | |
207 | 207 | // default: hop to altered object |
208 | - public function after_save() {$this->router()->hop($this->route_back());} |
|
208 | + public function after_save() {$this->router()->hop($this->route_back()); } |
|
209 | 209 | |
210 | 210 | public function destroy_confirm() |
211 | 211 | { |
212 | - if(is_null($this->load_model)) |
|
212 | + if (is_null($this->load_model)) |
|
213 | 213 | { |
214 | 214 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE'])); |
215 | 215 | $this->router()->hop($this->model_type); |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | |
223 | 223 | public function before_destroy() // default: checks for load_model and immortality, hops back to object on failure |
224 | 224 | { |
225 | - if(is_null($this->load_model)) |
|
225 | + if (is_null($this->load_model)) |
|
226 | 226 | { |
227 | 227 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE'])); |
228 | 228 | $this->router()->hop($this->model_type); |
229 | 229 | } |
230 | - elseif($this->load_model->immortal()) |
|
230 | + elseif ($this->load_model->immortal()) |
|
231 | 231 | { |
232 | 232 | |
233 | 233 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_IS_IMMORTAL', ['MODEL_'.$this->model_type.'_INSTANCE'])); |
@@ -237,10 +237,10 @@ discard block |
||
237 | 237 | |
238 | 238 | public function destroy() |
239 | 239 | { |
240 | - if(!$this->router()->submits()) |
|
240 | + if (!$this->router()->submits()) |
|
241 | 241 | throw new \Exception('KADRO_ROUTER_MUST_SUBMIT'); |
242 | 242 | |
243 | - if($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
|
243 | + if ($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
|
244 | 244 | { |
245 | 245 | $this->logger()->info(L('CRUDITES_ERR_INSTANCE_IS_UNDELETABLE', [''.$this->load_model])); |
246 | 246 | $this->route_back($this->load_model); |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | |
264 | 264 | $this->viewport('form_model_type', $this->model_type); |
265 | 265 | |
266 | - if(isset($this->load_model)) |
|
266 | + if (isset($this->load_model)) |
|
267 | 267 | $this->viewport('load_model', $this->load_model); |
268 | 268 | |
269 | - if(isset($this->form_model)) |
|
269 | + if (isset($this->form_model)) |
|
270 | 270 | $this->viewport('form_model', $this->form_model); |
271 | 271 | } |
272 | 272 | |
@@ -278,15 +278,15 @@ discard block |
||
278 | 278 | |
279 | 279 | $header = false; |
280 | 280 | |
281 | - foreach($collection as $line) |
|
281 | + foreach ($collection as $line) |
|
282 | 282 | { |
283 | 283 | $line = get_object_vars($line); |
284 | - if($header === false) |
|
284 | + if ($header === false) |
|
285 | 285 | { |
286 | - fputcsv($fp,array_keys($line)); |
|
286 | + fputcsv($fp, array_keys($line)); |
|
287 | 287 | $header = true; |
288 | 288 | } |
289 | - fputcsv($fp,$line); |
|
289 | + fputcsv($fp, $line); |
|
290 | 290 | } |
291 | 291 | fclose($fp); |
292 | 292 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | public function export() |
297 | 297 | { |
298 | 298 | $format = $this->router()->params('format'); |
299 | - switch($format) |
|
299 | + switch ($format) |
|
300 | 300 | { |
301 | 301 | case null: |
302 | 302 | $filename = $this->model_type; |
@@ -325,33 +325,33 @@ discard block |
||
325 | 325 | $route_params = []; |
326 | 326 | |
327 | 327 | $route_name = get_class($model)::model_type().'_'; |
328 | - if($model->is_new()) |
|
329 | - $route_name.= 'new'; |
|
328 | + if ($model->is_new()) |
|
329 | + $route_name .= 'new'; |
|
330 | 330 | else |
331 | 331 | { |
332 | - $route_name.= 'default'; |
|
332 | + $route_name .= 'default'; |
|
333 | 333 | $route_params = ['id' => $model->get_id()]; |
334 | 334 | } |
335 | 335 | $res = $this->router()->prehop($route_name, $route_params); |
336 | 336 | return $res; |
337 | 337 | } |
338 | 338 | |
339 | - public function route_factory($route=null, $route_params=[]) : string |
|
339 | + public function route_factory($route = null, $route_params = []) : string |
|
340 | 340 | { |
341 | - if(is_null($route) && $this->router()->submits()) |
|
341 | + if (is_null($route) && $this->router()->submits()) |
|
342 | 342 | $route = $this->form_model; |
343 | 343 | |
344 | - if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
344 | + if (!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
345 | 345 | $route = $this->route_model($route); |
346 | 346 | |
347 | 347 | return parent::route_factory($route, $route_params); |
348 | 348 | } |
349 | 349 | |
350 | - private function sanitize_post_data($post_data=[]) |
|
350 | + private function sanitize_post_data($post_data = []) |
|
351 | 351 | { |
352 | - foreach($this->model_class_name::table()->columns() as $col) |
|
352 | + foreach ($this->model_class_name::table()->columns() as $col) |
|
353 | 353 | { |
354 | - if($col->type()->is_boolean()) |
|
354 | + if ($col->type()->is_boolean()) |
|
355 | 355 | { |
356 | 356 | $post_data[$col->name()] = !empty($post_data[$col->name()]); |
357 | 357 | } |
@@ -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()])); |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | require APP_BASE.'vendor/autoload.php'; |
15 | 15 | |
16 | 16 | require 'PSR4Autoloader.class.php'; |
17 | - $loader=new PSR4Autoloader; |
|
17 | + $loader = new PSR4Autoloader; |
|
18 | 18 | $loader->register(); //Register loader with SPL autoloader stack. |
19 | 19 | |
20 | 20 | $loader->addNamespace('HexMakina', APP_BASE.'/lib/'); |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | |
40 | 40 | //--------------------------------------------------------------- parametroj |
41 | 41 | require_once APP_BASE.'configs/settings.php'; |
42 | - $box=new Container\LeMarchand($settings); |
|
42 | + $box = new Container\LeMarchand($settings); |
|
43 | 43 | |
44 | - foreach($box->get('settings.app.namespaces') as $namespace => $path) |
|
44 | + foreach ($box->get('settings.app.namespaces') as $namespace => $path) |
|
45 | 45 | { |
46 | 46 | $loader->addNamespace($namespace, $path); |
47 | 47 | } |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | |
58 | 58 | //--------------------------------------------------------------- kuketoj |
59 | 59 | setcookie('cookie_test', 'test_value', time()+(365 * 24 * 60 * 60), "/", ""); |
60 | - $cookies_enabled=isset($_COOKIE['cookie_test']); // houston, do we have cookies ? |
|
60 | + $cookies_enabled = isset($_COOKIE['cookie_test']); // houston, do we have cookies ? |
|
61 | 61 | |
62 | - if($cookies_enabled === false) |
|
62 | + if ($cookies_enabled === false) |
|
63 | 63 | { |
64 | 64 | ini_set('session.use_cookies', 0); |
65 | 65 | ini_set('session.use_only_cookies', 0); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | //--------------------------------------------------------------- Session Management |
71 | - $StateAgent=new StateAgent($box->get('settings.app.session_start_options') ?? []); |
|
71 | + $StateAgent = new StateAgent($box->get('settings.app.session_start_options') ?? []); |
|
72 | 72 | $StateAgent->add_runtime_filters((array)$box->get('settings.filter')); |
73 | 73 | $StateAgent->add_runtime_filters((array)($_SESSION['filter'] ?? [])); |
74 | 74 | $StateAgent->add_runtime_filters((array)($_REQUEST['filter'] ?? [])); |
@@ -92,24 +92,24 @@ 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'))) |
|
95 | + if (is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path'))) |
|
96 | 96 | throw new \Exception("SMARTY CONFIG ERROR: missing parameters"); |
97 | 97 | |
98 | - $smarty=new \Smarty(); |
|
98 | + $smarty = new \Smarty(); |
|
99 | 99 | $box->register('template_engine', $smarty); |
100 | 100 | |
101 | - $smarty->setTemplateDir($box->get('RouterInterface')->file_root() . $box->get('settings.smarty.template_path').'app'); |
|
102 | - $smarty->addTemplateDir($box->get('RouterInterface')->file_root() . $box->get('settings.smarty.template_path')); |
|
103 | - $smarty->addTemplateDir(KADRO_BASE . 'Views/'); |
|
101 | + $smarty->setTemplateDir($box->get('RouterInterface')->file_root().$box->get('settings.smarty.template_path').'app'); |
|
102 | + $smarty->addTemplateDir($box->get('RouterInterface')->file_root().$box->get('settings.smarty.template_path')); |
|
103 | + $smarty->addTemplateDir(KADRO_BASE.'Views/'); |
|
104 | 104 | |
105 | - $smarty->setCompileDir(APP_BASE . $box->get('settings.smarty.compiled_path')); |
|
105 | + $smarty->setCompileDir(APP_BASE.$box->get('settings.smarty.compiled_path')); |
|
106 | 106 | $smarty->setDebugging($box->get('settings.smarty.debug')); |
107 | 107 | |
108 | - $smarty->registerClass('Lezer', '\HexMakina\Lezer\Lezer'); |
|
109 | - $smarty->registerClass('Marker', '\HexMakina\Format\HTML\Marker'); |
|
110 | - $smarty->registerClass('Form', '\HexMakina\Format\HTML\Form'); |
|
111 | - $smarty->registerClass('TableToForm', '\HexMakina\kadro\TableToForm'); |
|
112 | - $smarty->registerClass('Dato', '\HexMakina\Format\Tempo\Dato'); |
|
108 | + $smarty->registerClass('Lezer', '\HexMakina\Lezer\Lezer'); |
|
109 | + $smarty->registerClass('Marker', '\HexMakina\Format\HTML\Marker'); |
|
110 | + $smarty->registerClass('Form', '\HexMakina\Format\HTML\Form'); |
|
111 | + $smarty->registerClass('TableToForm', '\HexMakina\kadro\TableToForm'); |
|
112 | + $smarty->registerClass('Dato', '\HexMakina\Format\Tempo\Dato'); |
|
113 | 113 | |
114 | 114 | $smarty->assign('APP_NAME', $box->get('settings.app.name')); |
115 | 115 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | $lezer->init(); |
125 | 125 | |
126 | 126 | $smarty->assign('language', $language); |
127 | - if($cookies_enabled === true) |
|
127 | + if ($cookies_enabled === true) |
|
128 | 128 | setcookie('lang', $language, time()+(365 * 24 * 60 * 60), "/", ""); |
129 | 129 | |
130 | 130 | } |
@@ -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 | } |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | return $this->get('language_code'); |
67 | 67 | } |
68 | 68 | |
69 | - public static function query_retrieve($filters=[], $options=[]) : Select |
|
69 | + public static function query_retrieve($filters = [], $options = []) : Select |
|
70 | 70 | { |
71 | 71 | $Query = static::table()->select(); |
72 | - if(isset($options['eager']) && $options['eager'] === true) |
|
72 | + if (isset($options['eager']) && $options['eager'] === true) |
|
73 | 73 | { |
74 | 74 | $Query->group_by('id'); |
75 | 75 | |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | $Query->select_also(["GROUP_CONCAT(DISTINCT kadro_permission.id) as permission_ids", "GROUP_CONCAT(DISTINCT kadro_permission.name) as permission_names"]); |
79 | 79 | } |
80 | 80 | |
81 | - if(isset($filters['model']) && !empty($filters['model'])) |
|
81 | + if (isset($filters['model']) && !empty($filters['model'])) |
|
82 | 82 | { |
83 | 83 | $model = $filters['model']; |
84 | - $Query->join([static::otm('t'), static::otm('a')],[[static::otm('a'),static::otm('k'), 't_from','id']], 'INNER'); |
|
84 | + $Query->join([static::otm('t'), static::otm('a')], [[static::otm('a'), static::otm('k'), 't_from', 'id']], 'INNER'); |
|
85 | 85 | $Query->aw_fields_eq(['model_id' => $filters['model']->get_id(), 'model_type' => get_class($filters['model'])::model_type()], static::otm('a')); |
86 | 86 | } |
87 | 87 |