@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | { |
8 | 8 | protected static function prepare_pagination($records_total) |
9 | 9 | { |
10 | - global $settings; |
|
11 | - global $smarty; |
|
10 | + global $settings; |
|
11 | + global $smarty; |
|
12 | 12 | |
13 | 13 | $pages_max_on_each_side = 3; |
14 | 14 | $pages_max_displayed = $pages_max_on_each_side*2+1; |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
36 | 36 | $pages_last = $pages_total; |
37 | 37 | |
38 | - $this->viewport("pages_total", $pages_total); |
|
39 | - $this->viewport("pages_first", $pages_first); |
|
38 | + $this->viewport("pages_total", $pages_total); |
|
39 | + $this->viewport("pages_first", $pages_first); |
|
40 | 40 | $this->viewport("pages_previous", $pages_current <= 1 ? $pages_total : $pages_current - 1); |
41 | - $this->viewport("pages_current", $pages_current); |
|
42 | - $this->viewport("pages_next", $pages_current >= $pages_total ? 1 : $pages_current + 1); |
|
43 | - $this->viewport("pages_last", $pages_last); |
|
41 | + $this->viewport("pages_current", $pages_current); |
|
42 | + $this->viewport("pages_next", $pages_current >= $pages_total ? 1 : $pages_current + 1); |
|
43 | + $this->viewport("pages_last", $pages_last); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -11,36 +11,36 @@ |
||
11 | 11 | global $smarty; |
12 | 12 | |
13 | 13 | $pages_max_on_each_side = 3; |
14 | - $pages_max_displayed = $pages_max_on_each_side*2+1; |
|
14 | + $pages_max_displayed = $pages_max_on_each_side * 2+1; |
|
15 | 15 | |
16 | 16 | // are we paginating ? |
17 | 17 | |
18 | - if(is_null($this->box('StateAgent')->filters('results_per_page'))) |
|
18 | + if (is_null($this->box('StateAgent')->filters('results_per_page'))) |
|
19 | 19 | return; |
20 | 20 | |
21 | 21 | $pages_range = intval($this->box('StateAgent')->filters('results_per_page')); |
22 | 22 | $pages_total = $pages_range > 0 ? intval(ceil($records_total / $pages_range)) : 1; |
23 | 23 | $pages_current = intval($this->box('StateAgent')->filters('page')); |
24 | 24 | |
25 | - if($pages_current >= $pages_total) |
|
25 | + if ($pages_current >= $pages_total) |
|
26 | 26 | $pages_current = $pages_total; |
27 | 27 | |
28 | - $pages_first = ($pages_current <= $pages_max_on_each_side)? 1 : $pages_current - $pages_max_on_each_side; |
|
28 | + $pages_first = ($pages_current <= $pages_max_on_each_side) ? 1 : $pages_current-$pages_max_on_each_side; |
|
29 | 29 | |
30 | - $pages_last = $pages_current + $pages_max_on_each_side; |
|
30 | + $pages_last = $pages_current+$pages_max_on_each_side; |
|
31 | 31 | |
32 | - if($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed |
|
32 | + if ($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed |
|
33 | 33 | $pages_last += $pages_max_displayed-$pages_last; |
34 | 34 | |
35 | - if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
|
35 | + if ($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
|
36 | 36 | $pages_last = $pages_total; |
37 | 37 | |
38 | - $this->viewport("pages_total", $pages_total); |
|
39 | - $this->viewport("pages_first", $pages_first); |
|
40 | - $this->viewport("pages_previous", $pages_current <= 1 ? $pages_total : $pages_current - 1); |
|
41 | - $this->viewport("pages_current", $pages_current); |
|
42 | - $this->viewport("pages_next", $pages_current >= $pages_total ? 1 : $pages_current + 1); |
|
43 | - $this->viewport("pages_last", $pages_last); |
|
38 | + $this->viewport("pages_total", $pages_total); |
|
39 | + $this->viewport("pages_first", $pages_first); |
|
40 | + $this->viewport("pages_previous", $pages_current <= 1 ? $pages_total : $pages_current-1); |
|
41 | + $this->viewport("pages_current", $pages_current); |
|
42 | + $this->viewport("pages_next", $pages_current >= $pages_total ? 1 : $pages_current+1); |
|
43 | + $this->viewport("pages_last", $pages_last); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -15,25 +15,31 @@ |
||
15 | 15 | |
16 | 16 | // are we paginating ? |
17 | 17 | |
18 | - if(is_null($this->box('StateAgent')->filters('results_per_page'))) |
|
19 | - return; |
|
18 | + if(is_null($this->box('StateAgent')->filters('results_per_page'))) { |
|
19 | + return; |
|
20 | + } |
|
20 | 21 | |
21 | 22 | $pages_range = intval($this->box('StateAgent')->filters('results_per_page')); |
22 | 23 | $pages_total = $pages_range > 0 ? intval(ceil($records_total / $pages_range)) : 1; |
23 | 24 | $pages_current = intval($this->box('StateAgent')->filters('page')); |
24 | 25 | |
25 | - if($pages_current >= $pages_total) |
|
26 | - $pages_current = $pages_total; |
|
26 | + if($pages_current >= $pages_total) { |
|
27 | + $pages_current = $pages_total; |
|
28 | + } |
|
27 | 29 | |
28 | 30 | $pages_first = ($pages_current <= $pages_max_on_each_side)? 1 : $pages_current - $pages_max_on_each_side; |
29 | 31 | |
30 | 32 | $pages_last = $pages_current + $pages_max_on_each_side; |
31 | 33 | |
32 | - if($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed |
|
34 | + if($pages_last < $pages_max_displayed) { |
|
35 | + // add the missing pages to fullfill $pages_max_displayed |
|
33 | 36 | $pages_last += $pages_max_displayed-$pages_last; |
37 | + } |
|
34 | 38 | |
35 | - if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
|
39 | + if($pages_last > $pages_total) { |
|
40 | + // $pages_max_displayed greater than the total of pages |
|
36 | 41 | $pages_last = $pages_total; |
42 | + } |
|
37 | 43 | |
38 | 44 | $this->viewport("pages_total", $pages_total); |
39 | 45 | $this->viewport("pages_first", $pages_first); |
@@ -107,18 +107,18 @@ discard block |
||
107 | 107 | $custom_template = null; |
108 | 108 | |
109 | 109 | if(method_exists($this, 'prepare')) |
110 | - $this->prepare(); |
|
110 | + $this->prepare(); |
|
111 | 111 | |
112 | - if(method_exists($this, $method = $this->router()->target_method())) |
|
112 | + if(method_exists($this, $method = $this->router()->target_method())) |
|
113 | 113 | { |
114 | 114 | $custom_template = $this->$method(); |
115 | 115 | } |
116 | 116 | |
117 | 117 | if(method_exists($this, 'conclude')) |
118 | - $this->conclude(); |
|
118 | + $this->conclude(); |
|
119 | 119 | |
120 | 120 | if(method_exists($this, 'display')) |
121 | - $template = $this->display($custom_template); |
|
121 | + $template = $this->display($custom_template); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function conclude(){} |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | |
144 | 144 | $template = $this->find_template($smarty, $custom_template); // throws Exception if nothing found |
145 | 145 | |
146 | - $this->viewport('controller', $this); |
|
146 | + $this->viewport('controller', $this); |
|
147 | 147 | |
148 | 148 | $this->viewport('user_messages', $this->logger()->get_user_report()); |
149 | 149 | |
150 | 150 | |
151 | - $this->viewport('file_root', $this->router()->file_root()); |
|
152 | - $this->viewport('view_path', $this->router()->file_root() . $this->box('settings.smarty.template_path').'app/'); |
|
153 | - $this->viewport('web_root', $this->router()->web_root()); |
|
154 | - $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path')); |
|
155 | - $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/'); |
|
151 | + $this->viewport('file_root', $this->router()->file_root()); |
|
152 | + $this->viewport('view_path', $this->router()->file_root() . $this->box('settings.smarty.template_path').'app/'); |
|
153 | + $this->viewport('web_root', $this->router()->web_root()); |
|
154 | + $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path')); |
|
155 | + $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/'); |
|
156 | 156 | |
157 | 157 | foreach($this->viewport() as $template_var_name => $value) |
158 | 158 | $smarty->assign($template_var_name, $value); |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | * |
228 | 228 | */ |
229 | 229 | public function route_back($route_name=null, $route_params=[]) : string |
230 | - { |
|
230 | + { |
|
231 | 231 | if(is_null($route_name)) |
232 | - return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
232 | + return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
233 | 233 | |
234 | 234 | return $this->route_back = $this->route_factory($route_name, $route_params); |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | public function route_factory($route_name=null, $route_params=[]) : string |
238 | 238 | { |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HexMakina\kadro\Controllers; |
4 | 4 | |
5 | -use \Psr\Container\{ContainerInterface,ContainerExceptionInterface,NotFoundExceptionInterface}; |
|
5 | +use \Psr\Container\{ContainerInterface, ContainerExceptionInterface, NotFoundExceptionInterface}; |
|
6 | 6 | |
7 | 7 | use \HexMakina\kadro\Auth\{OperatorInterface, AccessRefusedException}; |
8 | 8 | use \HexMakina\kadro\Router\RouterInterface; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | protected $route_back = null; |
17 | 17 | |
18 | - public function __toString(){ return get_called_class();} |
|
18 | + public function __toString() { return get_called_class(); } |
|
19 | 19 | |
20 | 20 | // -------- Controller Container |
21 | 21 | public function set_container(ContainerInterface $container) |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | // shortcut for (un)boxing |
32 | - public function box($key, $instance=null) |
|
32 | + public function box($key, $instance = null) |
|
33 | 33 | { |
34 | - if(!is_null($instance)) |
|
34 | + if (!is_null($instance)) |
|
35 | 35 | $this->container->register($key, $instance); |
36 | 36 | |
37 | 37 | // dd($this->container->get($key)); |
@@ -61,32 +61,32 @@ discard block |
||
61 | 61 | return true; // security by default |
62 | 62 | } |
63 | 63 | |
64 | - public function authorize($permission=null) |
|
64 | + public function authorize($permission = null) |
|
65 | 65 | { |
66 | 66 | // if(!$this->requires_operator() || is_null($permission)) |
67 | - if(!$this->requires_operator()) |
|
67 | + if (!$this->requires_operator()) |
|
68 | 68 | return true; |
69 | 69 | |
70 | 70 | $operator = $this->operator(); |
71 | - if(is_null($operator) || $operator->is_new() || !$operator->is_active()) |
|
71 | + if (is_null($operator) || $operator->is_new() || !$operator->is_active()) |
|
72 | 72 | throw new AccessRefusedException(); |
73 | 73 | |
74 | - if(!is_null($permission) && !$operator->has_permission($permission)) |
|
74 | + if (!is_null($permission) && !$operator->has_permission($permission)) |
|
75 | 75 | throw new AccessRefusedException(); |
76 | 76 | |
77 | 77 | return true; |
78 | 78 | } |
79 | 79 | |
80 | - public function viewport($key=null, $value=null, $coercion=false) |
|
80 | + public function viewport($key = null, $value = null, $coercion = false) |
|
81 | 81 | { |
82 | 82 | // no key, returns all |
83 | - if(is_null($key)) |
|
83 | + if (is_null($key)) |
|
84 | 84 | return $this->template_variables; |
85 | 85 | |
86 | 86 | // got key, got null value, returns $[$key] |
87 | - if(is_null($value)) |
|
87 | + if (is_null($value)) |
|
88 | 88 | { |
89 | - if($coercion === true) // break rule 1 ? |
|
89 | + if ($coercion === true) // break rule 1 ? |
|
90 | 90 | $this->template_variables[$key] = null; |
91 | 91 | |
92 | 92 | return $this->template_variables[$key] ?? null; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | // got key, got value |
96 | 96 | // sets or coerces $[$key]=$value and returns $[$key] |
97 | - if(!isset($this->template_variables[$key]) || $coercion === true) |
|
97 | + if (!isset($this->template_variables[$key]) || $coercion === true) |
|
98 | 98 | $this->template_variables[$key] = $value; |
99 | 99 | |
100 | 100 | return $this->template_variables[$key] ?? null; |
@@ -106,22 +106,22 @@ discard block |
||
106 | 106 | |
107 | 107 | $custom_template = null; |
108 | 108 | |
109 | - if(method_exists($this, 'prepare')) |
|
109 | + if (method_exists($this, 'prepare')) |
|
110 | 110 | $this->prepare(); |
111 | 111 | |
112 | - if(method_exists($this, $method = $this->router()->target_method())) |
|
112 | + if (method_exists($this, $method = $this->router()->target_method())) |
|
113 | 113 | { |
114 | 114 | $custom_template = $this->$method(); |
115 | 115 | } |
116 | 116 | |
117 | - if(method_exists($this, 'conclude')) |
|
117 | + if (method_exists($this, 'conclude')) |
|
118 | 118 | $this->conclude(); |
119 | 119 | |
120 | - if(method_exists($this, 'display')) |
|
120 | + if (method_exists($this, 'display')) |
|
121 | 121 | $template = $this->display($custom_template); |
122 | 122 | } |
123 | 123 | |
124 | - public function conclude(){} |
|
124 | + public function conclude() {} |
|
125 | 125 | |
126 | 126 | public function prepare() |
127 | 127 | { |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | |
131 | 131 | private function trim_request_data() |
132 | 132 | { |
133 | - array_walk_recursive($_GET, function(&$value){$value = trim($value);}); |
|
134 | - array_walk_recursive($_REQUEST, function(&$value){$value = trim($value);}); |
|
133 | + array_walk_recursive($_GET, function(&$value) {$value = trim($value); }); |
|
134 | + array_walk_recursive($_REQUEST, function(&$value) {$value = trim($value); }); |
|
135 | 135 | |
136 | - if($this->router()->submits()) |
|
137 | - array_walk_recursive($_POST, function(&$value){$value = trim($value);}); |
|
136 | + if ($this->router()->submits()) |
|
137 | + array_walk_recursive($_POST, function(&$value) {$value = trim($value); }); |
|
138 | 138 | } |
139 | 139 | |
140 | - public function display($custom_template = null, $standalone=false) |
|
140 | + public function display($custom_template = null, $standalone = false) |
|
141 | 141 | { |
142 | 142 | $smarty = $this->box('template_engine'); |
143 | 143 | |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | |
150 | 150 | |
151 | 151 | $this->viewport('file_root', $this->router()->file_root()); |
152 | - $this->viewport('view_path', $this->router()->file_root() . $this->box('settings.smarty.template_path').'app/'); |
|
152 | + $this->viewport('view_path', $this->router()->file_root().$this->box('settings.smarty.template_path').'app/'); |
|
153 | 153 | $this->viewport('web_root', $this->router()->web_root()); |
154 | - $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path')); |
|
155 | - $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/'); |
|
154 | + $this->viewport('view_url', $this->router()->web_root().$this->box('settings.smarty.template_path')); |
|
155 | + $this->viewport('images_url', $this->router()->web_root().$this->box('settings.smarty.template_path').'images/'); |
|
156 | 156 | |
157 | - foreach($this->viewport() as $template_var_name => $value) |
|
157 | + foreach ($this->viewport() as $template_var_name => $value) |
|
158 | 158 | $smarty->assign($template_var_name, $value); |
159 | 159 | |
160 | - if($standalone === false) |
|
160 | + if ($standalone === false) |
|
161 | 161 | { |
162 | 162 | $smarty->display(sprintf('%s|%s', $this->box('settings.smarty.template_inclusion_path'), $template)); |
163 | 163 | } |
@@ -180,32 +180,32 @@ discard block |
||
180 | 180 | $controller_template_path = $this->template_base(); |
181 | 181 | $templates = []; |
182 | 182 | |
183 | - if(!empty($custom_template)) |
|
183 | + if (!empty($custom_template)) |
|
184 | 184 | { |
185 | 185 | // 1. check for custom template in the current controller directory |
186 | - $templates ['custom_3']= sprintf('%s/%s.html', $controller_template_path, $custom_template); |
|
186 | + $templates ['custom_3'] = sprintf('%s/%s.html', $controller_template_path, $custom_template); |
|
187 | 187 | // 2. check for custom template formatted as controller/view |
188 | - $templates ['custom_2']= $custom_template.'.html'; |
|
189 | - $templates ['custom_1']= '_layouts/'.$custom_template.'.html'; |
|
188 | + $templates ['custom_2'] = $custom_template.'.html'; |
|
189 | + $templates ['custom_1'] = '_layouts/'.$custom_template.'.html'; |
|
190 | 190 | } |
191 | 191 | |
192 | - if(!empty($this->router()->target_method())) |
|
192 | + if (!empty($this->router()->target_method())) |
|
193 | 193 | { |
194 | 194 | // 1. check for template in controller-related directory |
195 | - $templates ['target_1']= sprintf('%s/%s.html', $controller_template_path, $this->router()->target_method()); |
|
195 | + $templates ['target_1'] = sprintf('%s/%s.html', $controller_template_path, $this->router()->target_method()); |
|
196 | 196 | // 2. check for template in app-related directory |
197 | - $templates ['target_2']= sprintf('_layouts/%s.html', $this->router()->target_method()); |
|
197 | + $templates ['target_2'] = sprintf('_layouts/%s.html', $this->router()->target_method()); |
|
198 | 198 | // 3. check for template in kadro directory |
199 | - $templates ['target_3']= sprintf('%s.html', $this->router()->target_method()); |
|
199 | + $templates ['target_3'] = sprintf('%s.html', $this->router()->target_method()); |
|
200 | 200 | } |
201 | 201 | |
202 | - $templates ['default_3']= sprintf('%s/edit.html', $controller_template_path); |
|
203 | - $templates ['default_4']= 'edit.tpl'; |
|
202 | + $templates ['default_3'] = sprintf('%s/edit.html', $controller_template_path); |
|
203 | + $templates ['default_4'] = 'edit.tpl'; |
|
204 | 204 | $templates = array_unique($templates); |
205 | 205 | |
206 | - while(!is_null($tpl_path = array_shift($templates))) |
|
206 | + while (!is_null($tpl_path = array_shift($templates))) |
|
207 | 207 | { |
208 | - if($smarty->templateExists($tpl_path)) |
|
208 | + if ($smarty->templateExists($tpl_path)) |
|
209 | 209 | return $tpl_path; |
210 | 210 | } |
211 | 211 | |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | * route_back($route_name [,$route_params]), sets $route_back using route_factory() |
227 | 227 | * |
228 | 228 | */ |
229 | - public function route_back($route_name=null, $route_params=[]) : string |
|
229 | + public function route_back($route_name = null, $route_params = []) : string |
|
230 | 230 | { |
231 | - if(is_null($route_name)) |
|
231 | + if (is_null($route_name)) |
|
232 | 232 | return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
233 | 233 | |
234 | 234 | return $this->route_back = $this->route_factory($route_name, $route_params); |
235 | 235 | } |
236 | 236 | |
237 | - public function route_factory($route_name=null, $route_params=[]) : string |
|
237 | + public function route_factory($route_name = null, $route_params = []) : string |
|
238 | 238 | { |
239 | 239 | $route = null; |
240 | 240 | |
241 | - if(is_string($route_name) && !empty($route_name)) |
|
241 | + if (is_string($route_name) && !empty($route_name)) |
|
242 | 242 | { |
243 | - if($this->router()->route_exists($route_name)) |
|
243 | + if ($this->router()->route_exists($route_name)) |
|
244 | 244 | $route = $this->router()->prehop($route_name, $route_params); |
245 | 245 | else |
246 | 246 | $route = $route_name; |
@@ -31,8 +31,9 @@ discard block |
||
31 | 31 | // shortcut for (un)boxing |
32 | 32 | public function box($key, $instance=null) |
33 | 33 | { |
34 | - if(!is_null($instance)) |
|
35 | - $this->container->register($key, $instance); |
|
34 | + if(!is_null($instance)) { |
|
35 | + $this->container->register($key, $instance); |
|
36 | + } |
|
36 | 37 | |
37 | 38 | // dd($this->container->get($key)); |
38 | 39 | return $this->container->get($key); |
@@ -64,15 +65,18 @@ discard block |
||
64 | 65 | public function authorize($permission=null) |
65 | 66 | { |
66 | 67 | // if(!$this->requires_operator() || is_null($permission)) |
67 | - if(!$this->requires_operator()) |
|
68 | - return true; |
|
68 | + if(!$this->requires_operator()) { |
|
69 | + return true; |
|
70 | + } |
|
69 | 71 | |
70 | 72 | $operator = $this->operator(); |
71 | - if(is_null($operator) || $operator->is_new() || !$operator->is_active()) |
|
72 | - throw new AccessRefusedException(); |
|
73 | + if(is_null($operator) || $operator->is_new() || !$operator->is_active()) { |
|
74 | + throw new AccessRefusedException(); |
|
75 | + } |
|
73 | 76 | |
74 | - if(!is_null($permission) && !$operator->has_permission($permission)) |
|
75 | - throw new AccessRefusedException(); |
|
77 | + if(!is_null($permission) && !$operator->has_permission($permission)) { |
|
78 | + throw new AccessRefusedException(); |
|
79 | + } |
|
76 | 80 | |
77 | 81 | return true; |
78 | 82 | } |
@@ -80,22 +84,26 @@ discard block |
||
80 | 84 | public function viewport($key=null, $value=null, $coercion=false) |
81 | 85 | { |
82 | 86 | // no key, returns all |
83 | - if(is_null($key)) |
|
84 | - return $this->template_variables; |
|
87 | + if(is_null($key)) { |
|
88 | + return $this->template_variables; |
|
89 | + } |
|
85 | 90 | |
86 | 91 | // got key, got null value, returns $[$key] |
87 | 92 | if(is_null($value)) |
88 | 93 | { |
89 | - if($coercion === true) // break rule 1 ? |
|
94 | + if($coercion === true) { |
|
95 | + // break rule 1 ? |
|
90 | 96 | $this->template_variables[$key] = null; |
97 | + } |
|
91 | 98 | |
92 | 99 | return $this->template_variables[$key] ?? null; |
93 | 100 | } |
94 | 101 | |
95 | 102 | // got key, got value |
96 | 103 | // sets or coerces $[$key]=$value and returns $[$key] |
97 | - if(!isset($this->template_variables[$key]) || $coercion === true) |
|
98 | - $this->template_variables[$key] = $value; |
|
104 | + if(!isset($this->template_variables[$key]) || $coercion === true) { |
|
105 | + $this->template_variables[$key] = $value; |
|
106 | + } |
|
99 | 107 | |
100 | 108 | return $this->template_variables[$key] ?? null; |
101 | 109 | } |
@@ -106,19 +114,22 @@ discard block |
||
106 | 114 | |
107 | 115 | $custom_template = null; |
108 | 116 | |
109 | - if(method_exists($this, 'prepare')) |
|
110 | - $this->prepare(); |
|
117 | + if(method_exists($this, 'prepare')) { |
|
118 | + $this->prepare(); |
|
119 | + } |
|
111 | 120 | |
112 | 121 | if(method_exists($this, $method = $this->router()->target_method())) |
113 | 122 | { |
114 | 123 | $custom_template = $this->$method(); |
115 | 124 | } |
116 | 125 | |
117 | - if(method_exists($this, 'conclude')) |
|
118 | - $this->conclude(); |
|
126 | + if(method_exists($this, 'conclude')) { |
|
127 | + $this->conclude(); |
|
128 | + } |
|
119 | 129 | |
120 | - if(method_exists($this, 'display')) |
|
121 | - $template = $this->display($custom_template); |
|
130 | + if(method_exists($this, 'display')) { |
|
131 | + $template = $this->display($custom_template); |
|
132 | + } |
|
122 | 133 | } |
123 | 134 | |
124 | 135 | public function conclude(){} |
@@ -133,8 +144,10 @@ discard block |
||
133 | 144 | array_walk_recursive($_GET, function(&$value){$value = trim($value);}); |
134 | 145 | array_walk_recursive($_REQUEST, function(&$value){$value = trim($value);}); |
135 | 146 | |
136 | - if($this->router()->submits()) |
|
137 | - array_walk_recursive($_POST, function(&$value){$value = trim($value);}); |
|
147 | + if($this->router()->submits()) { |
|
148 | + array_walk_recursive($_POST, function(&$value){$value = trim($value); |
|
149 | + } |
|
150 | + }); |
|
138 | 151 | } |
139 | 152 | |
140 | 153 | public function display($custom_template = null, $standalone=false) |
@@ -154,14 +167,14 @@ discard block |
||
154 | 167 | $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path')); |
155 | 168 | $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/'); |
156 | 169 | |
157 | - foreach($this->viewport() as $template_var_name => $value) |
|
158 | - $smarty->assign($template_var_name, $value); |
|
170 | + foreach($this->viewport() as $template_var_name => $value) { |
|
171 | + $smarty->assign($template_var_name, $value); |
|
172 | + } |
|
159 | 173 | |
160 | 174 | if($standalone === false) |
161 | 175 | { |
162 | 176 | $smarty->display(sprintf('%s|%s', $this->box('settings.smarty.template_inclusion_path'), $template)); |
163 | - } |
|
164 | - else |
|
177 | + } else |
|
165 | 178 | { |
166 | 179 | $smarty->display($template); |
167 | 180 | } |
@@ -205,8 +218,9 @@ discard block |
||
205 | 218 | |
206 | 219 | while(!is_null($tpl_path = array_shift($templates))) |
207 | 220 | { |
208 | - if($smarty->templateExists($tpl_path)) |
|
209 | - return $tpl_path; |
|
221 | + if($smarty->templateExists($tpl_path)) { |
|
222 | + return $tpl_path; |
|
223 | + } |
|
210 | 224 | } |
211 | 225 | |
212 | 226 | throw new \Exception('KADRO_ERR_NO_TEMPLATE_TO_DISPLAY'); |
@@ -228,8 +242,9 @@ discard block |
||
228 | 242 | */ |
229 | 243 | public function route_back($route_name=null, $route_params=[]) : string |
230 | 244 | { |
231 | - if(is_null($route_name)) |
|
232 | - return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
245 | + if(is_null($route_name)) { |
|
246 | + return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
247 | + } |
|
233 | 248 | |
234 | 249 | return $this->route_back = $this->route_factory($route_name, $route_params); |
235 | 250 | } |
@@ -240,10 +255,11 @@ discard block |
||
240 | 255 | |
241 | 256 | if(is_string($route_name) && !empty($route_name)) |
242 | 257 | { |
243 | - if($this->router()->route_exists($route_name)) |
|
244 | - $route = $this->router()->prehop($route_name, $route_params); |
|
245 | - else |
|
246 | - $route = $route_name; |
|
258 | + if($this->router()->route_exists($route_name)) { |
|
259 | + $route = $this->router()->prehop($route_name, $route_params); |
|
260 | + } else { |
|
261 | + $route = $route_name; |
|
262 | + } |
|
247 | 263 | |
248 | 264 | return $route; |
249 | 265 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 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 | |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages |
51 | - $this->conclude(); |
|
51 | + $this->conclude(); |
|
52 | 52 | |
53 | 53 | if(method_exists($this, 'display')) |
54 | - $template = $this->display($custom_template); |
|
54 | + $template = $this->display($custom_template); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | public function prepare() |
@@ -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 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | namespace HexMakina\kadro\Controllers; |
4 | 4 | |
5 | 5 | use \Psr\Container\ContainerInterface; |
6 | -use HexMakina\kadro\Auth\{Operator,Permission,ACL}; |
|
7 | -use HexMakina\kadro\Auth\{OperatorInterface,AccessRefusedException}; |
|
6 | +use HexMakina\kadro\Auth\{Operator, Permission, ACL}; |
|
7 | +use HexMakina\kadro\Auth\{OperatorInterface, AccessRefusedException}; |
|
8 | 8 | |
9 | 9 | class ReceptionController extends KadroController |
10 | 10 | { |
@@ -18,19 +18,19 @@ discard block |
||
18 | 18 | public function welcome(OperatorInterface $operator) |
19 | 19 | { |
20 | 20 | |
21 | - if($this->router()->name() === 'identify') |
|
21 | + if ($this->router()->name() === 'identify') |
|
22 | 22 | $this->identify($operator); |
23 | 23 | |
24 | 24 | $Controller = $this->router()->target_controller(); |
25 | 25 | $Controller = $this->box($Controller); |
26 | 26 | |
27 | 27 | |
28 | - if($Controller->requires_operator()) |
|
28 | + if ($Controller->requires_operator()) |
|
29 | 29 | { |
30 | - if(is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) |
|
30 | + if (is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) |
|
31 | 31 | $this->router()->hop('checkin'); |
32 | 32 | |
33 | - if(!$operator->is_active()) |
|
33 | + if (!$operator->is_active()) |
|
34 | 34 | { |
35 | 35 | $this->checkout(); |
36 | 36 | throw new AccessRefusedException(); |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | |
63 | 63 | $operator = get_class($op)::exists(['username' => $username]); |
64 | 64 | |
65 | - if(is_null($operator) || !$operator->is_active()) |
|
65 | + if (is_null($operator) || !$operator->is_active()) |
|
66 | 66 | throw new \Exception('ERR_DISABLED'); |
67 | 67 | |
68 | - if(!$operator->password_verify($password)) |
|
68 | + if (!$operator->password_verify($password)) |
|
69 | 69 | throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
70 | 70 | |
71 | 71 | $this->box('StateAgent')->operator_id($operator->get_id()); |
@@ -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()])); |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | $picture_directory = $this->build_path_to_directory(); |
17 | 17 | $thumbnail_directory = $picture_directory; |
18 | 18 | |
19 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
20 | - return []; |
|
19 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
20 | + return []; |
|
21 | 21 | |
22 | 22 | $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/');// ID_SEQUENCENUMBER.ext |
23 | 23 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
76 | 76 | $filepath = $this->locate_file($filepath); |
77 | 77 | |
78 | - if(file_exists($filepath)) |
|
78 | + if(file_exists($filepath)) |
|
79 | 79 | throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
80 | 80 | |
81 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
82 | - throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
81 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
82 | + throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
83 | 83 | |
84 | 84 | $this->make_thumbnail($filepath); |
85 | 85 | } |
@@ -95,64 +95,64 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | public function make_thumbnail($filepath) |
98 | - { |
|
98 | + { |
|
99 | 99 | global $settings; |
100 | 100 | |
101 | - $cover_iri = null; |
|
102 | - |
|
103 | - $mime_type = mime_content_type($filepath); |
|
104 | - switch($mime_type) |
|
105 | - { |
|
106 | - case 'image/jpeg': |
|
107 | - case 'image/pjpeg': |
|
108 | - $cover_iri = imagecreatefromjpeg($filepath); |
|
109 | - break; |
|
101 | + $cover_iri = null; |
|
110 | 102 | |
111 | - case 'image/png': |
|
112 | - $cover_iri = imagecreatefrompng($filepath); |
|
113 | - break; |
|
114 | - |
|
115 | - case 'image/gif': |
|
116 | - $cover_iri = imagecreatefromgif($filepath); |
|
117 | - break; |
|
118 | - } |
|
103 | + $mime_type = mime_content_type($filepath); |
|
104 | + switch($mime_type) |
|
105 | + { |
|
106 | + case 'image/jpeg': |
|
107 | + case 'image/pjpeg': |
|
108 | + $cover_iri = imagecreatefromjpeg($filepath); |
|
109 | + break; |
|
110 | + |
|
111 | + case 'image/png': |
|
112 | + $cover_iri = imagecreatefrompng($filepath); |
|
113 | + break; |
|
114 | + |
|
115 | + case 'image/gif': |
|
116 | + $cover_iri = imagecreatefromgif($filepath); |
|
117 | + break; |
|
118 | + } |
|
119 | 119 | |
120 | - if(!is_null($cover_iri)) |
|
121 | - { |
|
122 | - $width = imagesx( $cover_iri ); |
|
123 | - $height = imagesy( $cover_iri ); |
|
120 | + if(!is_null($cover_iri)) |
|
121 | + { |
|
122 | + $width = imagesx( $cover_iri ); |
|
123 | + $height = imagesy( $cover_iri ); |
|
124 | 124 | |
125 | - // calculate thumbnail size |
|
125 | + // calculate thumbnail size |
|
126 | 126 | |
127 | - $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
|
128 | - $new_height = floor( $height * ( $new_width / $width ) ); |
|
127 | + $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
|
128 | + $new_height = floor( $height * ( $new_width / $width ) ); |
|
129 | 129 | |
130 | - // create a new temporary image |
|
131 | - $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
|
130 | + // create a new temporary image |
|
131 | + $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
|
132 | 132 | |
133 | - // copy and resize old image into new image |
|
134 | - imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
133 | + // copy and resize old image into new image |
|
134 | + imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
135 | 135 | |
136 | - // save thumbnail into a file |
|
136 | + // save thumbnail into a file |
|
137 | 137 | imagejpeg($thumb_iri, $this->locate_thumbnail(pathinfo($filepath, PATHINFO_BASENAME))); |
138 | - } |
|
139 | - } |
|
138 | + } |
|
139 | + } |
|
140 | 140 | |
141 | 141 | public function remove_all() |
142 | 142 | { |
143 | 143 | $filenames = $this->filenames(); |
144 | 144 | |
145 | 145 | foreach($filenames as $filename) |
146 | - $this->remove($filename); |
|
146 | + $this->remove($filename); |
|
147 | 147 | |
148 | 148 | $directory = $this->build_path_to_directory(); |
149 | - if(file_exists($directory) === true) |
|
149 | + if(file_exists($directory) === true) |
|
150 | 150 | { |
151 | 151 | if(is_dir($directory) === false) |
152 | 152 | throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
153 | 153 | |
154 | - if(rmdir($directory) === false) |
|
155 | - throw new \Exception("rmdir($directory) failed like a bitch"); |
|
154 | + if(rmdir($directory) === false) |
|
155 | + throw new \Exception("rmdir($directory) failed like a bitch"); |
|
156 | 156 | } |
157 | 157 | else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
158 | 158 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | foreach($pathes as $what => $path) |
170 | 170 | { |
171 | 171 | $error = null; |
172 | - if(!file_exists($path)) |
|
172 | + if(!file_exists($path)) |
|
173 | 173 | $error = 'file does not exist'; |
174 | 174 | elseif(unlink($path)===false) |
175 | 175 | $error = 'unlink() failed'; |
@@ -223,16 +223,16 @@ discard block |
||
223 | 223 | global $settings; |
224 | 224 | $pi_manager = new PictureManager($item, $picture_type); |
225 | 225 | |
226 | - $pictures = $pi_manager->filenames(); |
|
226 | + $pictures = $pi_manager->filenames(); |
|
227 | 227 | |
228 | 228 | $item_model_type = get_class($item)::model_type(); |
229 | 229 | if(count($pictures)===0) |
230 | 230 | return $settings[$item_model_type][$picture_type]['generic_picture']; |
231 | 231 | |
232 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
233 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
234 | - else |
|
235 | - $filename = array_shift($pictures); |
|
232 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
233 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
234 | + else |
|
235 | + $filename = array_shift($pictures); |
|
236 | 236 | |
237 | 237 | return $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
238 | 238 | } |
@@ -11,35 +11,35 @@ discard block |
||
11 | 11 | { |
12 | 12 | use FileManager; |
13 | 13 | |
14 | - public function filenames($replace_by_thumbs_if_exists=false) : array |
|
14 | + public function filenames($replace_by_thumbs_if_exists = false) : array |
|
15 | 15 | { |
16 | 16 | $picture_directory = $this->build_path_to_directory(); |
17 | 17 | $thumbnail_directory = $picture_directory; |
18 | 18 | |
19 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
19 | + if (!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
20 | 20 | return []; |
21 | 21 | |
22 | - $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/');// ID_SEQUENCENUMBER.ext |
|
22 | + $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/'); // ID_SEQUENCENUMBER.ext |
|
23 | 23 | |
24 | 24 | sort($filenames); |
25 | 25 | return $filenames; |
26 | 26 | } |
27 | 27 | |
28 | - public function filepathes($replace_by_thumbs_if_exists=false) |
|
28 | + public function filepathes($replace_by_thumbs_if_exists = false) |
|
29 | 29 | { |
30 | 30 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
31 | 31 | $filepathes = []; |
32 | - foreach($filenames as $filename) |
|
32 | + foreach ($filenames as $filename) |
|
33 | 33 | $filepathes[] = $this->locate_thumbnail($filename); |
34 | 34 | |
35 | 35 | return $filepathes; |
36 | 36 | } |
37 | 37 | |
38 | - public function file_uris($replace_by_thumbs_if_exists=false) |
|
38 | + public function file_uris($replace_by_thumbs_if_exists = false) |
|
39 | 39 | { |
40 | 40 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
41 | 41 | $uris = []; |
42 | - foreach($filenames as $filename) |
|
42 | + foreach ($filenames as $filename) |
|
43 | 43 | $uris[] = $this->locate_file($filename); |
44 | 44 | |
45 | 45 | dd($uris); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | 'image/gif' => 'imagecreatefromgif', |
56 | 56 | ); |
57 | 57 | $mime = mime_content_type($filepath); |
58 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
58 | + if (array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
59 | 59 | return true; |
60 | 60 | return $mime; |
61 | 61 | } |
@@ -63,22 +63,22 @@ discard block |
||
63 | 63 | |
64 | 64 | public function upload() |
65 | 65 | { |
66 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
66 | + if (!array_key_exists($this->get_type(), $_FILES)) |
|
67 | 67 | throw new \Exception($this->get_type()." not found in _FILES"); |
68 | 68 | |
69 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
69 | + if (!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
70 | 70 | throw new \Exception('uploaded file has no size'); |
71 | 71 | |
72 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
72 | + if (($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
73 | 73 | throw new \Exception('data sent is not an image but a '.$file_type.''); |
74 | 74 | |
75 | - $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
|
75 | + $filepath = $this->build_filename().'.'.self::file_ext($_FILES[$this->get_type()]['name']); |
|
76 | 76 | $filepath = $this->locate_file($filepath); |
77 | 77 | |
78 | - if(file_exists($filepath)) |
|
78 | + if (file_exists($filepath)) |
|
79 | 79 | throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
80 | 80 | |
81 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
81 | + if (copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
82 | 82 | throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
83 | 83 | |
84 | 84 | $this->make_thumbnail($filepath); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | public function download($url) |
88 | 88 | { |
89 | - $filepath = $this->build_filename() . '.' . self::file_ext($url); |
|
89 | + $filepath = $this->build_filename().'.'.self::file_ext($url); |
|
90 | 90 | $filepath = $this->locate_file($filepath); |
91 | 91 | |
92 | 92 | \qivive\Curlyb::fetch($url, $filepath); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $cover_iri = null; |
102 | 102 | |
103 | 103 | $mime_type = mime_content_type($filepath); |
104 | - switch($mime_type) |
|
104 | + switch ($mime_type) |
|
105 | 105 | { |
106 | 106 | case 'image/jpeg': |
107 | 107 | case 'image/pjpeg': |
@@ -117,21 +117,21 @@ discard block |
||
117 | 117 | break; |
118 | 118 | } |
119 | 119 | |
120 | - if(!is_null($cover_iri)) |
|
120 | + if (!is_null($cover_iri)) |
|
121 | 121 | { |
122 | - $width = imagesx( $cover_iri ); |
|
123 | - $height = imagesy( $cover_iri ); |
|
122 | + $width = imagesx($cover_iri); |
|
123 | + $height = imagesy($cover_iri); |
|
124 | 124 | |
125 | 125 | // calculate thumbnail size |
126 | 126 | |
127 | 127 | $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
128 | - $new_height = floor( $height * ( $new_width / $width ) ); |
|
128 | + $new_height = floor($height * ($new_width / $width)); |
|
129 | 129 | |
130 | 130 | // create a new temporary image |
131 | 131 | $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
132 | 132 | |
133 | 133 | // copy and resize old image into new image |
134 | - imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
134 | + imagecopyresized($thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
135 | 135 | |
136 | 136 | // save thumbnail into a file |
137 | 137 | imagejpeg($thumb_iri, $this->locate_thumbnail(pathinfo($filepath, PATHINFO_BASENAME))); |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | { |
143 | 143 | $filenames = $this->filenames(); |
144 | 144 | |
145 | - foreach($filenames as $filename) |
|
145 | + foreach ($filenames as $filename) |
|
146 | 146 | $this->remove($filename); |
147 | 147 | |
148 | 148 | $directory = $this->build_path_to_directory(); |
149 | - if(file_exists($directory) === true) |
|
149 | + if (file_exists($directory) === true) |
|
150 | 150 | { |
151 | - if(is_dir($directory) === false) |
|
151 | + if (is_dir($directory) === false) |
|
152 | 152 | throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
153 | 153 | |
154 | - if(rmdir($directory) === false) |
|
154 | + if (rmdir($directory) === false) |
|
155 | 155 | throw new \Exception("rmdir($directory) failed like a bitch"); |
156 | 156 | } |
157 | 157 | else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
@@ -162,27 +162,27 @@ discard block |
||
162 | 162 | // removing a picture, and maybe a thumbnail? build the $pathes array accordingly |
163 | 163 | $pathes = []; |
164 | 164 | $pathes[$this->get_type()] = $this->locate_file($picture_filename); |
165 | - $pathes[$this->get_type() . ' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
165 | + $pathes[$this->get_type().' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
166 | 166 | |
167 | 167 | $deleted = []; |
168 | 168 | $still_walking = []; |
169 | - foreach($pathes as $what => $path) |
|
169 | + foreach ($pathes as $what => $path) |
|
170 | 170 | { |
171 | 171 | $error = null; |
172 | - if(!file_exists($path)) |
|
172 | + if (!file_exists($path)) |
|
173 | 173 | $error = 'file does not exist'; |
174 | - elseif(unlink($path)===false) |
|
174 | + elseif (unlink($path) === false) |
|
175 | 175 | $error = 'unlink() failed'; |
176 | 176 | |
177 | - if(is_null($error)) |
|
178 | - $deleted[]= $what; |
|
177 | + if (is_null($error)) |
|
178 | + $deleted[] = $what; |
|
179 | 179 | else |
180 | 180 | { |
181 | 181 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
182 | - $still_walking[]=$what; |
|
182 | + $still_walking[] = $what; |
|
183 | 183 | } |
184 | 184 | } |
185 | - return count($still_walking)===0; |
|
185 | + return count($still_walking) === 0; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | public function locate_thumbnail($filename) |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | return $settings['thumbnail']['file_prefix'].''.pathinfo($picture_basename, PATHINFO_FILENAME).'.jpg'; |
197 | 197 | } |
198 | 198 | |
199 | - public static function file_info($absolute_path_to_picture, $what=null) |
|
199 | + public static function file_info($absolute_path_to_picture, $what = null) |
|
200 | 200 | { |
201 | - $ret = parent::file_info($absolute_path_to_picture, $what=null); |
|
201 | + $ret = parent::file_info($absolute_path_to_picture, $what = null); |
|
202 | 202 | |
203 | - if(is_array($ret)) |
|
203 | + if (is_array($ret)) |
|
204 | 204 | { |
205 | 205 | $t = getimagesize($absolute_path_to_picture); |
206 | 206 | $ret['width'] = $t[0]; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | |
220 | 220 | |
221 | - public static function uri_for($item, $picture_type, $thumbnail=true) |
|
221 | + public static function uri_for($item, $picture_type, $thumbnail = true) |
|
222 | 222 | { |
223 | 223 | global $settings; |
224 | 224 | $pi_manager = new PictureManager($item, $picture_type); |
@@ -226,24 +226,24 @@ discard block |
||
226 | 226 | $pictures = $pi_manager->filenames(); |
227 | 227 | |
228 | 228 | $item_model_type = get_class($item)::model_type(); |
229 | - if(count($pictures)===0) |
|
229 | + if (count($pictures) === 0) |
|
230 | 230 | return $settings[$item_model_type][$picture_type]['generic_picture']; |
231 | 231 | |
232 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
232 | + if ($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
233 | 233 | $filename = $pictures[array_rand($pictures, 1)]; |
234 | 234 | else |
235 | 235 | $filename = array_shift($pictures); |
236 | 236 | |
237 | - return $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
|
237 | + return $thumbnail === true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | public function last_index() |
241 | 241 | { |
242 | 242 | $last_index = 0; |
243 | - if(count($filenames = $this->filenames()) > 0) |
|
243 | + if (count($filenames = $this->filenames()) > 0) |
|
244 | 244 | { |
245 | 245 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
246 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
246 | + if (preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
247 | 247 | throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
248 | 248 | |
249 | 249 | $last_index = $last_index[1]; |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | return sprintf('%s%s.jpg', $settings['thumbnail']['file_prefix'], pathinfo($picture_basename, PATHINFO_FILENAME)); |
258 | 258 | } |
259 | 259 | |
260 | - public function build_filename($index=null) |
|
260 | + public function build_filename($index = null) |
|
261 | 261 | { |
262 | - if(is_null($index)) |
|
262 | + if (is_null($index)) |
|
263 | 263 | $index = $this->last_index()+1; |
264 | 264 | |
265 | 265 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $new_thumbname_path = $this->locate_file($this->build_thumb_filename($new_filename_path)); //move current to zero |
279 | 279 | $this->rename($selected_thumbname_path, $new_thumbname_path); |
280 | 280 | |
281 | - for($i=$filename_index-1; $i>=0; --$i) |
|
281 | + for ($i = $filename_index-1; $i >= 0; --$i) |
|
282 | 282 | { |
283 | 283 | $move_this = $this->locate_file($files[$i]); |
284 | 284 | $to_that = $this->locate_file($files[$i+1]); |
@@ -16,8 +16,9 @@ discard block |
||
16 | 16 | $picture_directory = $this->build_path_to_directory(); |
17 | 17 | $thumbnail_directory = $picture_directory; |
18 | 18 | |
19 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
20 | - return []; |
|
19 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) { |
|
20 | + return []; |
|
21 | + } |
|
21 | 22 | |
22 | 23 | $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/');// ID_SEQUENCENUMBER.ext |
23 | 24 | |
@@ -29,8 +30,9 @@ discard block |
||
29 | 30 | { |
30 | 31 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
31 | 32 | $filepathes = []; |
32 | - foreach($filenames as $filename) |
|
33 | - $filepathes[] = $this->locate_thumbnail($filename); |
|
33 | + foreach($filenames as $filename) { |
|
34 | + $filepathes[] = $this->locate_thumbnail($filename); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | return $filepathes; |
36 | 38 | } |
@@ -39,8 +41,9 @@ discard block |
||
39 | 41 | { |
40 | 42 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
41 | 43 | $uris = []; |
42 | - foreach($filenames as $filename) |
|
43 | - $uris[] = $this->locate_file($filename); |
|
44 | + foreach($filenames as $filename) { |
|
45 | + $uris[] = $this->locate_file($filename); |
|
46 | + } |
|
44 | 47 | |
45 | 48 | dd($uris); |
46 | 49 | return $uris; |
@@ -55,31 +58,37 @@ discard block |
||
55 | 58 | 'image/gif' => 'imagecreatefromgif', |
56 | 59 | ); |
57 | 60 | $mime = mime_content_type($filepath); |
58 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
59 | - return true; |
|
61 | + if(array_key_exists($mime, $picture_mime_to_gd_create_function)) { |
|
62 | + return true; |
|
63 | + } |
|
60 | 64 | return $mime; |
61 | 65 | } |
62 | 66 | |
63 | 67 | |
64 | 68 | public function upload() |
65 | 69 | { |
66 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
67 | - throw new \Exception($this->get_type()." not found in _FILES"); |
|
70 | + if(!array_key_exists($this->get_type(), $_FILES)) { |
|
71 | + throw new \Exception($this->get_type()." not found in _FILES"); |
|
72 | + } |
|
68 | 73 | |
69 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
70 | - throw new \Exception('uploaded file has no size'); |
|
74 | + if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) { |
|
75 | + throw new \Exception('uploaded file has no size'); |
|
76 | + } |
|
71 | 77 | |
72 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
73 | - throw new \Exception('data sent is not an image but a '.$file_type.''); |
|
78 | + if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) { |
|
79 | + throw new \Exception('data sent is not an image but a '.$file_type.''); |
|
80 | + } |
|
74 | 81 | |
75 | 82 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
76 | 83 | $filepath = $this->locate_file($filepath); |
77 | 84 | |
78 | - if(file_exists($filepath)) |
|
79 | - throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
|
85 | + if(file_exists($filepath)) { |
|
86 | + throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
|
87 | + } |
|
80 | 88 | |
81 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
82 | - throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
89 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) { |
|
90 | + throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
91 | + } |
|
83 | 92 | |
84 | 93 | $this->make_thumbnail($filepath); |
85 | 94 | } |
@@ -142,19 +151,23 @@ discard block |
||
142 | 151 | { |
143 | 152 | $filenames = $this->filenames(); |
144 | 153 | |
145 | - foreach($filenames as $filename) |
|
146 | - $this->remove($filename); |
|
154 | + foreach($filenames as $filename) { |
|
155 | + $this->remove($filename); |
|
156 | + } |
|
147 | 157 | |
148 | 158 | $directory = $this->build_path_to_directory(); |
149 | 159 | if(file_exists($directory) === true) |
150 | 160 | { |
151 | - if(is_dir($directory) === false) |
|
152 | - throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
|
161 | + if(is_dir($directory) === false) { |
|
162 | + throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
|
163 | + } |
|
153 | 164 | |
154 | - if(rmdir($directory) === false) |
|
155 | - throw new \Exception("rmdir($directory) failed like a bitch"); |
|
165 | + if(rmdir($directory) === false) { |
|
166 | + throw new \Exception("rmdir($directory) failed like a bitch"); |
|
167 | + } |
|
168 | + } else { |
|
169 | + trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
156 | 170 | } |
157 | - else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
158 | 171 | } |
159 | 172 | |
160 | 173 | public function remove($picture_filename) |
@@ -169,14 +182,15 @@ discard block |
||
169 | 182 | foreach($pathes as $what => $path) |
170 | 183 | { |
171 | 184 | $error = null; |
172 | - if(!file_exists($path)) |
|
173 | - $error = 'file does not exist'; |
|
174 | - elseif(unlink($path)===false) |
|
175 | - $error = 'unlink() failed'; |
|
176 | - |
|
177 | - if(is_null($error)) |
|
178 | - $deleted[]= $what; |
|
179 | - else |
|
185 | + if(!file_exists($path)) { |
|
186 | + $error = 'file does not exist'; |
|
187 | + } elseif(unlink($path)===false) { |
|
188 | + $error = 'unlink() failed'; |
|
189 | + } |
|
190 | + |
|
191 | + if(is_null($error)) { |
|
192 | + $deleted[]= $what; |
|
193 | + } else |
|
180 | 194 | { |
181 | 195 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
182 | 196 | $still_walking[]=$what; |
@@ -226,13 +240,15 @@ discard block |
||
226 | 240 | $pictures = $pi_manager->filenames(); |
227 | 241 | |
228 | 242 | $item_model_type = get_class($item)::model_type(); |
229 | - if(count($pictures)===0) |
|
230 | - return $settings[$item_model_type][$picture_type]['generic_picture']; |
|
243 | + if(count($pictures)===0) { |
|
244 | + return $settings[$item_model_type][$picture_type]['generic_picture']; |
|
245 | + } |
|
231 | 246 | |
232 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
233 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
234 | - else |
|
235 | - $filename = array_shift($pictures); |
|
247 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) { |
|
248 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
249 | + } else { |
|
250 | + $filename = array_shift($pictures); |
|
251 | + } |
|
236 | 252 | |
237 | 253 | return $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
238 | 254 | } |
@@ -243,8 +259,9 @@ discard block |
||
243 | 259 | if(count($filenames = $this->filenames()) > 0) |
244 | 260 | { |
245 | 261 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
246 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
247 | - throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
262 | + if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) { |
|
263 | + throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
264 | + } |
|
248 | 265 | |
249 | 266 | $last_index = $last_index[1]; |
250 | 267 | } |
@@ -259,8 +276,9 @@ discard block |
||
259 | 276 | |
260 | 277 | public function build_filename($index=null) |
261 | 278 | { |
262 | - if(is_null($index)) |
|
263 | - $index = $this->last_index()+1; |
|
279 | + if(is_null($index)) { |
|
280 | + $index = $this->last_index()+1; |
|
281 | + } |
|
264 | 282 | |
265 | 283 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
266 | 284 | } |
@@ -11,9 +11,9 @@ |
||
11 | 11 | return $this->breadcrumbs; |
12 | 12 | } |
13 | 13 | |
14 | - public function breadcrumb($show, $route=null) |
|
14 | + public function breadcrumb($show, $route = null) |
|
15 | 15 | { |
16 | - $this->breadcrumbs[]= ['show' => $show, 'route' => $route]; |
|
16 | + $this->breadcrumbs[] = ['show' => $show, 'route' => $route]; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function reset_breadcrumbs() : array |
@@ -33,7 +33,7 @@ |
||
33 | 33 | $headers = explode(',', trim($language_data[0])); |
34 | 34 | array_shift($language_data); |
35 | 35 | |
36 | - foreach($language_data as $i => $lang) |
|
36 | + foreach ($language_data as $i => $lang) |
|
37 | 37 | { |
38 | 38 | $data = array_combine($headers, explode(',', $lang)); |
39 | 39 |
@@ -9,11 +9,13 @@ discard block |
||
9 | 9 | { |
10 | 10 | private static function compute_field_value($model,$field_name) |
11 | 11 | { |
12 | - if(method_exists($model,$field_name)) |
|
13 | - return $model->$field_name(); |
|
12 | + if(method_exists($model,$field_name)) { |
|
13 | + return $model->$field_name(); |
|
14 | + } |
|
14 | 15 | |
15 | - if(property_exists($model,$field_name)) |
|
16 | - return $model->$field_name; |
|
16 | + if(property_exists($model,$field_name)) { |
|
17 | + return $model->$field_name; |
|
18 | + } |
|
17 | 19 | |
18 | 20 | return ''; |
19 | 21 | } |
@@ -51,74 +53,66 @@ discard block |
||
51 | 53 | |
52 | 54 | $table = get_class($model)::table(); |
53 | 55 | |
54 | - if(is_null($table->column($field_name))) |
|
55 | - return Form::input($field_name,$field_value,$attributes,$errors); |
|
56 | + if(is_null($table->column($field_name))) { |
|
57 | + return Form::input($field_name,$field_value,$attributes,$errors); |
|
58 | + } |
|
56 | 59 | |
57 | 60 | $ret = ''; |
58 | 61 | |
59 | 62 | $field = $table->column($field_name); |
60 | 63 | |
61 | 64 | |
62 | - if(isset($attributes['required']) && $attributes['required'] === false) |
|
63 | - unset($attributes['required']); |
|
64 | - |
|
65 | - elseif(!$field->is_nullable()) |
|
66 | - $attributes[] = 'required'; |
|
65 | + if(isset($attributes['required']) && $attributes['required'] === false) { |
|
66 | + unset($attributes['required']); |
|
67 | + } elseif(!$field->is_nullable()) { |
|
68 | + $attributes[] = 'required'; |
|
69 | + } |
|
67 | 70 | |
68 | 71 | if($field->is_auto_incremented()) |
69 | 72 | { |
70 | 73 | $ret .= Form::hidden($field->name(),$field_value); |
71 | - } |
|
72 | - elseif($field->type()->is_boolean()) |
|
74 | + } elseif($field->type()->is_boolean()) |
|
73 | 75 | { |
74 | 76 | $option_list = $attributes['values'] ?? [0 => 0, 1 => 1]; |
75 | 77 | $ret .= Form::select($field->name(), $option_list ,$field_value, $attributes); // |
76 | - } |
|
77 | - elseif($field->type()->is_integer()) |
|
78 | + } elseif($field->type()->is_integer()) |
|
78 | 79 | { |
79 | 80 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
80 | - } |
|
81 | - elseif($field->type()->is_year()) |
|
81 | + } elseif($field->type()->is_year()) |
|
82 | 82 | { |
83 | 83 | $attributes['size'] = $attributes['maxlength'] = 4; |
84 | 84 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
85 | - } |
|
86 | - elseif($field->type()->is_date()) |
|
85 | + } elseif($field->type()->is_date()) |
|
87 | 86 | { |
88 | 87 | $ret .= Form::date($field->name(),$field_value,$attributes,$errors); |
89 | - } |
|
90 | - elseif($field->type()->is_time()) |
|
88 | + } elseif($field->type()->is_time()) |
|
91 | 89 | { |
92 | 90 | $ret .= Form::time($field->name(),$field_value,$attributes,$errors); |
93 | - } |
|
94 | - elseif($field->type()->is_datetime()) |
|
91 | + } elseif($field->type()->is_datetime()) |
|
95 | 92 | { |
96 | 93 | $ret .= Form::datetime($field->name(),$field_value,$attributes,$errors); |
97 | - } |
|
98 | - elseif($field->type()->is_text()) |
|
94 | + } elseif($field->type()->is_text()) |
|
99 | 95 | { |
100 | 96 | $ret .= Form::textarea($field->name(),$field_value,$attributes,$errors); |
101 | - } |
|
102 | - elseif($field->type()->is_enum()) |
|
97 | + } elseif($field->type()->is_enum()) |
|
103 | 98 | { |
104 | 99 | |
105 | 100 | $enum_values = []; |
106 | - foreach($field->type()->enum_values() as $e_val) |
|
107 | - $enum_values[$e_val] = $e_val; |
|
101 | + foreach($field->type()->enum_values() as $e_val) { |
|
102 | + $enum_values[$e_val] = $e_val; |
|
103 | + } |
|
108 | 104 | |
109 | 105 | $selected = $attributes['value'] ?? $field_value ?? ''; |
110 | 106 | // foreach($field->) |
111 | 107 | $ret .= Form::select($field->name(), $enum_values, $selected, $attributes); // |
112 | 108 | |
113 | 109 | // throw new \Exception('ENUM IS NOT HANDLED BY TableToFom'); |
114 | - } |
|
115 | - elseif($field->type()->is_string()) |
|
110 | + } elseif($field->type()->is_string()) |
|
116 | 111 | { |
117 | 112 | $max_length = $field->type()->length(); |
118 | 113 | $attributes['size'] = $attributes['maxlength'] = $max_length; |
119 | 114 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
120 | - } |
|
121 | - else |
|
115 | + } else |
|
122 | 116 | { |
123 | 117 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
124 | 118 | } |
@@ -130,8 +124,9 @@ discard block |
||
130 | 124 | public static function field_with_label($model,$field_name,$attributes=[],$errors=[]) : string |
131 | 125 | { |
132 | 126 | $field_attributes = $attributes; |
133 | - if(isset($attributes['label'])) |
|
134 | - unset($field_attributes['label']); |
|
127 | + if(isset($attributes['label'])) { |
|
128 | + unset($field_attributes['label']); |
|
129 | + } |
|
135 | 130 | |
136 | 131 | return sprintf('%s %s', self::label($model,$field_name,$attributes,$errors), self::field($model,$field_name,$field_attributes,$errors)); |
137 | 132 | } |
@@ -148,14 +143,15 @@ discard block |
||
148 | 143 | $form_field = ''; |
149 | 144 | if($column->is_auto_incremented()) |
150 | 145 | { |
151 | - if(!$model->is_new()) |
|
152 | - $form_field = self::field($model,$column_name); |
|
153 | - } |
|
154 | - else |
|
146 | + if(!$model->is_new()) { |
|
147 | + $form_field = self::field($model,$column_name); |
|
148 | + } |
|
149 | + } else |
|
155 | 150 | { |
156 | 151 | $form_field = self::field_with_label($model,$column_name); |
157 | - if(!is_null($group_class)) |
|
158 | - $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
152 | + if(!is_null($group_class)) { |
|
153 | + $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
154 | + } |
|
159 | 155 | } |
160 | 156 | $ret .= PHP_EOL.$form_field; |
161 | 157 | } |
@@ -3,26 +3,26 @@ discard block |
||
3 | 3 | namespace HexMakina\kadro; |
4 | 4 | |
5 | 5 | use \HexMakina\Crudites\Interfaces\ModelInterface; |
6 | -use \HexMakina\Format\HTML\{Form,Element}; |
|
6 | +use \HexMakina\Format\HTML\{Form, Element}; |
|
7 | 7 | |
8 | 8 | class TableToForm |
9 | 9 | { |
10 | - private static function compute_field_value($model,$field_name) |
|
10 | + private static function compute_field_value($model, $field_name) |
|
11 | 11 | { |
12 | - if(method_exists($model,$field_name)) |
|
12 | + if (method_exists($model, $field_name)) |
|
13 | 13 | return $model->$field_name(); |
14 | 14 | |
15 | - if(property_exists($model,$field_name)) |
|
15 | + if (property_exists($model, $field_name)) |
|
16 | 16 | return $model->$field_name; |
17 | 17 | |
18 | 18 | return ''; |
19 | 19 | } |
20 | 20 | |
21 | - public static function label($model,$field_name,$attributes=[],$errors=[]) |
|
21 | + public static function label($model, $field_name, $attributes = [], $errors = []) |
|
22 | 22 | { |
23 | 23 | $label_content = $field_name; |
24 | 24 | |
25 | - if(isset($attributes['label'])) |
|
25 | + if (isset($attributes['label'])) |
|
26 | 26 | { |
27 | 27 | $label_content = $attributes['label']; |
28 | 28 | unset($attributes['label']); |
@@ -44,66 +44,66 @@ discard block |
||
44 | 44 | return $ret; |
45 | 45 | } |
46 | 46 | |
47 | - public static function field(ModelInterface $model,$field_name,$attributes=[],$errors=[]) : string |
|
47 | + public static function field(ModelInterface $model, $field_name, $attributes = [], $errors = []) : string |
|
48 | 48 | { |
49 | - $field_value = $attributes['value'] ?? self::compute_field_value($model,$field_name); |
|
49 | + $field_value = $attributes['value'] ?? self::compute_field_value($model, $field_name); |
|
50 | 50 | $attributes['name'] = $attributes['name'] ?? $field_name; |
51 | 51 | |
52 | 52 | $table = get_class($model)::table(); |
53 | 53 | |
54 | - if(is_null($table->column($field_name))) |
|
55 | - return Form::input($field_name,$field_value,$attributes,$errors); |
|
54 | + if (is_null($table->column($field_name))) |
|
55 | + return Form::input($field_name, $field_value, $attributes, $errors); |
|
56 | 56 | |
57 | 57 | $ret = ''; |
58 | 58 | |
59 | 59 | $field = $table->column($field_name); |
60 | 60 | |
61 | 61 | |
62 | - if(isset($attributes['required']) && $attributes['required'] === false) |
|
62 | + if (isset($attributes['required']) && $attributes['required'] === false) |
|
63 | 63 | unset($attributes['required']); |
64 | 64 | |
65 | - elseif(!$field->is_nullable()) |
|
65 | + elseif (!$field->is_nullable()) |
|
66 | 66 | $attributes[] = 'required'; |
67 | 67 | |
68 | - if($field->is_auto_incremented()) |
|
68 | + if ($field->is_auto_incremented()) |
|
69 | 69 | { |
70 | - $ret .= Form::hidden($field->name(),$field_value); |
|
70 | + $ret .= Form::hidden($field->name(), $field_value); |
|
71 | 71 | } |
72 | - elseif($field->type()->is_boolean()) |
|
72 | + elseif ($field->type()->is_boolean()) |
|
73 | 73 | { |
74 | 74 | $option_list = $attributes['values'] ?? [0 => 0, 1 => 1]; |
75 | - $ret .= Form::select($field->name(), $option_list ,$field_value, $attributes); // |
|
75 | + $ret .= Form::select($field->name(), $option_list, $field_value, $attributes); // |
|
76 | 76 | } |
77 | - elseif($field->type()->is_integer()) |
|
77 | + elseif ($field->type()->is_integer()) |
|
78 | 78 | { |
79 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
79 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
80 | 80 | } |
81 | - elseif($field->type()->is_year()) |
|
81 | + elseif ($field->type()->is_year()) |
|
82 | 82 | { |
83 | 83 | $attributes['size'] = $attributes['maxlength'] = 4; |
84 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
84 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
85 | 85 | } |
86 | - elseif($field->type()->is_date()) |
|
86 | + elseif ($field->type()->is_date()) |
|
87 | 87 | { |
88 | - $ret .= Form::date($field->name(),$field_value,$attributes,$errors); |
|
88 | + $ret .= Form::date($field->name(), $field_value, $attributes, $errors); |
|
89 | 89 | } |
90 | - elseif($field->type()->is_time()) |
|
90 | + elseif ($field->type()->is_time()) |
|
91 | 91 | { |
92 | - $ret .= Form::time($field->name(),$field_value,$attributes,$errors); |
|
92 | + $ret .= Form::time($field->name(), $field_value, $attributes, $errors); |
|
93 | 93 | } |
94 | - elseif($field->type()->is_datetime()) |
|
94 | + elseif ($field->type()->is_datetime()) |
|
95 | 95 | { |
96 | - $ret .= Form::datetime($field->name(),$field_value,$attributes,$errors); |
|
96 | + $ret .= Form::datetime($field->name(), $field_value, $attributes, $errors); |
|
97 | 97 | } |
98 | - elseif($field->type()->is_text()) |
|
98 | + elseif ($field->type()->is_text()) |
|
99 | 99 | { |
100 | - $ret .= Form::textarea($field->name(),$field_value,$attributes,$errors); |
|
100 | + $ret .= Form::textarea($field->name(), $field_value, $attributes, $errors); |
|
101 | 101 | } |
102 | - elseif($field->type()->is_enum()) |
|
102 | + elseif ($field->type()->is_enum()) |
|
103 | 103 | { |
104 | 104 | |
105 | 105 | $enum_values = []; |
106 | - foreach($field->type()->enum_values() as $e_val) |
|
106 | + foreach ($field->type()->enum_values() as $e_val) |
|
107 | 107 | $enum_values[$e_val] = $e_val; |
108 | 108 | |
109 | 109 | $selected = $attributes['value'] ?? $field_value ?? ''; |
@@ -112,50 +112,50 @@ discard block |
||
112 | 112 | |
113 | 113 | // throw new \Exception('ENUM IS NOT HANDLED BY TableToFom'); |
114 | 114 | } |
115 | - elseif($field->type()->is_string()) |
|
115 | + elseif ($field->type()->is_string()) |
|
116 | 116 | { |
117 | 117 | $max_length = $field->type()->length(); |
118 | 118 | $attributes['size'] = $attributes['maxlength'] = $max_length; |
119 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
119 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
120 | 120 | } |
121 | 121 | else |
122 | 122 | { |
123 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
123 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
127 | 127 | return $ret; |
128 | 128 | } |
129 | 129 | |
130 | - public static function field_with_label($model,$field_name,$attributes=[],$errors=[]) : string |
|
130 | + public static function field_with_label($model, $field_name, $attributes = [], $errors = []) : string |
|
131 | 131 | { |
132 | 132 | $field_attributes = $attributes; |
133 | - if(isset($attributes['label'])) |
|
133 | + if (isset($attributes['label'])) |
|
134 | 134 | unset($field_attributes['label']); |
135 | 135 | |
136 | - return sprintf('%s %s', self::label($model,$field_name,$attributes,$errors), self::field($model,$field_name,$field_attributes,$errors)); |
|
136 | + return sprintf('%s %s', self::label($model, $field_name, $attributes, $errors), self::field($model, $field_name, $field_attributes, $errors)); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
140 | - public static function fields(ModelInterface $model,$group_class=null) : string |
|
140 | + public static function fields(ModelInterface $model, $group_class = null) : string |
|
141 | 141 | { |
142 | 142 | $table = get_class($model)::table(); |
143 | 143 | $ret = ''; |
144 | - foreach($table->columns() as $column_name => $column) |
|
144 | + foreach ($table->columns() as $column_name => $column) |
|
145 | 145 | { |
146 | 146 | // vd($column_name); |
147 | 147 | |
148 | 148 | $form_field = ''; |
149 | - if($column->is_auto_incremented()) |
|
149 | + if ($column->is_auto_incremented()) |
|
150 | 150 | { |
151 | - if(!$model->is_new()) |
|
152 | - $form_field = self::field($model,$column_name); |
|
151 | + if (!$model->is_new()) |
|
152 | + $form_field = self::field($model, $column_name); |
|
153 | 153 | } |
154 | 154 | else |
155 | 155 | { |
156 | - $form_field = self::field_with_label($model,$column_name); |
|
157 | - if(!is_null($group_class)) |
|
158 | - $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
156 | + $form_field = self::field_with_label($model, $column_name); |
|
157 | + if (!is_null($group_class)) |
|
158 | + $form_field = new Element('div', $form_field, ['class' => $group_class]); |
|
159 | 159 | } |
160 | 160 | $ret .= PHP_EOL.$form_field; |
161 | 161 | } |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | return $this->iso_name().' ('.$this->Part3.')'; |
32 | 32 | } |
33 | 33 | |
34 | - public function traceable() : bool |
|
35 | - { |
|
36 | - return false; |
|
37 | - } |
|
34 | + public function traceable() : bool |
|
35 | + { |
|
36 | + return false; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | public function iso_name() |
40 | 40 | { |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | public static function search_language($term, $authority=null) |
103 | 103 | { |
104 | 104 | $rows = self::query_retrieve(['term' => $term, 'requires_authority' => $authority])->ret_ass(); |
105 | - $ret = []; |
|
106 | - foreach($rows as $row) |
|
107 | - $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
105 | + $ret = []; |
|
106 | + foreach($rows as $row) |
|
107 | + $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
108 | 108 | |
109 | 109 | return $ret; |
110 | 110 | } |
@@ -52,39 +52,39 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | |
55 | - public static function query_retrieve($filter=[], $options=[]) : \HexMakina\Crudites\Queries\BaseQuery |
|
55 | + public static function query_retrieve($filter = [], $options = []) : \HexMakina\Crudites\Queries\BaseQuery |
|
56 | 56 | { |
57 | 57 | |
58 | 58 | $searchable_fields = [self::ISO_NAME, self::ISO_3, self::ISO_2B, self::ISO_2T, self::ISO_1]; |
59 | 59 | |
60 | 60 | $Query = static::table()->select(); |
61 | 61 | |
62 | - if(isset($filter['name'])) |
|
62 | + if (isset($filter['name'])) |
|
63 | 63 | { |
64 | 64 | |
65 | 65 | } |
66 | 66 | |
67 | - if(isset($filter['code'])) |
|
67 | + if (isset($filter['code'])) |
|
68 | 68 | { |
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | - if(isset($filter['term'])) |
|
72 | + if (isset($filter['term'])) |
|
73 | 73 | { |
74 | 74 | $Query->aw_filter_content(['term' => $filter['term'], 'fields' => $searchable_fields], $Query->table_label(), 'OR'); |
75 | 75 | } |
76 | 76 | |
77 | - if(isset($filter['requires_authority']) && isset(self::ISO_SETS[$filter['requires_authority']])) |
|
77 | + if (isset($filter['requires_authority']) && isset(self::ISO_SETS[$filter['requires_authority']])) |
|
78 | 78 | { |
79 | 79 | $Query->aw_not_empty($filter['requires_authority']); |
80 | 80 | } |
81 | 81 | |
82 | - if(isset($filter['types'])) |
|
82 | + if (isset($filter['types'])) |
|
83 | 83 | { |
84 | 84 | $wc = sprintf('AND Type IN (\'%s\') ', implode('\', \'', array_keys(self::types()))); |
85 | 85 | $Query->and_where($wc); |
86 | 86 | } |
87 | - if(isset($filter['scopes'])) |
|
87 | + if (isset($filter['scopes'])) |
|
88 | 88 | { |
89 | 89 | $wc = sprintf('AND Scope IN (\'%s\') ', implode('\', \'', array_keys(self::scopes()))); |
90 | 90 | $Query->and_where($wc); |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | return $Query; |
100 | 100 | } |
101 | 101 | |
102 | - public static function search_language($term, $authority=null) |
|
102 | + public static function search_language($term, $authority = null) |
|
103 | 103 | { |
104 | 104 | $rows = self::query_retrieve(['term' => $term, 'requires_authority' => $authority])->ret_ass(); |
105 | 105 | $ret = []; |
106 | - foreach($rows as $row) |
|
106 | + foreach ($rows as $row) |
|
107 | 107 | $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
108 | 108 | |
109 | 109 | return $ret; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $Query->aw_eq(self::ISO_3, $code); |
116 | 116 | $rows = $Query->ret_col(); |
117 | 117 | |
118 | - if(isset($rows[0])) // only 1 result |
|
118 | + if (isset($rows[0])) // only 1 result |
|
119 | 119 | return current($rows); |
120 | 120 | |
121 | 121 | return null; // no results |
@@ -103,8 +103,9 @@ discard block |
||
103 | 103 | { |
104 | 104 | $rows = self::query_retrieve(['term' => $term, 'requires_authority' => $authority])->ret_ass(); |
105 | 105 | $ret = []; |
106 | - foreach($rows as $row) |
|
107 | - $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
106 | + foreach($rows as $row) { |
|
107 | + $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
108 | + } |
|
108 | 109 | |
109 | 110 | return $ret; |
110 | 111 | } |
@@ -115,8 +116,10 @@ discard block |
||
115 | 116 | $Query->aw_eq(self::ISO_3, $code); |
116 | 117 | $rows = $Query->ret_col(); |
117 | 118 | |
118 | - if(isset($rows[0])) // only 1 result |
|
119 | + if(isset($rows[0])) { |
|
120 | + // only 1 result |
|
119 | 121 | return current($rows); |
122 | + } |
|
120 | 123 | |
121 | 124 | return null; // no results |
122 | 125 | } |