Passed
Push — master ( 596853...253ba3 )
by Aimeos
16:40
created

Base::getContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2021
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm;
12
13
sprintf( 'type' ); // for translation
14
15
16
/**
17
 * Common abstract class for all admin client classes.
18
 *
19
 * @package Admin
20
 * @subpackage JQAdm
21
 */
22
abstract class Base
23
	implements \Aimeos\Admin\JQAdm\Iface
24
{
25
	private $view;
26
	private $aimeos;
27
	private $context;
28
	private $subclients;
29
	private $object;
30
31
32
	/**
33
	 * Initializes the class instance.
34
	 *
35
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
36
	 */
37
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
38
	{
39
		$this->context = $context;
40
	}
41
42
43
	/**
44
	 * Catch unknown methods
45
	 *
46
	 * @param string $name Name of the method
47
	 * @param array $param List of method parameter
48
	 * @throws \Aimeos\Admin\JQAdm\Exception If method call failed
49
	 */
50
	public function __call( string $name, array $param )
51
	{
52
		throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Unable to call method "%1$s"', $name ) );
53
	}
54
55
56
	/**
57
	 * Adds the required data used in the attribute template
58
	 *
59
	 * @param \Aimeos\MW\View\Iface $view View object
60
	 * @return \Aimeos\MW\View\Iface View object with assigned parameters
61
	 */
62
	public function addData( \Aimeos\MW\View\Iface $view ) : \Aimeos\MW\View\Iface
63
	{
64
		return $view;
65
	}
66
67
68
	/**
69
	 * Returns the Aimeos bootstrap object
70
	 *
71
	 * @return \Aimeos\Bootstrap The Aimeos bootstrap object
72
	 */
73
	public function getAimeos() : \Aimeos\Bootstrap
74
	{
75
		if( !isset( $this->aimeos ) ) {
76
			throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Aimeos object not available' ) );
77
		}
78
79
		return $this->aimeos;
80
	}
81
82
83
	/**
84
	 * Sets the Aimeos bootstrap object
85
	 *
86
	 * @param \Aimeos\Bootstrap $aimeos The Aimeos bootstrap object
87
	 * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls
88
	 */
89
	public function setAimeos( \Aimeos\Bootstrap $aimeos ) : \Aimeos\Admin\JQAdm\Iface
90
	{
91
		$this->aimeos = $aimeos;
92
		return $this;
93
	}
94
95
96
	/**
97
	 * Makes the outer decorator object available to inner objects
98
	 *
99
	 * @param \Aimeos\Admin\JQAdm\Iface $object Outmost object
100
	 * @return \Aimeos\Admin\JQAdm\Iface Same object for fluent interface
101
	 */
102
	public function setObject( \Aimeos\Admin\JQAdm\Iface $object ) : \Aimeos\Admin\JQAdm\Iface
103
	{
104
		$this->object = $object;
105
		return $this;
106
	}
107
108
109
	/**
110
	 * Returns the view object that will generate the admin output.
111
	 *
112
	 * @return \Aimeos\MW\View\Iface The view object which generates the admin output
113
	 */
114
	public function getView() : \Aimeos\MW\View\Iface
115
	{
116
		if( !isset( $this->view ) ) {
117
			throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'No view available' ) );
118
		}
119
120
		return $this->view;
121
	}
122
123
124
	/**
125
	 * Sets the view object that will generate the admin output.
126
	 *
127
	 * @param \Aimeos\MW\View\Iface $view The view object which generates the admin output
128
	 * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls
129
	 */
130
	public function setView( \Aimeos\MW\View\Iface $view ) : \Aimeos\Admin\JQAdm\Iface
131
	{
132
		$this->view = $view;
133
		return $this;
134
	}
135
136
137
	/**
138
	 * Copies a resource
139
	 *
140
	 * @return string|null Output to display
141
	 */
142
	public function copy() : ?string
143
	{
144
		$body = null;
145
		$view = $this->getView();
146
147
		foreach( $this->getSubClients() as $idx => $client )
148
		{
149
			$view->tabindex = ++$idx + 1;
150
			$body .= $client->copy();
151
		}
152
153
		return $body;
154
	}
