Completed
Push — master ( 7b4297...eec074 )
by Aimeos
03:02
created

Standard::getSubClient()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 77
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 77
rs 8.9342
cc 1
eloc 2
nc 1
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Dashboard\Order;
12
13
14
/**
15
 * Default implementation of dashboard order JQAdm client.
16
 *
17
 * @package Admin
18
 * @subpackage JQAdm
19
 */
20
class Standard
21
	extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
{
24
	/** admin/jqadm/dashboard/order/standard/subparts
25
	 * List of JQAdm sub-clients rendered within the dashboard order section
26
	 *
27
	 * The output of the frontend is composed of the code generated by the JQAdm
28
	 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
29
	 * that are responsible for rendering certain sub-parts of the output. The
30
	 * sub-clients can contain JQAdm clients themselves and therefore a
31
	 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
32
	 * the output that is placed inside the container of its parent.
33
	 *
34
	 * At first, always the JQAdm code generated by the parent is printed, then
35
	 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
36
	 * determines the order of the output of these sub-clients inside the parent
37
	 * container. If the configured list of clients is
38
	 *
39
	 *  array( "subclient1", "subclient2" )
40
	 *
41
	 * you can easily change the order of the output by reordering the subparts:
42
	 *
43
	 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
44
	 *
45
	 * You can also remove one or more parts if they shouldn't be rendered:
46
	 *
47
	 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
48
	 *
49
	 * As the clients only generates structural JQAdm, the layout defined via CSS
50
	 * should support adding, removing or reordering content by a fluid like
51
	 * design.
52
	 *
53
	 * @param array List of sub-client names
54
	 * @since 2016.01
55
	 * @category Developer
56
	 */
57
	private $subPartPath = 'admin/jqadm/dashboard/order/standard/subparts';
58
	private $subPartNames = array( 'paymentstatus' );
59
60
61
	/**
62
	 * Copies a resource
63
	 *
64
	 * @return string|null admin output to display or null for redirecting to the list
65
	 */
66
	public function copy()
67
	{
68
		throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be copied' );
69
	}
70
71
72
	/**
73
	 * Creates a new resource
74
	 *
75
	 * @return string|null admin output to display or null for redirecting to the list
76
	 */
77
	public function create()
78
	{
79
		throw new \Aimeos\Admin\JQAdm\Exception( 'New resources can not be created' );
80
	}
81
82
83
	/**
84
	 * Deletes a resource
85
	 *
86
	 * @return string|null admin output to display or null for redirecting to the list
87
	 */
88
	public function delete()
89
	{
90
		throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be deleted' );
91
	}
92
93
94
	/**
95
	 * Returns a single resource
96
	 *
97
	 * @return string|null admin output to display or null for redirecting to the list
98
	 */
99
	public function get()
100
	{
101
		throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be retrieved' );
102
	}
103
104
105
	/**
106
	 * Saves the data
107
	 *
108
	 * @return string|null admin output to display or null for redirecting to the list
109
	 */
110
	public function save()
111
	{
112
		throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be modified' );
113
	}
114
115
116
	/**
117
	 * Returns a list of resource according to the conditions
118
	 *
119
	 * @return string admin output to display
120
	 */
121
	public function search()
122
	{
123
		$view = $this->getView();
124
		$view->orderBody = '';
125
126
		foreach( $this->getSubClients() as $client ) {
127
			$view->orderBody .= $client->search();
128
		}
129
130
		$tplconf = 'admin/jqadm/dashboard/order/template-list';
131
		$default = 'dashboard/list-order-default.php';
132
133
		return $view->render( $view->config( $tplconf, $default ) );
134
	}
135
136
137
	/**
138
	 * Returns the sub-client given by its name.
139
	 *
140
	 * @param string $type Name of the client type
141
	 * @param string|null $name Name of the sub-client (Default if null)
142
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
143
	 */
144
	public function getSubClient( $type, $name = null )
145
	{
146
		/** admin/jqadm/dashboard/order/decorators/excludes
147
		 * Excludes decorators added by the "common" option from 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 remove a decorator added via
155
		 * "admin/jqadm/common/decorators/default" before they are wrapped
156
		 * around the JQAdm client.
157
		 *
158
		 *  admin/jqadm/dashboard/order/decorators/excludes = array( 'decorator1' )
159
		 *
160
		 * This would remove the decorator named "decorator1" from the list of
161
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
162
		 * "admin/jqadm/common/decorators/default" to the JQAdm client.
163
		 *
164
		 * @param array List of decorator names
165
		 * @since 2016.01
166
		 * @category Developer
167
		 * @see admin/jqadm/common/decorators/default
168
		 * @see admin/jqadm/dashboard/order/decorators/global
169
		 * @see admin/jqadm/dashboard/order/decorators/local
170
		 */
171
172
		/** admin/jqadm/dashboard/order/decorators/global
173
		 * Adds a list of globally available decorators only to the dashboard JQAdm client
174
		 *
175
		 * Decorators extend the functionality of a class by adding new aspects
176
		 * (e.g. log what is currently done), executing the methods of the underlying
177
		 * class only in certain conditions (e.g. only for logged in users) or
178
		 * modify what is returned to the caller.
179
		 *
180
		 * This option allows you to wrap global decorators
181
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
182
		 *
183
		 *  admin/jqadm/dashboard/order/decorators/global = array( 'decorator1' )
184
		 *
185
		 * This would add the decorator named "decorator1" defined by
186
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
187
		 *
188
		 * @param array List of decorator names
189
		 * @since 2016.01
190
		 * @category Developer
191
		 * @see admin/jqadm/common/decorators/default
192
		 * @see admin/jqadm/dashboard/order/decorators/excludes
193
		 * @see admin/jqadm/dashboard/order/decorators/local
194
		 */
195
196
		/** admin/jqadm/dashboard/order/decorators/local
197
		 * Adds a list of local decorators only to the dashboard JQAdm client
198
		 *
199
		 * Decorators extend the functionality of a class by adding new aspects
200
		 * (e.g. log what is currently done), executing the methods of the underlying
201
		 * class only in certain conditions (e.g. only for logged in users) or
202
		 * modify what is returned to the caller.
203
		 *
204
		 * This option allows you to wrap local decorators
205
		 * ("\Aimeos\Admin\JQAdm\Dashboard\Decorator\*") around the JQAdm client.
206
		 *
207
		 *  admin/jqadm/dashboard/order/decorators/local = array( 'decorator2' )
208
		 *
209
		 * This would add the decorator named "decorator2" defined by
210
		 * "\Aimeos\Admin\JQAdm\Dashboard\Decorator\Decorator2" only to the JQAdm client.
211
		 *
212
		 * @param array List of decorator names
213
		 * @since 2016.01
214
		 * @category Developer
215
		 * @see admin/jqadm/common/decorators/default
216
		 * @see admin/jqadm/dashboard/order/decorators/excludes
217
		 * @see admin/jqadm/dashboard/order/decorators/global
218
		 */
219
		return $this->createSubClient( 'dashboard/order/' . $type, $name );
220
	}
221
222
223
	/**
224
	 * Returns the list of sub-client names configured for the client.
225
	 *
226
	 * @return array List of JQAdm client names
227
	 */
228
	protected function getSubClientNames()
229
	{
230
		return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames );
231
	}
232
}
233