Passed
Push — master ( ace2f2...8e80f1 )
by Aimeos
03:44
created

Standard::save()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2022
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Type\Stock;
12
13
sprintf( 'type/stock' ); // for translation
14
15
16
/**
17
 * Default implementation of type stock JQAdm client.
18
 *
19
 * @package Admin
20
 * @subpackage JQAdm
21
 */
22
class Standard
23
	extends \Aimeos\Admin\JQAdm\Type\Base
24
	implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface
25
{
26
	/** admin/jqadm/type/stock/name
27
	 * Class name of the used account favorite client 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\Type\Stock\Standard
37
	 *
38
	 * and you want to replace it with your own version named
39
	 *
40
	 *  \Aimeos\Admin\JQAdm\Type\Stock\Myfavorite
41
	 *
42
	 * then you have to set the this configuration option:
43
	 *
44
	 *  admin/jqadm/type/stock/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 2017.10
57
	 * @category Developer
58
	 */
59
60
61
	/**
62
	 * Batch update of a resource
63
	 *
64
	 * @return string|null Output to display
65
	 */
66
	public function batch() : ?string
67
	{
68
		return $this->batchBase( 'stock' );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->batchBase('stock') targeting Aimeos\Admin\JQAdm\Type\Base::batchBase() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
69
	}
70
71
72
	/**
73
	 * Copies a resource
74
	 *
75
	 * @return string|null HTML output
76
	 */
77
	public function copy() : ?string
78
	{
79
		return $this->copyBase( 'stock' );
80
	}
81
82
83
	/**
84
	 * Creates a new resource
85
	 *
86
	 * @return string|null HTML output
87
	 */
88
	public function create() : ?string
89
	{
90
		return $this->createBase( 'stock' );
91
	}
92
93
94
	/**
95
	 * Deletes a resource
96
	 *
97
	 * @return string|null HTML output
98
	 */
99
	public function delete() : ?string
100
	{
101
		return $this->deleteBase( 'stock' );
102
	}
103
104
105
	/**
106
	 * Returns a single resource
107
	 *
108
	 * @return string|null HTML output
109
	 */
110
	public function get() : ?string
111
	{
112
		return $this->getBase( 'stock' );
113
	}
114
115
116
	/**
117
	 * Saves the data
118
	 *
119
	 * @return string|null HTML output
120
	 */
121
	public function save() : ?string
122
	{
123
		return $this->saveBase( 'stock' );
124
	}
125
126
127
	/**
128
	 * Returns a list of resource according to the conditions
129
	 *
130
	 * @return string|null HTML output
131
	 */
132
	public function search() : ?string
133
	{
134
		$view = $this->searchBase( 'stock' );
135
136
		/** admin/jqadm/type/stock/template-list
137
		 * Relative path to the HTML body template for the type list.
138
		 *
139
		 * The template file contains the HTML code and processing instructions
140
		 * to generate the result shown in the body of the frontend. The
141
		 * configuration string is the path to the template file relative
142
		 * to the templates directory (usually in admin/jqadm/templates).
143
		 *
144
		 * You can overwrite the template file configuration in extensions and
145
		 * provide alternative templates. These alternative templates should be
146
		 * named like the default one but with the string "default" replaced by
147
		 * an unique name. You may use the name of your project for this. If
148
		 * you've implemented an alternative client class as well, "default"
149
		 * should be replaced by the name of the new class.
150
		 *
151
		 * @param string Relative path to the template creating the HTML code
152
		 * @since 2016.04
153
		 * @category Developer
154
		 */
155
		$tplconf = 'admin/jqadm/type/stock/template-list';
156
		$default = 'type/stock/list';
157
158
		return $view->render( $view->config( $tplconf, $default ) );
159
	}
160
161
162
	/**
163
	 * Returns the sub-client given by its name.
164
	 *
165
	 * @param string $type Name of the client type
166
	 * @param string|null $name Name of the sub-client (Default if null)
167
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
168
	 */
169
	public function getSubClient( string $type, string $name = null ) : \Aimeos\Admin\JQAdm\Iface
170
	{
171
		/** admin/jqadm/type/stock/decorators/excludes
172
		 * Excludes decorators added by the "common" option from the type JQAdm client
173
		 *
174
		 * Decorators extend the functionality of a class by adding new aspects
175
		 * (e.g. log what is currently done), executing the methods of the underlying
176
		 * class only in certain conditions (e.g. only for logged in users) or
177
		 * modify what is returned to the caller.
178
		 *
179
		 * This option allows you to remove a decorator added via
180
		 * "client/jqadm/common/decorators/default" before they are wrapped
181
		 * around the JQAdm client.
182
		 *
183
		 *  admin/jqadm/type/stock/decorators/excludes = array( 'decorator1' )
184
		 *
185
		 * This would remove the decorator named "decorator1" from the list of
186
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
187
		 * "client/jqadm/common/decorators/default" to the JQAdm client.
188
		 *
189
		 * @param array List of decorator names
190
		 * @since 2017.10
191
		 * @category Developer
192
		 * @see admin/jqadm/common/decorators/default
193
		 * @see admin/jqadm/type/stock/decorators/global
194
		 * @see admin/jqadm/type/stock/decorators/local
195
		 */
196
197
		/** admin/jqadm/type/stock/decorators/global
198
		 * Adds a list of globally available decorators only to the type JQAdm client
199
		 *
200
		 * Decorators extend the functionality of a class by adding new aspects
201
		 * (e.g. log what is currently done), executing the methods of the underlying
202
		 * class only in certain conditions (e.g. only for logged in users) or
203
		 * modify what is returned to the caller.
204
		 *
205
		 * This option allows you to wrap global decorators
206
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
207
		 *
208
		 *  admin/jqadm/type/stock/decorators/global = array( 'decorator1' )
209
		 *
210
		 * This would add the decorator named "decorator1" defined by
211
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
212
		 *
213
		 * @param array List of decorator names
214
		 * @since 2017.10
215
		 * @category Developer
216
		 * @see admin/jqadm/common/decorators/default
217
		 * @see admin/jqadm/type/stock/decorators/excludes
218
		 * @see admin/jqadm/type/stock/decorators/local
219
		 */
220
221
		/** admin/jqadm/type/stock/decorators/local
222
		 * Adds a list of local decorators only to the type JQAdm client
223
		 *
224
		 * Decorators extend the functionality of a class by adding new aspects
225
		 * (e.g. log what is currently done), executing the methods of the underlying
226
		 * class only in certain conditions (e.g. only for logged in users) or
227
		 * modify what is returned to the caller.
228
		 *
229
		 * This option allows you to wrap local decorators
230
		 * ("\Aimeos\Admin\JQAdm\Type\Stock\Decorator\*") around the JQAdm client.
231
		 *
232
		 *  admin/jqadm/type/stock/decorators/local = array( 'decorator2' )
233
		 *
234
		 * This would add the decorator named "decorator2" defined by
235
		 * "\Aimeos\Admin\JQAdm\Type\Stock\Decorator\Decorator2" only to the JQAdm client.
236
		 *
237
		 * @param array List of decorator names
238
		 * @since 2017.10
239
		 * @category Developer
240
		 * @see admin/jqadm/common/decorators/default
241
		 * @see admin/jqadm/type/stock/decorators/excludes
242
		 * @see admin/jqadm/type/stock/decorators/global
243
		 */
244
		return $this->createSubClient( 'type/stock' . $type, $name );
245
	}
246
247
248
	/**
249
	 * Returns the list of sub-client names configured for the client.
250
	 *
251
	 * @return array List of JQAdm client names
252
	 */
253
	protected function getSubClientNames() : array
254
	{
255
		/** admin/jqadm/type/stock/subparts
256
		 * List of JQAdm sub-clients rendered within the type section
257
		 *
258
		 * The output of the frontend is composed of the code generated by the JQAdm
259
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
260
		 * that are responsible for rendering certain sub-parts of the output. The
261
		 * sub-clients can contain JQAdm clients themselves and therefore a
262
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
263
		 * the output that is placed inside the container of its parent.
264
		 *
265
		 * At first, always the JQAdm code generated by the parent is printed, then
266
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
267
		 * determines the order of the output of these sub-clients inside the parent
268
		 * container. If the configured list of clients is
269
		 *
270
		 *  array( "subclient1", "subclient2" )
271
		 *
272
		 * you can easily change the order of the output by reordering the subparts:
273
		 *
274
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
275
		 *
276
		 * You can also remove one or more parts if they shouldn't be rendered:
277
		 *
278
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
279
		 *
280
		 * As the clients only generates structural JQAdm, the layout defined via CSS
281
		 * should support adding, removing or reordering content by a fluid like
282
		 * design.
283
		 *
284
		 * @param array List of sub-client names
285
		 * @since 2017.10
286
		 * @category Developer
287
		 */
288
		return $this->context()->config()->get( 'admin/jqadm/type/stock/subparts', [] );
289
	}
290
291
292
	/**
293
	 * Returns the rendered template including the view data
294
	 *
295
	 * @param \Aimeos\Base\View\Iface $view View object with data assigned
296
	 * @return string HTML output
297
	 */
298
	protected function render( \Aimeos\Base\View\Iface $view ) : string
299
	{
300
		/** admin/jqadm/type/stock/template-item
301
		 * Relative path to the HTML body template for the type item.
302
		 *
303
		 * The template file contains the HTML code and processing instructions
304
		 * to generate the result shown in the body of the frontend. The
305
		 * configuration string is the path to the template file relative
306
		 * to the templates directory (usually in admin/jqadm/templates).
307
		 *
308
		 * You can overwrite the template file configuration in extensions and
309
		 * provide alternative templates. These alternative templates should be
310
		 * named like the default one but with the string "default" replaced by
311
		 * an unique name. You may use the name of your project for this. If
312
		 * you've implemented an alternative client class as well, "default"
313
		 * should be replaced by the name of the new class.
314
		 *
315
		 * @param string Relative path to the template creating the HTML code
316
		 * @since 2017.10
317
		 * @category Developer
318
		 */
319
		$tplconf = 'admin/jqadm/type/stock/template-item';
320
		$default = 'type/stock/item';
321
322
		return $view->render( $view->config( $tplconf, $default ) );
323
	}
324
}
325