Completed
Push — master ( 501177...b6b6ac )
by Aimeos
03:43
created

Standard::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 25
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2020
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Product\Order;
12
13
sprintf( 'order' ); // for translation
14
15
16
/**
17
 * Default implementation of product order 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/product/order/name
27
	 * Name of the order subpart used by the JQAdm product implementation
28
	 *
29
	 * Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Product\Order\Myname".
30
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
31
	 *
32
	 * @param string Last part of the JQAdm class name
33
	 * @since 2016.04
34
	 * @order Developer
35
	 */
36
37
38
	/**
39
	 * Copies a resource
40
	 *
41
	 * @return string|null HTML output
42
	 */
43
	public function copy() : ?string
44
	{
45
		return $this->get();
46
	}
47
48
49
	/**
50
	 * Creates a new resource
51
	 *
52
	 * @return string|null HTML output
53
	 */
54
	public function create() : ?string
55
	{
56
		return $this->get();
57
	}
58
59
60
	/**
61
	 * Returns a single resource
62
	 *
63
	 * @return string|null HTML output
64
	 */
65
	public function get() : ?string
66
	{
67
		$view = $this->getObject()->addData( $this->getView() );
68
		$view->orderBody = '';
69
70
		foreach( $this->getSubClients() as $client ) {
71
			$view->orderBody .= $client->get();
72
		}
73
74
		return $this->render( $view );
75
	}
76
77
78
	/**
79
	 * Returns the sub-client given by its name.
80
	 *
81
	 * @param string $type Name of the client type
82
	 * @param string|null $name Name of the sub-client (Default if null)
83
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
84
	 */
85
	public function getSubClient( string $type, string $name = null ) : \Aimeos\Admin\JQAdm\Iface
86
	{
87
		/** admin/jqadm/product/order/decorators/excludes
88
		 * Excludes decorators added by the "common" option from the product JQAdm client
89
		 *
90
		 * Decorators extend the functionality of a class by adding new aspects
91
		 * (e.g. log what is currently done), executing the methods of the underlying
92
		 * class only in certain conditions (e.g. only for logged in users) or
93
		 * modify what is returned to the caller.
94
		 *
95
		 * This option allows you to remove a decorator added via
96
		 * "admin/jqadm/common/decorators/default" before they are wrapped
97
		 * around the JQAdm client.
98
		 *
99
		 *  admin/jqadm/product/order/decorators/excludes = array( 'decorator1' )
100
		 *
101
		 * This would remove the decorator named "decorator1" from the list of
102
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
103
		 * "admin/jqadm/common/decorators/default" to the JQAdm client.
104
		 *
105
		 * @param array List of decorator names
106
		 * @since 2016.01
107
		 * @order Developer
108
		 * @see admin/jqadm/common/decorators/default
109
		 * @see admin/jqadm/product/order/decorators/global
110
		 * @see admin/jqadm/product/order/decorators/local
111
		 */
112
113
		/** admin/jqadm/product/order/decorators/global
114
		 * Adds a list of globally available decorators only to the product JQAdm client
115
		 *
116
		 * Decorators extend the functionality of a class by adding new aspects
117
		 * (e.g. log what is currently done), executing the methods of the underlying
118
		 * class only in certain conditions (e.g. only for logged in users) or
119
		 * modify what is returned to the caller.
120
		 *
121
		 * This option allows you to wrap global decorators
122
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
123
		 *
124
		 *  admin/jqadm/product/order/decorators/global = array( 'decorator1' )
125
		 *
126
		 * This would add the decorator named "decorator1" defined by
127
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
128
		 *
129
		 * @param array List of decorator names
130
		 * @since 2016.01
131
		 * @order Developer
132
		 * @see admin/jqadm/common/decorators/default
133
		 * @see admin/jqadm/product/order/decorators/excludes
134
		 * @see admin/jqadm/product/order/decorators/local
135
		 */
136
137
		/** admin/jqadm/product/order/decorators/local
138
		 * Adds a list of local decorators only to the product JQAdm client
139
		 *
140
		 * Decorators extend the functionality of a class by adding new aspects
141
		 * (e.g. log what is currently done), executing the methods of the underlying
142
		 * class only in certain conditions (e.g. only for logged in users) or
143
		 * modify what is returned to the caller.
144
		 *
145
		 * This option allows you to wrap local decorators
146
		 * ("\Aimeos\Admin\JQAdm\Product\Decorator\*") around the JQAdm client.
147
		 *
148
		 *  admin/jqadm/product/order/decorators/local = array( 'decorator2' )
149
		 *
150
		 * This would add the decorator named "decorator2" defined by
151
		 * "\Aimeos\Admin\JQAdm\Product\Decorator\Decorator2" only to the JQAdm client.
152
		 *
153
		 * @param array List of decorator names
154
		 * @since 2016.01
155
		 * @order Developer
156
		 * @see admin/jqadm/common/decorators/default
157
		 * @see admin/jqadm/product/order/decorators/excludes
158
		 * @see admin/jqadm/product/order/decorators/global
159
		 */
160
		return $this->createSubClient( 'product/order/' . $type, $name );
161
	}