155
156
157
	/**
158
	 * Creates a new resource
159
	 *
160
	 * @return string|null Output to display
161
	 */
162
	public function create() : ?string
163
	{
164
		$body = null;
165
		$view = $this->getView();
166
167
		foreach( $this->getSubClients() as $idx => $client )
168
		{
169
			$view->tabindex = ++$idx + 1;
170
			$body .= $client->create();
171
		}
172
173
		return $body;
174
	}
175
176
177
	/**
178
	 * Deletes a resource
179
	 *
180
	 * @return string|null Output to display
181
	 */
182
	public function delete() : ?string
183
	{
184
		$body = null;
185
186
		foreach( $this->getSubClients() as $client ) {
187
			$body .= $client->delete();
188
		}
189
190
		return $body;
191
	}
192
193
194
	/**
195
	 * Exports a resource
196
	 *
197
	 * @return string|null Output to display
198
	 */
199
	public function export() : ?string
200
	{
201
		$body = null;
202
203
		foreach( $this->getSubClients() as $client ) {
204
			$body .= $client->export();
205
		}
206
207
		return $body;
208
	}
209
210
211
	/**
212
	 * Returns a resource
213
	 *
214
	 * @return string|null Output to display
215
	 */
216
	public function get() : ?string
217
	{
218
		$body = null;
219
		$view = $this->getView();
220
221
		foreach( $this->getSubClients() as $idx => $client )
222
		{
223
			$view->tabindex = ++$idx + 1;
224
			$body .= $client->get();
225
		}
226
227
		return $body;
228
	}
229
230
231
	/**
232
	 * Imports a resource
233
	 *
234
	 * @return string|null Output to display
235
	 * @deprecated 2021.01
236
	 */
237
	public function import() : ?string
238
	{
239
		$body = null;
240
241
		foreach( $this->getSubClients() as $client ) {
242
			$body .= $client->import();
243
		}
244
245
		return null;
246
	}
247
248
249
	/**
250
	 * Saves the data
251
	 *
252
	 * @return string|null Output to display
253
	 */
254
	public function save() : ?string
255
	{
256
		$body = null;
257
258
		foreach( $this->getSubClients() as $client ) {
259
			$body .= $client->save();
260
		}
261
262
		return $body;
263
	}
264
265
266
	/**
267
	 * Returns a list of resource according to the conditions
268
	 *
269
	 * @return string|null Output to display
270
	 */
271
	public function search() : ?string
272
	{
273
		$body = null;
274
275
		foreach( $this->getSubClients() as $client ) {
276
			$body .= $client->search();
277
		}
278
279
		return $body;
280
	}
281
282
283
	/**
284
	 * Adds the decorators to the client object
285
	 *
286
	 * @param \Aimeos\Admin\JQAdm\Iface $client Admin object
287
	 * @param array $decorators List of decorator name that should be wrapped around the client
288
	 * @param string $classprefix Decorator class prefix, e.g. "\Aimeos\Admin\JQAdm\Catalog\Decorator\"
289
	 * @return \Aimeos\Admin\JQAdm\Iface Admin object
290
	 */
291
	protected function addDecorators( \Aimeos\Admin\JQAdm\Iface $client, array $decorators, string $classprefix ) : \Aimeos\Admin\JQAdm\Iface
292
	{
293
		foreach( $decorators as $name )
294
		{
295
			if( ctype_alnum( $name ) === false )
296
			{
297
				$classname = is_string( $name ) ? $classprefix . $name : '<not a string>';
298
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Invalid class name "%1$s"', $classname ) );
299
			}
300
301
			$classname = $classprefix . $name;
302
303
			if( class_exists( $classname ) === false ) {
304
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Class "%1$s" not found', $classname ) );
305
			}
306
307
			$client = new $classname( $client, $this->context );
308
309
			\Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Admin\\JQAdm\\Common\\Decorator\\Iface', $client );
310
		}
311
312
		return $client;
313
	}
