Total Complexity | 105 |
Total Lines | 818 |
Duplicated Lines | 0 % |
Changes | 7 | ||
Bugs | 0 | Features | 0 |
Complex classes like Base often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Base, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | abstract class Base |
||
23 | implements \Aimeos\Admin\JQAdm\Iface, \Aimeos\Macro\Iface |
||
24 | { |
||
25 | use \Aimeos\Macro\Macroable; |
||
26 | |||
27 | |||
28 | private $view; |
||
29 | private $aimeos; |
||
30 | private $context; |
||
31 | private $subclients; |
||
32 | private $object; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Initializes the class instance. |
||
37 | * |
||
38 | * @param \Aimeos\MShop\ContextIface $context Context object |
||
39 | */ |
||
40 | public function __construct( \Aimeos\MShop\ContextIface $context ) |
||
41 | { |
||
42 | $this->context = $context; |
||
43 | } |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Adds the required data used in the attribute template |
||
48 | * |
||
49 | * @param \Aimeos\Base\View\Iface $view View object |
||
50 | * @return \Aimeos\Base\View\Iface View object with assigned parameters |
||
51 | */ |
||
52 | public function data( \Aimeos\Base\View\Iface $view ) : \Aimeos\Base\View\Iface |
||
53 | { |
||
54 | return $view; |
||
55 | } |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Returns the Aimeos bootstrap object |
||
60 | * |
||
61 | * @return \Aimeos\Bootstrap The Aimeos bootstrap object |
||
62 | */ |
||
63 | public function getAimeos() : \Aimeos\Bootstrap |
||
64 | { |
||
65 | if( !isset( $this->aimeos ) ) { |
||
66 | throw new \Aimeos\Admin\JQAdm\Exception( $this->context->translate( 'admin', 'Aimeos object not available' ) ); |
||
67 | } |
||
68 | |||
69 | return $this->aimeos; |
||
70 | } |
||
71 | |||
72 | |||
73 | /** |
||
74 | * Sets the Aimeos bootstrap object |
||
75 | * |
||
76 | * @param \Aimeos\Bootstrap $aimeos The Aimeos bootstrap object |
||
77 | * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls |
||
78 | */ |
||
79 | public function setAimeos( \Aimeos\Bootstrap $aimeos ) : \Aimeos\Admin\JQAdm\Iface |
||
80 | { |
||
81 | $this->aimeos = $aimeos; |
||
82 | return $this; |
||
83 | } |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Makes the outer decorator object available to inner objects |
||
88 | * |
||
89 | * @param \Aimeos\Admin\JQAdm\Iface $object Outmost object |
||
90 | * @return \Aimeos\Admin\JQAdm\Iface Same object for fluent interface |
||
91 | */ |
||
92 | public function setObject( \Aimeos\Admin\JQAdm\Iface $object ) : \Aimeos\Admin\JQAdm\Iface |
||
96 | } |
||
97 | |||
98 | |||
99 | /** |
||
100 | * Returns the view object that will generate the admin output. |
||
101 | * |
||
102 | * @return \Aimeos\Base\View\Iface The view object which generates the admin output |
||
103 | */ |
||
104 | protected function view() : \Aimeos\Base\View\Iface |
||
111 | } |
||
112 | |||
113 | |||
114 | /** |
||
115 | * Sets the view object that will generate the admin output. |
||
116 | * |
||
117 | * @param \Aimeos\Base\View\Iface $view The view object which generates the admin output |
||
118 | * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls |
||
119 | */ |
||
120 | public function setView( \Aimeos\Base\View\Iface $view ) : \Aimeos\Admin\JQAdm\Iface |
||
124 | } |
||
125 | |||
126 | |||
127 | /** |
||
128 | * Batch update of a resource |
||
129 | * |
||
130 | * @return string|null Output to display |
||
131 | */ |
||
132 | public function batch() : ?string |
||
133 | { |
||
134 | foreach( $this->getSubClients() as $client ) { |
||
135 | $client->batch(); |
||
136 | } |
||
137 | |||
138 | return null; |
||
139 | } |
||
140 | |||
141 | |||
142 | /** |
||
143 | * Copies a resource |
||
144 | * |
||
145 | * @return string|null Output to display |
||
146 | */ |
||
147 | public function copy() : ?string |
||
148 | { |
||
149 | $body = null; |
||
150 | $view = $this->view(); |
||
151 | |||
152 | foreach( $this->getSubClients() as $idx => $client ) |
||
153 | { |
||
154 | $view->tabindex = ++$idx + 1; |
||
155 | $body .= $client->copy(); |
||
156 | } |
||
157 | |||
158 | return $body; |
||
159 | } |
||
160 | |||
161 | |||
162 | /** |
||
163 | * Creates a new resource |
||
164 | * |
||
165 | * @return string|null Output to display |
||
166 | */ |
||
167 | public function create() : ?string |
||
168 | { |
||
169 | $body = null; |
||
170 | $view = $this->view(); |
||
171 | |||
172 | foreach( $this->getSubClients() as $idx => $client ) |
||
173 | { |
||
174 | $view->tabindex = ++$idx + 1; |
||
175 | $body .= $client->create(); |
||
176 | } |
||
177 | |||
178 | return $body; |
||
179 | } |
||
180 | |||
181 | |||
182 | /** |
||
183 | * Deletes a resource |
||
184 | * |
||
185 | * @return string|null Output to display |
||
186 | */ |
||
187 | public function delete() : ?string |
||
188 | { |
||
189 | $body = null; |
||
190 | |||
191 | foreach( $this->getSubClients() as $client ) { |
||
192 | $body .= $client->delete(); |
||
193 | } |
||
194 | |||
195 | return $body; |
||
196 | } |
||
197 | |||
198 | |||
199 | /** |
||
200 | * Exports a resource |
||
201 | * |
||
202 | * @return string|null Output to display |
||
203 | */ |
||
204 | public function export() : ?string |
||
205 | { |
||
206 | $body = null; |
||
207 | |||
208 | foreach( $this->getSubClients() as $client ) { |
||
209 | $body .= $client->export(); |
||
210 | } |
||
211 | |||
212 | return $body; |
||
213 | } |
||
214 | |||
215 | |||
216 | /** |
||
217 | * Returns a resource |
||
218 | * |
||
219 | * @return string|null Output to display |
||
220 | */ |
||
221 | public function get() : ?string |
||
222 | { |
||
223 | $body = null; |
||
224 | $view = $this->view(); |
||
225 | |||
226 | foreach( $this->getSubClients() as $idx => $client ) |
||
227 | { |
||
228 | $view->tabindex = ++$idx + 1; |
||
229 | $body .= $client->get(); |
||
230 | } |
||
231 | |||
232 | return $body; |
||
233 | } |
||
234 | |||
235 | |||
236 | /** |
||
237 | * Imports a resource |
||
238 | * |
||
239 | * @return string|null Output to display |
||
240 | * @deprecated 2021.01 |
||
241 | */ |
||
242 | public function import() : ?string |
||
243 | { |
||
244 | $body = null; |
||
245 | |||
246 | foreach( $this->getSubClients() as $client ) { |
||
247 | $body .= $client->import(); |
||
248 | } |
||
249 | |||
250 | return null; |
||
251 | } |
||
252 | |||
253 | |||
254 | /** |
||
255 | * Saves the data |
||
256 | * |
||
257 | * @return string|null Output to display |
||
258 | */ |
||
259 | public function save() : ?string |
||
260 | { |
||
261 | $body = null; |
||
262 | |||
263 | foreach( $this->getSubClients() as $client ) { |
||
264 | $body .= $client->save(); |
||
265 | } |
||
266 | |||
267 | return $body; |
||
268 | } |
||
269 | |||
270 | |||
271 | /** |
||
272 | * Returns a list of resource according to the conditions |
||
273 | * |
||
274 | * @return string|null Output to display |
||
275 | */ |
||
276 | public function search() : ?string |
||
277 | { |
||
278 | $body = null; |
||
279 | |||
280 | foreach( $this->getSubClients() as $client ) { |
||
281 | $body .= $client->search(); |
||
282 | } |
||
283 | |||
284 | return $body; |
||
285 | } |
||
286 | |||
287 | |||
288 | /** |
||
289 | * Returns the PSR-7 response object for the request |
||
290 | * |
||
291 | * @return \Psr\Http\Message\ResponseInterface Response object |
||
292 | */ |
||
293 | public function response() : \Psr\Http\Message\ResponseInterface |
||
294 | { |
||
295 | return $this->view()->response(); |
||
296 | } |
||
297 | |||
298 | |||
299 | /** |
||
300 | * Adds the decorators to the client object |
||
301 | * |
||
302 | * @param \Aimeos\Admin\JQAdm\Iface $client Admin object |
||
303 | * @param array $decorators List of decorator name that should be wrapped around the client |
||
304 | * @param string $classprefix Decorator class prefix, e.g. "\Aimeos\Admin\JQAdm\Catalog\Decorator\" |
||
305 | * @return \Aimeos\Admin\JQAdm\Iface Admin object |
||
306 | */ |
||
307 | protected function addDecorators( \Aimeos\Admin\JQAdm\Iface $client, array $decorators, string $classprefix ) : \Aimeos\Admin\JQAdm\Iface |
||
308 | { |
||
309 | foreach( $decorators as $name ) |
||
310 | { |
||
311 | $classname = $classprefix . $name; |
||
312 | |||
313 | if( ctype_alnum( $name ) === false ) |
||
314 | { |
||
315 | $msg = $this->context->translate( 'admin', 'Invalid class name "%1$s"' ); |
||
316 | throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, $classname ) ); |
||
317 | } |
||
318 | |||
319 | if( class_exists( $classname ) === false ) |
||
320 | { |
||
321 | $msg = $this->context->translate( 'admin', 'Class "%1$s" not found' ); |
||
322 | throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, $classname ) ); |
||
323 | } |
||
324 | |||
325 | $client = new $classname( $client, $this->context ); |
||
326 | |||
327 | \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Admin\\JQAdm\\Common\\Decorator\\Iface', $client ); |
||
328 | } |
||
329 | |||
330 | return $client; |
||
331 | } |
||
332 | |||
333 | |||
334 | /** |
||
335 | * Adds the decorators to the client object |
||
336 | * |
||
337 | * @param \Aimeos\Admin\JQAdm\Iface $client Admin object |
||
338 | * @param string $path Admin string in lower case, e.g. "catalog/detail/basic" |
||
339 | * @return \Aimeos\Admin\JQAdm\Iface Admin object |
||
340 | */ |
||
341 | protected function addClientDecorators( \Aimeos\Admin\JQAdm\Iface $client, string $path ) : \Aimeos\Admin\JQAdm\Iface |
||
342 | { |
||
343 | if( !is_string( $path ) || $path === '' ) |
||
|
|||
344 | { |
||
345 | $msg = $this->context->translate( 'admin', 'Invalid domain "%1$s"' ); |
||
346 | throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, $path ) ); |
||
347 | } |
||
348 | |||
349 | $localClass = str_replace( '/', '\\', ucwords( $path, '/' ) ); |
||
350 | $config = $this->context->config(); |
||
351 | |||
352 | $classprefix = '\\Aimeos\\Admin\\JQAdm\\Common\\Decorator\\'; |
||
353 | $decorators = $config->get( 'admin/jqadm/' . $path . '/decorators/global', [] ); |
||
354 | $client = $this->addDecorators( $client, $decorators, $classprefix ); |
||
355 | |||
356 | $classprefix = '\\Aimeos\\Admin\\JQAdm\\' . $localClass . '\\Decorator\\'; |
||
357 | $decorators = $config->get( 'admin/jqadm/' . $path . '/decorators/local', [] ); |
||
358 | $client = $this->addDecorators( $client, $decorators, $classprefix ); |
||
359 | |||
360 | return $client; |
||
361 | } |
||
362 | |||
363 | |||
364 | /** |
||
365 | * Modifiy several items at once |
||
366 | * |
||
367 | * @param string $domain Data domain of the items |
||
368 | * @param string|null $resource Resource name or null for domain name |
||
369 | * @return string|null Output to display |
||
370 | */ |
||
371 | protected function batchBase( string $domain, string $resource = null ) : ?string |
||
372 | { |
||
373 | $view = $this->view(); |
||
374 | |||
375 | if( !empty( $ids = $view->param( 'id' ) ) ) |
||
376 | { |
||
377 | $manager = \Aimeos\MShop::create( $this->context(), $domain ); |
||
378 | $filter = $manager->filter()->add( [str_replace( '/', '.', $domain ) . '.id' => $ids] )->slice( 0, count( $ids ) ); |
||
379 | $items = $manager->search( $filter, $this->getDomains() ); |
||
380 | |||
381 | $data = $view->param( 'item', [] ); |
||
382 | |||
383 | foreach( $items as $item ) { |
||
384 | $temp = $data; $item->fromArray( $temp, true ); |
||
385 | } |
||
386 | |||
387 | $view->items = $items; |
||
388 | |||
389 | foreach( $this->getSubClients() as $client ) { |
||
390 | $client->batch(); |
||
391 | } |
||
392 | |||
393 | $manager->save( $items ); |
||
394 | } |
||
395 | |||
396 | return $this->redirect( $resource ?: $domain, 'search', null, 'save' ); |
||
397 | } |
||
398 | |||
399 | |||
400 | /** |
||
401 | * Returns the sub-client given by its name. |
||
402 | * |
||
403 | * @param string $path Name of the sub-part in lower case (can contain a path like catalog/filter/tree) |
||
404 | * @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
||
405 | * @return \Aimeos\Admin\JQAdm\Iface Sub-part object |
||
406 | */ |
||
407 | protected function createSubClient( string $path, string $name = null ) : \Aimeos\Admin\JQAdm\Iface |
||
435 | } |
||
436 | |||
437 | |||
438 | /** |
||
439 | * Returns the value for the given key in the array |
||
440 | * |
||
441 | * @param array $values Multi-dimensional associative list of key/value pairs |
||
442 | * @param string $key Parameter key like "name" or "list/test" for associative arrays |
||
443 | * @param mixed $default Returned value if no one for key is available |
||
444 | * @return mixed Value from the array or default value if not present in array |
||
445 | */ |
||
446 | protected function val( array $values, $key, $default = null ) |
||
447 | { |
||
448 | foreach( explode( '/', trim( $key, '/' ) ) as $part ) |
||
449 | { |
||
450 | if( is_array( $values ) && isset( $values[$part] ) ) { |
||
451 | $values = $values[$part]; |
||
452 | } else { |
||
453 | return $default; |
||
454 | } |
||
455 | } |
||
456 | |||
457 | return $values; |
||
458 | } |
||
459 | |||
460 | |||
461 | /** |
||
462 | * Returns the known client parameters and their values |
||
463 | * |
||
464 | * @param array $names List of parameter names |
||
465 | * @return array Associative list of parameters names as key and their values |
||
466 | */ |
||
467 | protected function getClientParams( $names = ['id', 'resource', 'site', 'locale'] ) : array |
||
479 | } |
||
480 | |||
481 | |||
482 | /** |
||
483 | * Returns the domain names whose items should be fetched too |
||
484 | * |
||
485 | * @return string[] List of domain names |
||
486 | */ |
||
487 | protected function getDomains() : array |
||
490 | } |
||
491 | |||
492 | |||
493 | /** |
||
494 | * Returns the context object. |
||
495 | * |
||
496 | * @return \Aimeos\MShop\ContextIface Context object |
||
497 | */ |
||
498 | protected function context() : \Aimeos\MShop\ContextIface |
||
501 | } |
||
502 | |||
503 | |||
504 | /** |
||
505 | * Returns the available class names without namespace that are stored in the given path |
||
506 | * |
||
507 | * @param string $relpath Path relative to the include paths |
||
508 | * @param string[] $excludes List of file names to execlude |
||
509 | * @return string[] List of available class names |
||
510 | */ |
||
511 | protected function getClassNames( string $relpath, array $excludes = ['Base.php', 'Iface.php', 'Example.php', 'None.php'] ) : array |
||
512 | { |
||
513 | $list = []; |
||
514 | |||
515 | foreach( $this->getAimeos()->getIncludePaths() as $path ) |
||
516 | { |
||
517 | $path .= DIRECTORY_SEPARATOR . $relpath; |
||
518 | |||
519 | if( is_dir( $path ) ) |
||
520 | { |
||
521 | foreach( new \DirectoryIterator( $path ) as $entry ) |
||
522 | { |
||
523 | if( $entry->isFile() && !in_array( $entry->getFileName(), $excludes ) ) { |
||
524 | $list[] = pathinfo( $entry->getFileName(), PATHINFO_FILENAME ); |
||
525 | } |
||
526 | } |
||
527 | } |
||
528 | } |
||
529 | |||
530 | sort( $list ); |
||
531 | return $list; |
||
532 | } |
||
533 | |||
534 | |||
535 | /** |
||
536 | * Returns the array of criteria conditions based on the given parameters |
||
537 | * |
||
538 | * @param array $params List of criteria data with condition, sorting and paging |
||
539 | * @return array Multi-dimensional associative list of criteria conditions |
||
540 | */ |
||
541 | protected function getCriteriaConditions( array $params ) : array |
||
542 | { |
||
543 | $expr = []; |
||
544 | |||
545 | if( isset( $params['key'] ) ) |
||
546 | { |
||
547 | foreach( (array) $params['key'] as $idx => $key ) |
||
548 | { |
||
549 | if( $key != '' && isset( $params['op'][$idx] ) && $params['op'][$idx] != '' |
||
550 | && isset( $params['val'][$idx] ) && $params['val'][$idx] != '' |
||
551 | ) { |
||
552 | $expr[] = [$params['op'][$idx] => [$key => $params['val'][$idx]]]; |
||
553 | } |
||
554 | } |
||
555 | |||
556 | if( !empty( $expr ) ) { |
||
557 | $expr = ['&&' => $expr]; |
||
558 | } |
||
559 | } |
||
560 | |||
561 | return $expr; |
||
562 | } |
||
563 | |||
564 | |||
565 | /** |
||
566 | * Returns the outer decoratorator of the object |
||
567 | * |
||
568 | * @return \Aimeos\Admin\JQAdm\Iface Outmost object |
||
569 | */ |
||
570 | protected function object() : Iface |
||
571 | { |
||
572 | if( isset( $this->object ) ) { |
||
573 | return $this->object; |
||
574 | } |
||
575 | |||
576 | return $this; |
||
577 | } |
||
578 | |||
579 | |||
580 | /** |
||
581 | * Returns the sub-client given by its name. |
||
582 | * |
||
583 | * @param string $type Name of the client type |
||
584 | * @param string|null $name Name of the sub-client (Default if null) |
||
585 | * @return \Aimeos\Admin\JQAdm\Iface Sub-client object |
||
586 | */ |
||
587 | public function getSubClient( string $type, string $name = null ) : \Aimeos\Admin\JQAdm\Iface |
||
588 | { |
||
589 | $msg = $this->context()->translate( 'admin', 'Not implemented' ); |
||
590 | throw new \Aimeos\Admin\JQAdm\Exception( $msg ); |
||
591 | } |
||
592 | |||
593 | |||
594 | /** |
||
595 | * Returns the configured sub-clients or the ones named in the default parameter if none are configured. |
||
596 | * |
||
597 | * @return array List of sub-clients implementing \Aimeos\Admin\JQAdm\Iface ordered in the same way as the names |
||
598 | */ |
||
599 | protected function getSubClients() : array |
||
600 | { |
||
601 | if( !isset( $this->subclients ) ) |
||
602 | { |
||
603 | $this->subclients = []; |
||
604 | |||
605 | foreach( $this->getSubClientNames() as $name ) { |
||
606 | $this->subclients[] = $this->getSubClient( $name ); |
||
607 | } |
||
608 | } |
||
609 | |||
610 | return $this->subclients; |
||
611 | } |
||
612 | |||
613 | |||
614 | /** |
||
615 | * Returns the list of sub-client names configured for the client. |
||
616 | * |
||
617 | * @return array List of admin client names |
||
618 | */ |
||
619 | protected function getSubClientNames() : array |
||
622 | } |
||
623 | |||
624 | |||
625 | /** |
||
626 | * Initializes the criteria object based on the given parameter |
||
627 | * |
||
628 | * @param \Aimeos\Base\Criteria\Iface $criteria Criteria object |
||
629 | * @param array $params List of criteria data with condition, sorting and paging |
||
630 | * @return \Aimeos\Base\Criteria\Iface Initialized criteria object |
||
631 | */ |
||
632 | protected function initCriteria( \Aimeos\Base\Criteria\Iface $criteria, array $params ) : \Aimeos\Base\Criteria\Iface |
||
633 | { |
||
634 | if( isset( $params['sort'] ) && !empty( $params['sort'] ) ) { |
||
635 | $criteria->order( $params['sort'] ); |
||
636 | } |
||
637 | |||
638 | return $criteria->slice( $params['page']['offset'] ?? 0, $params['page']['limit'] ?? 25 ) |
||
639 | ->add( $criteria->parse( $this->getCriteriaConditions( $params['filter'] ?? [] ) ) ); |
||
640 | } |
||
641 | |||
642 | |||
643 | /** |
||
644 | * Flattens the nested configuration array |
||
645 | * |
||
646 | * @param array $config Multi-dimensional list of key/value pairs |
||
647 | * @param string $path Path of keys separated by slashes (/) to add new values for |
||
648 | * @return array List of arrays with "key" and "val" keys |
||
649 | */ |
||
650 | protected function flatten( array $config, string $path = '' ) : array |
||
651 | { |
||
652 | $list = []; |
||
653 | |||
654 | foreach( $config as $key => $val ) |
||
655 | { |
||
656 | if( is_array( $val ) ) { |
||
657 | $list = array_merge( $list, $this->flatten( $val, $path . '/' . $key ) ); |
||
658 | } else { |
||
659 | $list[] = ['key' => trim( $path . '/' . $key, '/' ), 'val' => $val]; |
||
660 | } |
||
661 | } |
||
662 | |||
663 | return $list; |
||
664 | } |
||
665 | |||
666 | |||
667 | /** |
||
668 | * Writes the exception details to the log |
||
669 | * |
||
670 | * @param \Exception $e Exception object |
||
671 | * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls |
||
672 | */ |
||
673 | protected function log( \Exception $e ) : Iface |
||
674 | { |
||
675 | $msg = $e->getMessage() . PHP_EOL; |
||
676 | |||
677 | if( $e instanceof \Aimeos\Admin\JQAdm\Exception ) { |
||
678 | $msg .= print_r( $e->getDetails(), true ) . PHP_EOL; |
||
679 | } |
||
680 | |||
681 | $this->context->logger()->error( $msg . $e->getTraceAsString(), 'admin/jqadm' ); |
||
682 | |||
683 | return $this; |
||
684 | } |
||
685 | |||
686 | |||
687 | /** |
||
688 | * Adds a redirect to the response for the next action |
||
689 | * |
||
690 | * @param string $resource Resource name |
||
691 | * @param string|null $action Next action |
||
692 | * @param string|null $id ID of the next resource item |
||
693 | * @param string|null $method Current method name |
||
694 | * @param array $params URL parameters to use |
||
695 | * @return string|null Returns value for the actions |
||
696 | */ |
||
697 | protected function redirect( string $resource, ?string $action, string $id = null, |
||
698 | string $method = null, array $params = [] ) : ?string |
||
699 | { |
||
700 | $params += $this->getClientParams(); |
||
701 | $context = $this->context(); |
||
702 | $view = $this->view(); |
||
703 | |||
704 | $params['resource'] = $resource; |
||
705 | unset( $params['id'] ); |
||
706 | |||
707 | switch( $action ) |
||
708 | { |
||
709 | case 'search': |
||
710 | $url = $view->link( 'admin/jqadm/url/search', $params ); break; |
||
711 | case 'create': |
||
712 | $url = $view->link( 'admin/jqadm/url/create', ['parentid' => $id] + $params ); break; |
||
713 | case 'copy': |
||
714 | $url = $view->link( 'admin/jqadm/url/copy', ['id' => $id] + $params ); break; |
||
715 | default: |
||
716 | $url = $view->link( 'admin/jqadm/url/get', ['id' => $id] + $params ); |
||
717 | } |
||
718 | |||
719 | switch( $method ) |
||
720 | { |
||
721 | case 'save': |
||
722 | $context->session()->set( 'info', [$context->translate( 'admin', 'Item saved successfully' )] ); break; |
||
723 | case 'delete': |
||
724 | $context->session()->set( 'info', [$context->translate( 'admin', 'Item deleted successfully' )] ); break; |
||
725 | } |
||
726 | |||
727 | $view->response()->withStatus( 302 ); |
||
728 | $view->response()->withHeader( 'Location', $url ); |
||
729 | $view->response()->withHeader( 'Cache-Control', 'no-store' ); |
||
730 | |||
731 | return null; |
||
732 | } |
||
733 | |||
734 | |||
735 | /** |
||
736 | * Writes the exception details to the log |
||
737 | * |
||
738 | * @param \Exception $e Exception object |
||
739 | * @param string $method Method it's called from |
||
740 | * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls |
||
741 | */ |
||
742 | protected function report( \Exception $e, string $method ) : Iface |
||
768 | } |
||
769 | |||
770 | |||
771 | /** |
||
772 | * Checks and returns the request parameter for the given name |
||
773 | * |
||
774 | * @param string $name Name of the request parameter, can be a path like 'page/limit' |
||
775 | * @return mixed Parameter value |
||
776 | * @throws \Aimeos\Admin\JQAdm\Exception If the parameter is missing |
||
777 | */ |
||
778 | protected function require( string $name ) |
||
779 | { |
||
780 | if( ( $value = $this->view()->param( $name ) ) !== null ) { |
||
781 | return $value; |
||
782 | } |
||
783 | |||
784 | $msg = $this->context->translate( 'admin', 'Required parameter "%1$s" is missing' ); |
||
785 | throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, $name ) ); |
||
786 | } |
||
787 | |||
788 | |||
789 | /** |
||
790 | * Stores and returns the parameters used for searching items |
||
791 | * |
||
792 | * @param array $params GET/POST parameter set |
||
793 | * @param string $name Name of the panel/subpanel |
||
794 | * @return array Associative list of parameters for searching items |
||
795 | */ |
||
796 | protected function storeFilter( array $params, string $name ) : array |
||
813 | ]; |
||
814 | } |
||
815 | |||
816 | |||
817 | /** |
||
818 | * Throws an exception with given details |
||
819 | * |
||
820 | * @param array $errors List of key/message pairs of errors |
||
821 | * @throws \Aimeos\Admin\JQAdm\Exception Exception with error details |
||
822 | */ |
||
823 | protected function notify( array $errors ) : Iface |
||
840 | } |
||
841 | } |
||
842 |