Passed
Push — master ( d4b18c...ae3ece )
by Aimeos
01:45
created

Base::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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