314
315
316
	/**
317
	 * Adds the decorators to the client object
318
	 *
319
	 * @param \Aimeos\Admin\JQAdm\Iface $client Admin object
320
	 * @param string $path Admin string in lower case, e.g. "catalog/detail/basic"
321
	 * @return \Aimeos\Admin\JQAdm\Iface Admin object
322
	 */
323
	protected function addClientDecorators( \Aimeos\Admin\JQAdm\Iface $client, string $path ) : \Aimeos\Admin\JQAdm\Iface
324
	{
325
		if( !is_string( $path ) || $path === '' ) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
326
			throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Invalid domain "%1$s"', $path ) );
327
		}
328
329
		$localClass = str_replace( '/', '\\', ucwords( $path, '/' ) );
330
		$config = $this->context->getConfig();
331
332
		$classprefix = '\\Aimeos\\Admin\\JQAdm\\Common\\Decorator\\';
333
		$decorators = $config->get( 'admin/jqadm/' . $path . '/decorators/global', [] );
334
		$client = $this->addDecorators( $client, $decorators, $classprefix );
335
336
		$classprefix = '\\Aimeos\\Admin\\JQAdm\\' . $localClass . '\\Decorator\\';
337
		$decorators = $config->get( 'admin/jqadm/' . $path . '/decorators/local', [] );
338
		$client = $this->addDecorators( $client, $decorators, $classprefix );
339
340
		return $client;
341
	}
342
343
344
	/**
345
	 * Returns the sub-client given by its name.
346
	 *
347
	 * @param string $path Name of the sub-part in lower case (can contain a path like catalog/filter/tree)
348
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
349
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-part object
350
	 */
351
	protected function createSubClient( string $path, string $name = null ) : \Aimeos\Admin\JQAdm\Iface
352
	{
353
		$path = strtolower( $path );
354
355
		if( $name === null ) {
356
			$name = $this->context->getConfig()->get( 'admin/jqadm/' . $path . '/name', 'Standard' );
357
		}
358
359
		if( empty( $name ) || ctype_alnum( $name ) === false ) {
360
			throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Invalid characters in client name "%1$s"', $name ) );
361
		}
362
363
		$subnames = str_replace( '/', '\\', ucwords( $path, '/' ) );
364
365
		$classname = '\\Aimeos\\Admin\\JQAdm\\' . $subnames . '\\' . $name;
366
367
		if( class_exists( $classname ) === false ) {
368
			throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Class "%1$s" not available', $classname ) );
369
		}
370
371
		$object = new $classname( $this->context );
372
		$object = \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Admin\\JQAdm\\Iface', $object );
373
		$object = $this->addClientDecorators( $object, $path );
374
375
		return $object->setObject( $object )->setAimeos( $this->aimeos )->setView( $this->view );
0 ignored issues
show
Bug introduced by
The method setObject() does not exist on Aimeos\Admin\JQAdm\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface or Aimeos\Admin\JQAdm\Common\Decorator\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

375
		return $object->/** @scrutinizer ignore-call */ setObject( $object )->setAimeos( $this->aimeos )->setView( $this->view );
Loading history...
376
	}
377
378
379
	/**
380
	 * Returns the value for the given key in the array
381
	 *
382
	 * @param array $values Multi-dimensional associative list of key/value pairs
383
	 * @param string $key Parameter key like "name" or "list/test" for associative arrays
384
	 * @param mixed $default Returned value if no one for key is available
385
	 * @return mixed Value from the array or default value if not present in array
386
	 */
387
	protected function getValue( array $values, $key, $default = null )
388
	{
389
		foreach( explode( '/', trim( $key, '/' ) ) as $part )
390
		{
391
			if( array_key_exists( $part, $values ) ) {
392
				$values = $values[$part];
393
			} else {
394
				return $default;
395
			}
396
		}
397
398
		return $values;
399
	}
400
401
402
	/**
403
	 * Returns the known client parameters and their values
404
	 *
405
	 * @param array $names List of parameter names
406
	 * @return array Associative list of parameters names as key and their values
407
	 */
