Passed
Push — master ( 6ee4ae...fdac5c )
by Aimeos
03:28
created

Base::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
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), 2017-2020
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Stock\Decorator;
12
13
14
/**
15
 * Base for stock 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\Stock\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\Stock\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( string $name, array $param )
51
	{
52
		return @call_user_func_array( array( $this->controller, $name ), $param );
53
	}
54
55
56
	/**
57
	 * Adds the IDs of the products for filtering
58
	 *
59
	 * @param array|string $ids Codes of the products
60
	 * @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface
61
	 * @since 2019.04
62
	 */
63
	public function product( $ids ) : \Aimeos\Controller\Frontend\Stock\Iface
64
	{
65
		$this->controller->product( $ids );
66
		return $this;
67
	}
68
69
70
	/**
71
	 * Adds generic condition for filtering
72
	 *
73
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
74
	 * @param string $key Search key defined by the stock manager, e.g. "stock.dateback"
75
	 * @param array|string $value Value or list of values to compare to
76
	 * @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface
77
	 * @since 2019.04
78
	 */
79
	public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Stock\Iface
80
	{
81
		$this->controller->compare( $operator, $key, $value );
82
		return $this;
83
	}
84
85
86
	/**
87
	 * Returns the stock item for the given stock ID
88
	 *
89
	 * @param string $id Unique stock ID
90
	 * @return \Aimeos\MShop\Stock\Item\Iface Stock item
91
	 * @since 2019.04
92
	 */
93
	public function get( string $id ) : \Aimeos\MShop\Stock\Item\Iface
94
	{
95
		return $this->controller->get( $id );
96
	}
97
98
99
	/**
100
	 * Parses the given array and adds the conditions to the list of conditions
101
	 *
102
	 * @param array $conditions List of conditions, e.g. ['>' => ['stock.dateback' => '2000-01-01 00:00:00']]
103
	 * @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface
104
	 * @since 2019.04
105
	 */
106
	public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Stock\Iface
107
	{
108
		$this->controller->parse( $conditions );
109
		return $this;
110
	}
111
112
113
	/**
114
	 * Returns the stock items filtered by the previously assigned conditions
115
	 *
116
	 * @param int &$total Parameter where the total number of found stock items will be stored in
117
	 * @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Stock\Item\Iface
118
	 * @since 2019.04
119
	 */
120
	public function search( int &$total = null ) : \Aimeos\Map
121
	{
122
		return $this->controller->search( $total );
123
	}
124
125
126
	/**
127
	 * Sets the start value and the number of returned stock items for slicing the list of found stock items
128
	 *
129
	 * @param int $start Start value of the first stock item in the list
130
	 * @param int $limit Number of returned stock items
131
	 * @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface
132
	 * @since 2019.04
133
	 */
134
	public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Stock\Iface
135
	{
136
		$this->controller->slice( $start, $limit );
137
		return $this;
138
	}
139
140
141
	/**
142
	 * Sets the sorting of the result list
143
	 *
144
	 * @param string|null $key Sorting of the result list like "stock.type", null for no sorting
145
	 * @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface
146
	 * @since 2019.04
147
	 */
148
	public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Stock\Iface
149
	{
150
		$this->controller->sort( $key );
151
		return $this;
152
	}
153
154
155
	/**
156
	 * Adds stock types for filtering
157
	 *
158
	 * @param array|string $types Stock type codes
159
	 * @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface
160
	 * @since 2019.04
161
	 */
162
	public function type( $types ) : \Aimeos\Controller\Frontend\Stock\Iface
163
	{
164
		$this->controller->type( $types );
165
		return $this;
166
	}
167
168
169
	/**
170
	 * Injects the reference of the outmost object
171
	 *
172
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
173
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
174
	 */
175
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface
176
	{
177
		parent::setObject( $object );
178
179
		$this->controller->setObject( $object );
180
181
		return $this;
182
	}
183
184
185
	/**
186
	 * Returns the frontend controller
187
	 *
188
	 * @return \Aimeos\Controller\Frontend\Stock\Iface Frontend controller object
189
	 */
190
	protected function getController() : \Aimeos\Controller\Frontend\Stock\Iface
191
	{
192
		return $this->controller;
193
	}
194
}
195