Passed
Push — master ( 07eb96...1dd005 )
by Aimeos
09:52
created

Standard::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2022
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Order\Transaction;
12
13
sprintf( 'transaction' ); // for translation
14
15
16
/**
17
 * Default implementation of order transaction 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/order/transaction/name
27
	 * Name of the transaction subpart used by the JQAdm order implementation
28
	 *
29
	 * Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Order\Transaction\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 2023.01
34
	 * @category 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->object()->data( $this->view() );
68
69
		return $this->render( $view );
70
	}
71
72
73
	/**
74
	 * Saves the data
75
	 *
76
	 * @return string|null HTML output
77
	 */
78
	public function save() : ?string
79
	{
80
		$view = $this->view();
81
82
		$manager = \Aimeos\MShop::create( $this->context(), 'order' );
83
		$manager->begin();
84
85
		try
86
		{
87
			$this->fromArray( $view->item, $view->param( 'transaction', [] ) );
88
			$view->transactionBody = parent::save();
89
90
			$manager->commit();
91
		}
92
		catch( \Exception $e )
93
		{
94
			$manager->rollback();
95
			throw $e;
96
		}
97
98
		return null;
99
	}
100
101
102
	/**
103
	 * Returns the sub-client given by its name.
104
	 *
105
	 * @param string $type Name of the client type
106
	 * @param string|null $name Name of the sub-client (Default if null)
107
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
108
	 */
109
	public function getSubClient( string $type, string $name = null ) : \Aimeos\Admin\JQAdm\Iface
110
	{
111
		/** admin/jqadm/order/transaction/decorators/excludes
112
		 * Excludes decorators added by the "common" option from the order JQAdm client
113
		 *
114
		 * Decorators extend the functionality of a class by adding new aspects
115
		 * (e.g. log what is currently done), executing the methods of the underlying
116
		 * class only in certain conditions (e.g. only for logged in users) or
117
		 * modify what is returned to the caller.
118
		 *
119
		 * This option allows you to remove a decorator added via
120
		 * "admin/jqadm/common/decorators/default" before they are wrapped
121
		 * around the JQAdm client.
122
		 *
123
		 *  admin/jqadm/order/transaction/decorators/excludes = array( 'decorator1' )
124
		 *
125
		 * This would remove the decorator named "decorator1" from the list of
126
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
127
		 * "admin/jqadm/common/decorators/default" to the JQAdm client.
128
		 *
129
		 * @param array List of decorator names
130
		 * @since 2023.01
131
		 * @category Developer
132
		 * @see admin/jqadm/common/decorators/default
133
		 * @see admin/jqadm/order/transaction/decorators/global
134
		 * @see admin/jqadm/order/transaction/decorators/local
135
		 */
136
137
		/** admin/jqadm/order/transaction/decorators/global
138
		 * Adds a list of globally available decorators only to the order 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 global decorators
146
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
147
		 *
148
		 *  admin/jqadm/order/transaction/decorators/global = array( 'decorator1' )
149
		 *
150
		 * This would add the decorator named "decorator1" defined by
151
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
152
		 *
153
		 * @param array List of decorator names
154
		 * @since 2023.01
155
		 * @category Developer
156
		 * @see admin/jqadm/common/decorators/default
157
		 * @see admin/jqadm/order/transaction/decorators/excludes
158
		 * @see admin/jqadm/order/transaction/decorators/local
159
		 */
160
161
		/** admin/jqadm/order/transaction/decorators/local
162
		 * Adds a list of local decorators only to the order JQAdm client
163
		 *
164
		 * Decorators extend the functionality of a class by adding new aspects
165
		 * (e.g. log what is currently done), executing the methods of the underlying
166
		 * class only in certain conditions (e.g. only for logged in users) or
167
		 * modify what is returned to the caller.
168
		 *
169
		 * This option allows you to wrap local decorators
170
		 * ("\Aimeos\Admin\JQAdm\Order\Decorator\*") around the JQAdm client.
171
		 *
172
		 *  admin/jqadm/order/transaction/decorators/local = array( 'decorator2' )
173
		 *
174
		 * This would add the decorator named "decorator2" defined by
175
		 * "\Aimeos\Admin\JQAdm\Order\Decorator\Decorator2" only to the JQAdm client.
176
		 *
177
		 * @param array List of decorator names
178
		 * @since 2023.01
179
		 * @category Developer
180
		 * @see admin/jqadm/common/decorators/default
181
		 * @see admin/jqadm/order/transaction/decorators/excludes
182
		 * @see admin/jqadm/order/transaction/decorators/global
183
		 */
184
		return $this->createSubClient( 'order/transaction/' . $type, $name );
185
	}