408
	protected function getClientParams( $names = ['id', 'resource', 'site', 'lang'] ) : array
409
	{
410
		$list = [];
411
412
		foreach( $names as $name )
413
		{
414
			if( ( $val = $this->view->param( $name ) ) !== null ) {
415
				$list[$name] = $val;
416
			}
417
		}
418
419
		return $list;
420
	}
421
422
423
	/**
424
	 * Returns the context object.
425
	 *
426
	 * @return \Aimeos\MShop\Context\Item\Iface Context object
427
	 */
428
	protected function getContext() : \Aimeos\MShop\Context\Item\Iface
429
	{
430
		return $this->context;
431
	}
432
433
434
	/**
435
	 * Returns the list of sub-client names configured for the client.
436
	 *
437
	 * @return array List of admin client names
438
	 */
439
	abstract protected function getSubClientNames() : array;
440
441
442
	/**
443
	 * Returns the available class names without namespace that are stored in the given path
444
	 *
445
	 * @param string $relpath Path relative to the include paths
446
	 * @param string[] $excludes List of file names to execlude
447
	 * @return string[] List of available class names
448
	 */
449
	protected function getClassNames( string $relpath, array $excludes = ['Base.php', 'Iface.php', 'Example.php', 'None.php'] ) : array
450
	{
451
		$list = [];
452
453
		foreach( $this->getAimeos()->getIncludePaths() as $path )
454
		{
455
			$path .= DIRECTORY_SEPARATOR . $relpath;
456
457
			if( is_dir( $path ) )
458
			{
459
				foreach( new \DirectoryIterator( $path ) as $entry )
460
				{
461
					if( $entry->isFile() && !in_array( $entry->getFileName(), $excludes ) ) {
462
						$list[] = pathinfo( $entry->getFileName(), PATHINFO_FILENAME );
463
					}
464
				}
465
			}
466
		}
467
468
		sort( $list );
469
		return $list;
470
	}
471
472
473
	/**
474
	 * Returns the array of criteria conditions based on the given parameters
475
	 *
476
	 * @param array $params List of criteria data with condition, sorting and paging
477
	 * @return array Multi-dimensional associative list of criteria conditions
478
	 */
479
	protected function getCriteriaConditions( array $params ) : array
480
	{
481
		$expr = [];
482
483
		if( isset( $params['key'] ) )
484
		{
485
			foreach( (array) $params['key'] as $idx => $key )
486
			{
487
				if( $key != '' && isset( $params['op'][$idx] ) && $params['op'][$idx] != ''
488
					&& isset( $params['val'][$idx] ) && $params['val'][$idx] != ''
489
				) {
490
					$expr[] = [$params['op'][$idx] => [$key => $params['val'][$idx]]];
491
				}
492
			}
493
494
			if( !empty( $expr ) ) {
495
				$expr = ['&&' => $expr];
496
			}
497
		}
498
499
		return $expr;
500
	}
501
502
503
	/**
504
	 * Returns the outer decoratorator of the object
505
	 *
506
	 * @return \Aimeos\Admin\JQAdm\Iface Outmost object
507
	 */
508
	protected function getObject() : Iface
509
	{
510
		if( isset( $this->object ) ) {
511
			return $this->object;
512
		}
513
514
		return $this;
515
	}
516
517
518
	/**
519
	 * Returns the configured sub-clients or the ones named in the default parameter if none are configured.
520
	 *
521
	 * @return array List of sub-clients implementing \Aimeos\Admin\JQAdm\Iface ordered in the same way as the names
522
	 */
523
	protected function getSubClients() : array
524
	{
525
		if( !isset( $this->subclients ) )
526
		{
527
			$this->subclients = [];
528
529
			foreach( $this->getSubClientNames() as $name ) {
530
				$this->subclients[] = $this->getSubClient( $name );
531
			}
532
		}
533
534
		return $this->subclients;
535
	}
