Passed
Push — master ( ef4aba...66430f )
by Aimeos
32:26 queued 24:14
created

Base::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2022
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Order\Decorator;
12
13
14
/**
15
 * Base for order frontend controller decorators
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
abstract class Base
21
	extends \Aimeos\Controller\Frontend\Base
22
	implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Order\Iface
23
{
24
	use \Aimeos\Controller\Frontend\Common\Decorator\Traits;
25
26
27
	private $controller;
28
29
30
	/**
31
	 * Initializes the controller decorator.
32
	 *
33
	 * @param \Aimeos\Controller\Frontend\Iface $controller Controller object
34
	 * @param \Aimeos\MShop\ContextIface $context Context object with required objects
35
	 */
36
	public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\ContextIface $context )
37
	{
38
		parent::__construct( $context );
39
40
		$iface = \Aimeos\Controller\Frontend\Order\Iface::class;
41
		$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller );
42
	}
43
44
45
	/**
46
	 * Passes unknown methods to wrapped objects.
47
	 *
48
	 * @param string $name Name of the method
49
	 * @param array $param List of method parameter
50
	 * @return mixed Returns the value of the called method
51
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
52
	 */
53
	public function __call( string $name, array $param )
54
	{
55
		return @call_user_func_array( array( $this->controller, $name ), $param );
56
	}
57
58
59
	/**
60
	 * Adds generic condition for filtering orders
61
	 *
62
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
63
	 * @param string $key Search key defined by the order manager, e.g. "order.status"
64
	 * @param array|string $value Value or list of values to compare to
65
	 * @return \Aimeos\Controller\Frontend\Order\Iface Order controller for fluent interface
66
	 * @since 2019.04
67
	 */
68
	public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Order\Iface
69
	{
70
		$this->controller->compare( $operator, $key, $value );
71
		return $this;
72
	}
73
74
75
	/**
76
	 * Returns the order for the given order ID
77
	 *
78
	 * @param string $id Unique order ID
79
	 * @param bool $default Use default criteria to limit orders
80
	 * @return \Aimeos\MShop\Order\Item\Iface Order item object
81
	 * @since 2019.04
82
	 */
83
	public function get( string $id, bool $default = true ) : \Aimeos\MShop\Order\Item\Iface
84
	{
85
		return $this->controller->get( $id, $default );
86
	}
87
88
89
	/**
90
	 * Parses the given array and adds the conditions to the list of conditions
91
	 *
92
	 * @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['order.statuspayment' => 0]], ['==' => ['order.type' => 'web']]]]
93
	 * @return \Aimeos\Controller\Frontend\Order\Iface Order controller for fluent interface
94
	 * @since 2019.04
95
	 */
96
	public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Order\Iface
97
	{
98
		$this->controller->parse( $conditions );
99
		return $this;
100
	}
101
102
103
	/**
104
	 * Updates the given order item in the storage
105
	 *
106
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
107
	 * @return \Aimeos\MShop\Order\Item\Iface $orderItem Saved order item object
108
	 * @since 2019.04
109
	 */
110
	public function save( \Aimeos\MShop\Order\Item\Iface $orderItem ) : \Aimeos\MShop\Order\Item\Iface
111
	{
112
		return $this->controller->save( $orderItem );
113
	}
114
115
116
	/**
117
	 * Returns the orders filtered by the previously assigned conditions
118
	 *
119
	 * @param int &$total Parameter where the total number of found attributes will be stored in
120
	 * @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Order\Item\Iface
121
	 * @since 2019.04
122
	 */
123
	public function search( int &$total = null ) : \Aimeos\Map
124
	{
125
		return $this->controller->search( $total );
126
	}
127
128
129
	/**
130
	 * Sets the start value and the number of returned orders for slicing the list of found orders
131
	 *
132
	 * @param int $start Start value of the first order in the list
133
	 * @param int $limit Number of returned orders
134
	 * @return \Aimeos\Controller\Frontend\Order\Iface Order controller for fluent interface
135
	 * @since 2019.04
136
	 */
137
	public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Order\Iface
138
	{
139
		$this->controller->slice( $start, $limit );
140
		return $this;
141
	}
142
143
144
	/**
145
	 * Sets the sorting of the result list
146
	 *
147
	 * @param string|null $key Sorting of the result list like "-order.id", null for no sorting
148
	 * @return \Aimeos\Controller\Frontend\Order\Iface Order controller for fluent interface
149
	 * @since 2019.04
150
	 */
151
	public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Order\Iface
152
	{
153
		$this->controller->sort( $key );
154
		return $this;
155
	}
156
157
158
	/**
159
	 * Sets the referenced domains that will be fetched too when retrieving items
160
	 *
161
	 * @param array $domains Domain names of the referenced items that should be fetched too
162
	 * @return \Aimeos\Controller\Frontend\Order\Iface Order controller for fluent interface
163
	 * @since 2020.04
164
	 */
165
	public function uses( array $domains ) : \Aimeos\Controller\Frontend\Order\Iface
166
	{
167
		$this->controller->uses( $domains );
168
		return $this;
169
	}
170
171
172
	/**
173
	 * Injects the reference of the outmost object
174
	 *
175
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
176
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
177
	 */
178
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface
179
	{
180
		parent::setObject( $object );
181
182
		$this->controller->setObject( $object );
183
184
		return $this;
185
	}
186
187
188
	/**
189
	 * Returns the frontend controller
190
	 *
191
	 * @return \Aimeos\Controller\Frontend\Iface Frontend controller object
192
	 */
193
	protected function getController() : \Aimeos\Controller\Frontend\Iface
194
	{
195
		return $this->controller;
196
	}
197
}
198