Ezpublish::clear()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2020
6
 * @package MShop
7
 * @subpackage Customer
8
 */
9
10
11
namespace Aimeos\MShop\Customer\Manager\Lists;
12
13
14
/**
15
 * ezPublish implementation of the customer list class
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class Ezpublish
21
	extends \Aimeos\MShop\Customer\Manager\Lists\Standard
22
	implements \Aimeos\MShop\Customer\Manager\Lists\Iface, \Aimeos\MShop\Common\Manager\Lists\Iface
23
{
24
	private $searchConfig = array(
25
		'customer.lists.id'=> array(
26
			'code'=>'customer.lists.id',
27
			'internalcode'=>'ezuli."id"',
28
			'internaldeps' => array( 'LEFT JOIN "ezuser_list" AS ezuli ON ( ezu."id" = ezuli."parentid" )' ),
29
			'label'=>'Customer list ID',
30
			'type'=> 'integer',
31
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_INT,
32
			'public' => false,
33
		),
34
		'customer.lists.siteid'=> array(
35
			'code'=>'customer.lists.siteid',
36
			'internalcode'=>'ezuli."siteid"',
37
			'label'=>'Customer list site ID',
38
			'type'=> 'string',
39
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
40
			'public' => false,
41
		),
42
		'customer.lists.parentid'=> array(
43
			'code'=>'customer.lists.parentid',
44
			'internalcode'=>'ezuli."parentid"',
45
			'label'=>'Customer list parent ID',
46
			'type'=> 'integer',
47
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_INT,
48
			'public' => false,
49
		),
50
		'customer.lists.domain'=> array(
51
			'code'=>'customer.lists.domain',
52
			'internalcode'=>'ezuli."domain"',
53
			'label'=>'Customer list domain',
54
			'type'=> 'string',
55
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
56
		),
57
		'customer.lists.type' => array(
58
			'code'=>'customer.lists.type',
59
			'internalcode'=>'ezuli."type"',
60
			'label'=>'Customer list type',
61
			'type'=> 'string',
62
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
63
		),
64
		'customer.lists.refid'=> array(
65
			'code'=>'customer.lists.refid',
66
			'internalcode'=>'ezuli."refid"',
67
			'label'=>'Customer list reference ID',
68
			'type'=> 'string',
69
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
70
		),
71
		'customer.lists.datestart' => array(
72
			'code'=>'customer.lists.datestart',
73
			'internalcode'=>'ezuli."start"',
74
			'label'=>'Customer list start date/time',
75
			'type'=> 'datetime',
76
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
77
		),
78
		'customer.lists.dateend' => array(
79
			'code'=>'customer.lists.dateend',
80
			'internalcode'=>'ezuli."end"',
81
			'label'=>'Customer list end date/time',
82
			'type'=> 'datetime',
83
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
84
		),
85
		'customer.lists.config' => array(
86
			'code'=>'customer.lists.config',
87
			'internalcode'=>'ezuli."config"',
88
			'label'=>'Customer list position',
89
			'type'=> 'string',
90
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
91
		),
92
		'customer.lists.position' => array(
93
			'code'=>'customer.lists.position',
94
			'internalcode'=>'ezuli."pos"',
95
			'label'=>'Customer list position',
96
			'type'=> 'integer',
97
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
98
		),
99
		'customer.lists.status' => array(
100
			'code'=>'customer.lists.status',
101
			'internalcode'=>'ezuli."status"',
102
			'label'=>'Customer list status',
103
			'type'=> 'integer',
104
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
105
		),
106
		'customer.lists.ctime'=> array(
107
			'code'=>'customer.lists.ctime',
108
			'internalcode'=>'ezuli."ctime"',
109
			'label'=>'Customer list create date/time',
110
			'type'=> 'datetime',
111
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
112
		),
113
		'customer.lists.mtime'=> array(
114
			'code'=>'customer.lists.mtime',
115
			'internalcode'=>'ezuli."mtime"',
116
			'label'=>'Customer list modification date/time',
117
			'type'=> 'datetime',
118
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
119
		),
120
		'customer.lists.editor'=> array(
121
			'code'=>'customer.lists.editor',
122
			'internalcode'=>'ezuli."editor"',
123
			'label'=>'Customer list editor',
124
			'type'=> 'string',
125
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
126
		),
127
	);
128
129
130
	/**
131
	 * Removes old entries from the storage.
132
	 *
133
	 * @param string[] $siteids List of IDs for sites whose entries should be deleted
134
	 * @return \Aimeos\MShop\Common\Manager\Iface Same object for fluent interface
135
	 */
136
	public function clear( array $siteids ) : \Aimeos\MShop\Common\Manager\Iface
137
	{
138
		$path = 'mshop/customer/manager/lists/submanagers';
139
		foreach( $this->getContext()->getConfig()->get( $path, [] ) as $domain ) {
140
			$this->getObject()->getSubManager( $domain )->clear( $siteids );
141
		}
142
143
		return $this->clearBase( $siteids, $this->getConfigPath() . 'delete' );
144
	}
145
146
147
	/**
148
	 * Returns the attributes that can be used for searching.
149
	 *
150
	 * @param bool $withsub Return also attributes of sub-managers if true
151
	 * @return array Returns a list of attribtes implementing \Aimeos\MW\Criteria\Attribute\Iface
152
	 */
153
	public function getSearchAttributes( bool $withsub = true ) : array
154
	{
155
		$path = 'mshop/customer/manager/lists/submanagers';
156
157
		return $this->getSearchAttributesBase( $this->getSearchConfig(), $path, [], $withsub );
158
	}
159
160
161
	/**
162
	 * Returns a new manager for customer extensions
163
	 *
164
	 * @param string $manager Name of the sub manager type in lower case
165
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
166
	 * @return mixed Manager for different extensions, e.g stock, tags, locations, etc.
167
	 */
168
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
169
	{
170
		return $this->getSubManagerBase( 'customer', 'lists/' . $manager, ( $name === null ? 'Ezpublish' : $name ) );
171
	}
172
173
174
	/**
175
	 * Updates or adds a common list item object.
176
	 *
177
	 * @param \Aimeos\MShop\Common\Item\Lists\Iface $item List item object which should be saved
178
	 * @param bool $fetch True if the new ID should be returned in the item
179
	 * @return \Aimeos\MShop\Common\Item\Lists\Iface $item Updated item including the generated ID
180
	 */
181
	public function saveItem( \Aimeos\MShop\Common\Item\Lists\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Lists\Iface
182
	{
183
		if( $item->getDomain() === 'customer/group' ) {
184
			throw new \Aimeos\MShop\Customer\Exception( sprintf( 'Adding groups to customers is not supported, please use the eZ Publish backend' ) );
185
		}
186
187
		return parent::saveItem( $item, $fetch );
188
	}
189
190
191
	/**
192
	 * Returns the config path for retrieving the configuration values.
193
	 *
194
	 * @return string Configuration path (mshop/customer/manager/lists/ezpublish/)
195
	 */
196
	protected function getConfigPath() : string
197
	{
198
		return 'mshop/customer/manager/lists/ezpublish/';
199
	}
200
201
202
	/**
203
	 * Returns the search configuration for searching items.
204
	 *
205
	 * @return array Associative list of search keys and search definitions
206
	 */
207
	protected function getSearchConfig() : array
208
	{
209
		return $this->searchConfig;
210
	}
211
}
212