Standard::search()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 32
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), 2016-2026
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Dashboard;
12
13
sprintf( 'dashboard' ); // for translation
14
15
16
/**
17
 * Default implementation of dashboard JQAdm client.
18
 *
19
 * @package Admin
20
 * @subpackage JQAdm
21
 */
22
class Standard
23
	extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base
24
	implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface
25
{
26
	/** admin/jqadm/dashboard/name
27
	 * Class name of the used dashboard panel implementation
28
	 *
29
	 * Each default admin client can be replace by an alternative imlementation.
30
	 * To use this implementation, you have to set the last part of the class
31
	 * name as configuration value so the client factory knows which class it
32
	 * has to instantiate.
33
	 *
34
	 * For example, if the name of the default class is
35
	 *
36
	 *  \Aimeos\Admin\JQAdm\Dashboard\Standard
37
	 *
38
	 * and you want to replace it with your own version named
39
	 *
40
	 *  \Aimeos\Admin\JQAdm\Dashboard\Myfavorite
41
	 *
42
	 * then you have to set the this configuration option:
43
	 *
44
	 *  admin/jqadm/dashboard/name = Myfavorite
45
	 *
46
	 * The value is the last part of your own class name and it's case sensitive,
47
	 * so take care that the configuration value is exactly named like the last
48
	 * part of the class name.
49
	 *
50
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
51
	 * characters are possible! You should always start the last part of the class
52
	 * name with an upper case character and continue only with lower case characters
53
	 * or numbers. Avoid chamel case names like "MyFavorite"!
54
	 *
55
	 * @param string Last part of the class name
56
	 * @since 2016.07
57
	 */
58
59
60
	/**
61
	 * Deletes a resource
62
	 *
63
	 * @return string|null Output to display or null for none
64
	 */
65
	public function delete() : ?string
66
	{
67
		parent::delete();
68
		return $this->search();
69
	}
70
71
72
	/**
73
	 * Returns a list of resource according to the conditions
74
	 *
75
	 * @return string Output to display
76
	 */
77
	public function search() : ?string
78
	{
79
		$view = $this->view();
80
81
		try {
82
			$view->listBody = parent::search();
83
		} catch( \Exception $e ) {
84
			$this->report( $e, 'search' );
85
		}
86
87
		/** admin/jqadm/dashboard/template-list
88
		 * Relative path to the HTML body template of the dashboard.
89
		 *
90
		 * The template file contains the HTML code and processing instructions
91
		 * to generate the result shown in the body of the frontend. The
92
		 * configuration string is the path to the template file relative
93
		 * to the templates directory (usually in templates/admin/jqadm).
94
		 *
95
		 * You can overwrite the template file configuration in extensions and
96
		 * provide alternative templates. These alternative templates should be
97
		 * named like the default one but with the string "default" replaced by
98
		 * an unique name. You may use the name of your project for this. If
99
		 * you've implemented an alternative client class as well, "default"
100
		 * should be replaced by the name of the new class.
101
		 *
102
		 * @param string Relative path to the template creating the HTML code
103
		 * @since 2016.04
104
		 */
105
		$tplconf = 'admin/jqadm/dashboard/template-list';
106
		$default = 'dashboard/list';
107
108
		return $view->render( $view->config( $tplconf, $default ) );
109
	}
110
111
112
	/**
113
	 * Returns the sub-client given by its name.
114
	 *
115
	 * @param string $type Name of the client type
116
	 * @param string|null $name Name of the sub-client (Default if null)
117
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
118
	 */
119
	public function getSubClient( string $type, ?string $name = null ) : \Aimeos\Admin\JQAdm\Iface
120
	{
121
		/** admin/jqadm/dashboard/decorators/excludes
122
		 * Excludes decorators added by the "common" option from the dashboard JQAdm client
123
		 *
124
		 * Decorators extend the functionality of a class by adding new aspects
125
		 * (e.g. log what is currently done), executing the methods of the underlying
126
		 * class only in certain conditions (e.g. only for logged in users) or
127
		 * modify what is returned to the caller.
128
		 *
129
		 * This option allows you to remove a decorator added via
130
		 * "client/jqadm/common/decorators/default" before they are wrapped
131
		 * around the JQAdm client.
132
		 *
133
		 *  admin/jqadm/dashboard/decorators/excludes = array( 'decorator1' )
134
		 *
135
		 * This would remove the decorator named "decorator1" from the list of
136
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
137
		 * "client/jqadm/common/decorators/default" to the JQAdm client.
138
		 *
139
		 * @param array List of decorator names
140
		 * @since 2016.07
141
		 * @see admin/jqadm/common/decorators/default
142
		 * @see admin/jqadm/dashboard/decorators/global
143
		 * @see admin/jqadm/dashboard/decorators/local
144
		 */
145
146
		/** admin/jqadm/dashboard/decorators/global
147
		 * Adds a list of globally available decorators only to the dashboard JQAdm client
148
		 *
149
		 * Decorators extend the functionality of a class by adding new aspects
150
		 * (e.g. log what is currently done), executing the methods of the underlying
151
		 * class only in certain conditions (e.g. only for logged in users) or
152
		 * modify what is returned to the caller.
153
		 *
154
		 * This option allows you to wrap global decorators
155
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
156
		 *
157
		 *  admin/jqadm/dashboard/decorators/global = array( 'decorator1' )
158
		 *
159
		 * This would add the decorator named "decorator1" defined by
160
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
161
		 *
162
		 * @param array List of decorator names
163
		 * @since 2016.07
164
		 * @see admin/jqadm/common/decorators/default
165
		 * @see admin/jqadm/dashboard/decorators/excludes
166
		 * @see admin/jqadm/dashboard/decorators/local
167
		 */
168
169
		/** admin/jqadm/dashboard/decorators/local
170
		 * Adds a list of local decorators only to the dashboard JQAdm client
171
		 *
172
		 * Decorators extend the functionality of a class by adding new aspects
173
		 * (e.g. log what is currently done), executing the methods of the underlying
174
		 * class only in certain conditions (e.g. only for logged in users) or
175
		 * modify what is returned to the caller.
176
		 *
177
		 * This option allows you to wrap local decorators
178
		 * ("\Aimeos\Admin\JQAdm\Dashboard\Decorator\*") around the JQAdm client.
179
		 *
180
		 *  admin/jqadm/dashboard/decorators/local = array( 'decorator2' )
181
		 *
182
		 * This would add the decorator named "decorator2" defined by
183
		 * "\Aimeos\Admin\JQAdm\Dashboard\Decorator\Decorator2" only to the JQAdm client.
184
		 *
185
		 * @param array List of decorator names
186
		 * @since 2016.07
187
		 * @see admin/jqadm/common/decorators/default
188
		 * @see admin/jqadm/dashboard/decorators/excludes
189
		 * @see admin/jqadm/dashboard/decorators/global
190
		 */
191
		return $this->createSubClient( 'dashboard/' . $type, $name );
192
	}
193
194
195
	/**
196
	 * Returns the list of sub-client names configured for the client.
197
	 *
198
	 * @return array List of JQAdm client names
199
	 */
200
	protected function getSubClientNames() : array
201
	{
202
		/** admin/jqadm/dashboard/subparts
203
		 * List of JQAdm sub-clients rendered within the dashboard section
204
		 *
205
		 * The output of the frontend is composed of the code generated by the JQAdm
206
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
207
		 * that are responsible for rendering certain sub-parts of the output. The
208
		 * sub-clients can contain JQAdm clients themselves and therefore a
209
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
210
		 * the output that is placed inside the container of its parent.
211
		 *
212
		 * At first, always the JQAdm code generated by the parent is printed, then
213
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
214
		 * determines the order of the output of these sub-clients inside the parent
215
		 * container. If the configured list of clients is
216
		 *
217
		 *  array( "subclient1", "subclient2" )
218
		 *
219
		 * you can easily change the order of the output by reordering the subparts:
220
		 *
221
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
222
		 *
223
		 * You can also remove one or more parts if they shouldn't be rendered:
224
		 *
225
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
226
		 *
227
		 * As the clients only generates structural JQAdm, the layout defined via CSS
228
		 * should support adding, removing or reordering content by a fluid like
229
		 * design.
230
		 *
231
		 * @param array List of sub-client names
232
		 * @since 2016.07
233
		 */
234
		return $this->context()->config()->get( 'admin/jqadm/dashboard/subparts', [] );
235
	}
236
}
237