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

Standard::search()   B

Complexity

Conditions 4
Paths 11

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 8.5806
cc 4
eloc 16
nc 11
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Dashboard\Order\Latest;
12
13
14
/**
15
 * Default implementation of dashboard latest 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/latest/standard/subparts
25
	 * List of JQAdm sub-clients rendered within the dashboard latest 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/latest/standard/subparts';
58
	private $subPartNames = array();
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
125
		try
126
		{
127
			$this->addOrders( $view );
128
			$view->orderlatestBody = '';
129
130
			foreach( $this->getSubClients() as $client ) {
131
				$view->orderlatestBody .= $client->search();
132
			}
133
		}
134
		catch( \Aimeos\MShop\Exception $e )
135
		{
136
			$error = array( 'order-latest' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) );
137
			$view->errors = $view->get( 'errors', array() ) + $error;
138
		}
139
		catch( \Exception $e )
140
		{
141
			$error = array( 'order-latest' => $e->getMessage() );
142
			$view->errors = $view->get( 'errors', array() ) + $error;
143
		}
144
145
		$tplconf = 'admin/jqadm/dashboard/order/latest/template-item';
146
		$default = 'dashboard/item-order-latest-default.php';
147
148
		return $view->render( $view->config( $tplconf, $default ) );
149
	}
150
151
152
	/**
153
	 * Returns the sub-client given by its name.
154
	 *
155
	 * @param string $type Name of the client type
156
	 * @param string|null $name Name of the sub-client (Default if null)
157
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
158
	 */
159
	public function getSubClient( $type, $name = null )
160
	{
161
		/** admin/jqadm/dashboard/order/latest/decorators/excludes
162
		 * Excludes decorators added by the "common" option from the dashboard 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 remove a decorator added via
170
		 * "admin/jqadm/common/decorators/default" before they are wrapped
171
		 * around the JQAdm client.
172
		 *
173
		 *  admin/jqadm/dashboard/order/latest/decorators/excludes = array( 'decorator1' )
174
		 *
175
		 * This would remove the decorator named "decorator1" from the list of
176
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
177
		 * "admin/jqadm/common/decorators/default" to the JQAdm client.
178
		 *
179
		 * @param array List of decorator names
180
		 * @since 2016.01
181
		 * @category Developer
182
		 * @see admin/jqadm/common/decorators/default
183
		 * @see admin/jqadm/dashboard/order/latest/decorators/global
184
		 * @see admin/jqadm/dashboard/order/latest/decorators/local
185
		 */
186
187
		/** admin/jqadm/dashboard/order/latest/decorators/global
188
		 * Adds a list of globally available decorators only to the dashboard JQAdm client
189
		 *
190
		 * Decorators extend the functionality of a class by adding new aspects
191
		 * (e.g. log what is currently done), executing the methods of the underlying
192
		 * class only in certain conditions (e.g. only for logged in users) or
193
		 * modify what is returned to the caller.
194
		 *
195
		 * This option allows you to wrap global decorators
196
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
197
		 *
198
		 *  admin/jqadm/dashboard/order/latest/decorators/global = array( 'decorator1' )
199
		 *
200
		 * This would add the decorator named "decorator1" defined by
201
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
202
		 *
203
		 * @param array List of decorator names
204
		 * @since 2016.01
205
		 * @category Developer
206
		 * @see admin/jqadm/common/decorators/default
207
		 * @see admin/jqadm/dashboard/order/latest/decorators/excludes
208
		 * @see admin/jqadm/dashboard/order/latest/decorators/local
209
		 */
210
211
		/** admin/jqadm/dashboard/order/latest/decorators/local
212
		 * Adds a list of local decorators only to the dashboard JQAdm client
213
		 *
214
		 * Decorators extend the functionality of a class by adding new aspects
215
		 * (e.g. log what is currently done), executing the methods of the underlying
216
		 * class only in certain conditions (e.g. only for logged in users) or
217
		 * modify what is returned to the caller.
218
		 *
219
		 * This option allows you to wrap local decorators
220
		 * ("\Aimeos\Admin\JQAdm\Dashboard\Decorator\*") around the JQAdm client.
221
		 *
222
		 *  admin/jqadm/dashboard/order/latest/decorators/local = array( 'decorator2' )
223
		 *
224
		 * This would add the decorator named "decorator2" defined by
225
		 * "\Aimeos\Admin\JQAdm\Dashboard\Decorator\Decorator2" only to the JQAdm client.
226
		 *
227
		 * @param array List of decorator names
228
		 * @since 2016.01
229
		 * @category Developer
230
		 * @see admin/jqadm/common/decorators/default
231
		 * @see admin/jqadm/dashboard/order/latest/decorators/excludes
232
		 * @see admin/jqadm/dashboard/order/latest/decorators/global
233
		 */
234
		return $this->createSubClient( 'dashboard/order/latest/' . $type, $name );
235
	}
236
237
238
	/**
239
	 * Adds the latest orders to the view object
240
	 *
241
	 * @param \Aimeos\MW\View\Iface $view View object to add the parameters to
242
	 */
243
	protected function addOrders( \Aimeos\MW\View\Iface $view )
244
	{
245
		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base' );
246
247
		$search = $manager->createSearch();
248
		$search->setSortations( array( $search->sort( '-', 'order.base.ctime' ) ) );
249
		$search->setSlice( 0, 10 );
250
251
		$orders = $manager->searchItems( $search );
252
253
254
		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order' );
255
256
		$search = $manager->createSearch();
257
		$search->setConditions( $search->compare( '==', 'order.baseid', array_keys( $orders ) ) );
258
259
		$items = $manager->searchItems( $search );
260
261
262
		$view->orderlatestOrders = $orders;
263
		$view->orderlatestItems = $items;
264
	}
265
266
267
	/**
268
	 * Returns the list of sub-client names configured for the client.
269
	 *
270
	 * @return array List of JQAdm client names
271
	 */
272
	protected function getSubClientNames()
273
	{
274
		return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames );
275
	}
276
}
277