536
537
538
	/**
539
	 * Initializes the criteria object based on the given parameter
540
	 *
541
	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
542
	 * @param array $params List of criteria data with condition, sorting and paging
543
	 * @return \Aimeos\MW\Criteria\Iface Initialized criteria object
544
	 */
545
	protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $params ) : \Aimeos\MW\Criteria\Iface
546
	{
547
		return $criteria->order( $params['sort'] ?? [] )
548
			->slice( $params['page']['offset'] ?? 0, $params['page']['limit'] ?? 25 )
549
			->add( $criteria->parse( $this->getCriteriaConditions( $params['filter'] ?? [] ) ) );
550
	}
551
552
553
	/**
554
	 * Writes the exception details to the log
555
	 *
556
	 * @param \Exception $e Exception object
557
	 * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls
558
	 */
559
	protected function log( \Exception $e ) : Iface
560
	{
561
		$logger = $this->context->getLogger();
562
		$logger->log( $e->getMessage(), \Aimeos\MW\Logger\Base::ERR, 'admin/jqadm' );
563
		$logger->log( $e->getTraceAsString(), \Aimeos\MW\Logger\Base::ERR, 'admin/jqadm' );
564
565
		return $this;
566
	}
567
568
569
	/**
570
	 * Returns a map of code/item pairs
571
	 *
572
	 * @param \Aimeos\MShop\Common\Item\Type\Iface[] $items Associative list of type items
573
	 * @return \Aimeos\MShop\Common\Item\Type\Iface[] Associative list of codes as keys and items as values
574
	 * @deprecated 2021.01
575
	 */
576
	protected function map( \Aimeos\Map $items ) : array
577
	{
578
		$list = [];
579
580
		foreach( $items as $item ) {
581
			$list[$item->getCode()] = $item;
582
		}
583
584
		return $list;
585
	}
586
587
588
	/**
589
	 * Adds a redirect to the response for the next action
590
	 *
591
	 * @param string $resource Resource name
592
	 * @param string|null $action Next action
593
	 * @param string|null $id ID of the next resource item
594
	 * @param string|null $act Current action name
595
	 * @return string|null Returns value for the actions
596
	 */
597
	protected function redirect( string $resource, ?string $action, string $id = null,
598
		string $method = null ) : ?string
599
	{
600
		$params = $this->getClientParams();
601
		$context = $this->getContext();
602
		$view = $this->getView();
603
604
		$params['resource'] = $resource;
605
		unset( $params['id'] );
606
607
		switch( $action )
608
		{
609
			case 'search':
610
				$target = $view->config( 'admin/jqadm/url/search/target' );
611
				$cntl = $view->config( 'admin/jqadm/url/search/controller', 'Jqadm' );
612
				$action = $view->config( 'admin/jqadm/url/search/action', 'search' );
613
				$conf = $view->config( 'admin/jqadm/url/search/config', [] );
614
				$url = $view->url( $target, $cntl, $action, $params, [], $conf );
615
				break;
616
			case 'create':
617
				$params['parentid'] = $id;
618
				$target = $view->config( 'admin/jqadm/url/create/target' );
619
				$cntl = $view->config( 'admin/jqadm/url/create/controller', 'Jqadm' );
620
				$action = $view->config( 'admin/jqadm/url/create/action', 'create' );
621
				$conf = $view->config( 'admin/jqadm/url/create/config', [] );
622
				$url = $view->url( $target, $cntl, $action, $params, [], $conf );
623
				break;
624
			case 'copy':
625
				$target = $view->config( 'admin/jqadm/url/copy/target' );
626
				$cntl = $view->config( 'admin/jqadm/url/copy/controller', 'Jqadm' );
627
				$action = $view->config( 'admin/jqadm/url/copy/action', 'copy' );
628
				$conf = $view->config( 'admin/jqadm/url/copy/config', [] );
629
				$url = $view->url( $target, $cntl, $action, ['id' => $id] + $params, [], $conf );
630
				break;
631
			default:
632
				$target = $view->config( 'admin/jqadm/url/get/target' );
633
				$cntl = $view->config( 'admin/jqadm/url/get/controller', 'Jqadm' );
634
				$action = $view->config( 'admin/jqadm/url/get/action', 'get' );
635
				$conf = $view->config( 'admin/jqadm/url/get/config', [] );
636
				$url = $view->url( $target, $cntl, $action, ['id' => $id] + $params, [], $conf );
637
		}
638
639
		switch( $method )
640
		{
641
			case 'save':
642
				$context->getSession()->set( 'info', [$context->getI18n()->dt( 'admin', 'Item saved successfully' )] ); break;
643
			case 'delete':
644
				$context->getSession()->set( 'info', [$context->getI18n()->dt( 'admin', 'Item deleted successfully' )] ); break;
645
		}
646
647
		$view->response()->withStatus( 302 );
648
		$view->response()->withHeader( 'Location', $url );
649
		$view->response()->withHeader( 'Cache-Control', 'no-store' );
650
651
		return null;
652
	}