162
163
164
	/**
165
	 * Returns the list of sub-client names configured for the client.
166
	 *
167
	 * @return array List of JQAdm client names
168
	 */
169
	protected function getSubClientNames() : array
170
	{
171
		/** admin/jqadm/product/order/standard/subparts
172
		 * List of JQAdm sub-clients rendered within the product order section
173
		 *
174
		 * The output of the frontend is composed of the code generated by the JQAdm
175
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
176
		 * that are responsible for rendering certain sub-parts of the output. The
177
		 * sub-clients can contain JQAdm clients themselves and therefore a
178
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
179
		 * the output that is placed inside the container of its parent.
180
		 *
181
		 * At first, always the JQAdm code generated by the parent is printed, then
182
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
183
		 * determines the order of the output of these sub-clients inside the parent
184
		 * container. If the configured list of clients is
185
		 *
186
		 *  array( "subclient1", "subclient2" )
187
		 *
188
		 * you can easily change the order of the output by reordering the subparts:
189
		 *
190
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
191
		 *
192
		 * You can also remove one or more parts if they shouldn't be rendered:
193
		 *
194
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
195
		 *
196
		 * As the clients only generates structural JQAdm, the layout defined via CSS
197
		 * should support adding, removing or reordering content by a fluid like
198
		 * design.
199
		 *
200
		 * @param array List of sub-client names
201
		 * @since 2016.01
202
		 * @order Developer
203
		 */
204
		return $this->getContext()->getConfig()->get( 'admin/jqadm/product/order/standard/subparts', [] );
205
	}
206
207
208
	/**
209
	 * Returns the rendered template including the view data
210
	 *
211
	 * @param \Aimeos\MW\View\Iface $view View object with data assigned
212
	 * @return string|null HTML output
213
	 */
214
	protected function render( \Aimeos\MW\View\Iface $view ) : string
215
	{
216
		/** admin/jqadm/product/order/template-item
217
		 * Relative path to the HTML body template of the order subpart for products.
218
		 *
219
		 * The template file contains the HTML code and processing instructions
220
		 * to generate the result shown in the body of the frontend. The
221
		 * configuration string is the path to the template file relative
222
		 * to the templates directory (usually in admin/jqadm/templates).
223
		 *
224
		 * You can overwrite the template file configuration in extensions and
225
		 * provide alternative templates. These alternative templates should be
226
		 * named like the default one but with the string "default" replaced by
227
		 * an unique name. You may use the name of your project for this. If
228
		 * you've implemented an alternative client class as well, "default"
229
		 * should be replaced by the name of the new class.
230
		 *
231
		 * @param string Relative path to the template creating the HTML code
232
		 * @since 2016.04
233
		 * @order Developer
234
		 */
235
		$tplconf = 'admin/jqadm/product/order/template-item';
236
		$default = 'product/item-order-standard';
237
238
		return $view->render( $view->config( $tplconf, $default ) );
239
	}
240
}
241