186
187
188
	/**
189
	 * Returns the list of sub-client names configured for the client.
190
	 *
191
	 * @return array List of JQAdm client names
192
	 */
193
	protected function getSubClientNames() : array
194
	{
195
		/** admin/jqadm/order/transaction/subparts
196
		 * List of JQAdm sub-clients rendered within the order transaction section
197
		 *
198
		 * The output of the frontend is composed of the code generated by the JQAdm
199
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
200
		 * that are responsible for rendering certain sub-parts of the output. The
201
		 * sub-clients can contain JQAdm clients themselves and therefore a
202
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
203
		 * the output that is placed inside the container of its parent.
204
		 *
205
		 * At first, always the JQAdm code generated by the parent is printed, then
206
		 * the JQAdm code of its sub-clients. The transaction of the JQAdm sub-clients
207
		 * determines the transaction of the output of these sub-clients inside the parent
208
		 * container. If the configured list of clients is
209
		 *
210
		 *  array( "subclient1", "subclient2" )
211
		 *
212
		 * you can easily change the transaction of the output by retransactioning the subparts:
213
		 *
214
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
215
		 *
216
		 * You can also remove one or more parts if they shouldn't be rendered:
217
		 *
218
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
219
		 *
220
		 * As the clients only generates structural JQAdm, the layout defined via CSS
221
		 * should support adding, removing or retransactioning content by a fluid like
222
		 * design.
223
		 *
224
		 * @param array List of sub-client names
225
		 * @since 2023.01
226
		 * @category Developer
227
		 */
228
		return $this->context()->config()->get( 'admin/jqadm/order/transaction/subparts', [] );
229
	}
230
231
232
	/**
233
	 * Creates new and updates existing items using the data array
234
	 *
235
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $order Order base item object
236
	 * @param array $data Data array
237
	 */
238
	protected function fromArray( \Aimeos\MShop\Order\Item\Base\Iface $order, array $data )
239
	{
240
	}
241
242
243
	/**
244
	 * Returns the rendered template including the view data
245
	 *
246
	 * @param \Aimeos\Base\View\Iface $view View object with data assigned
247
	 * @return string HTML output
248
	 */
249
	protected function render( \Aimeos\Base\View\Iface $view ) : string
250
	{
251
		/** admin/jqadm/order/transaction/template-item
252
		 * Relative path to the HTML body template of the transaction subpart for orders.
253
		 *
254
		 * The template file contains the HTML code and processing instructions
255
		 * to generate the result shown in the body of the frontend. The
256
		 * configuration string is the path to the template file relative
257
		 * to the templates directory (usually in templates/admin/jqadm).
258
		 *
259
		 * You can overwrite the template file configuration in extensions and
260
		 * provide alternative templates. These alternative templates should be
261
		 * named like the default one but with the string "default" replaced by
262
		 * an unique name. You may use the name of your project for this. If
263
		 * you've implemented an alternative client class as well, "default"
264
		 * should be replaced by the name of the new class.
265
		 *
266
		 * @param string Relative path to the template creating the HTML code
267
		 * @since 2016.04
268
		 * @category Developer
269
		 */
270
		$tplconf = 'admin/jqadm/order/transaction/template-item';
271
		$default = 'order/item-transaction';
272
273
		return $view->render( $view->config( $tplconf, $default ) );
274
	}
275
}
276