653
654
655
	/**
656
	 * Writes the exception details to the log
657
	 *
658
	 * @param \Exception $e Exception object
659
	 * @param string $method Method it's called from
660
	 * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls
661
	 */
662
	protected function report( \Exception $e, string $method ) : Iface
663
	{
664
		$view = $this->view;
665
		$i18n = $this->context->getI18n();
666
667
		if( $e instanceof \Aimeos\Admin\JQAdm\Exception )
668
		{
669
			$view->errors = array_merge( $view->get( 'errors', [] ), [$e->getMessage()] );
670
			return $this;
671
		}
672
		elseif( $e instanceof \Aimeos\MShop\Exception )
673
		{
674
			$view->errors = array_merge( $view->get( 'errors', [] ), [$i18n->dt( 'mshop', $e->getMessage() )] );
675
			return $this;
676
		}
677
678
		switch( $method )
679
		{
680
			case 'save': $msg = $i18n->dt( 'admin', 'Error saving data' ); break;
681
			case 'delete': $msg = $i18n->dt( 'admin', 'Error deleting data' ); break;
682
			default: $msg = $i18n->dt( 'admin', 'Error retrieving data' ); break;
683
		}
684
685
		$view->errors = array_merge( $view->get( 'errors', [] ), [$msg] );
686
687
		return $this->log( $e );
688
	}
689
690
691
	/**
692
	 * Checks and returns the request parameter for the given name
693
	 *
694
	 * @param string $name Name of the request parameter, can be a path like 'page/limit'
695
	 * @return mixed Parameter value
696
	 * @throws \Aimeos\Admin\JQAdm\Exception If the parameter is missing
697
	 */
698
	protected function require( string $name )
699
	{
700
		if( ( $value = $this->getView()->param( $name ) ) !== null ) {
701
			return $value;
702
		}
703
704
		throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', $name ) );
705
	}
706
707
708
	/**
709
	 * Stores and returns the parameters used for searching items
710
	 *
711
	 * @param array $params GET/POST parameter set
712
	 * @param string $name Name of the panel/subpanel
713
	 * @return array Associative list of parameters for searching items
714
	 */
715
	protected function storeFilter( array $params, string $name ) : array
716
	{
717
		$key = 'aimeos/admin/jqadm/' . $name;
718
		$session = $this->getContext()->getSession();
719
720
		if( isset( $params['filter'] ) ) {
721
			$session->set( $key . '/filter', $params['filter'] );
722
		}
723
724
		if( isset( $params['sort'] ) ) {
725
			$session->set( $key . '/sort', $params['sort'] );
726
		}
727
728
		if( isset( $params['page'] ) ) {
729
			$session->set( $key . '/page', $params['page'] );
730
		}
731
732
		if( isset( $params['fields'] ) ) {
733
			$session->set( $key . '/fields', $params['fields'] );
734
		}
735
736
		return [
737
			'fields' => $session->get( $key . '/fields' ),
738
			'filter' => $session->get( $key . '/filter' ),
739
			'page' => $session->get( $key . '/page' ),
740
			'sort' => $session->get( $key . '/sort' ),
741
		];
742
	}
743
}
744