Completed
Push — master ( 702095...b9dfd2 )
by Aimeos
02:26
created

Ezpublish::saveItem()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
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'=> 'integer',
39
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_INT,
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.typeid' => array(
58
			'code'=>'customer.lists.typeid',
59
			'internalcode'=>'ezuli."typeid"',
60
			'label'=>'Customer list type ID',
61
			'type'=> 'integer',
62
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
63
			'public' => false,
64
		),
65
		'customer.lists.refid'=> array(
66
			'code'=>'customer.lists.refid',
67
			'internalcode'=>'ezuli."refid"',
68
			'label'=>'Customer list reference ID',
69
			'type'=> 'string',
70
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
71
		),
72
		'customer.lists.datestart' => array(
73
			'code'=>'customer.lists.datestart',
74
			'internalcode'=>'ezuli."start"',
75
			'label'=>'Customer list start date/time',
76
			'type'=> 'datetime',
77
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
78
		),
79
		'customer.lists.dateend' => array(
80
			'code'=>'customer.lists.dateend',
81
			'internalcode'=>'ezuli."end"',
82
			'label'=>'Customer list end date/time',
83
			'type'=> 'datetime',
84
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
85
		),
86
		'customer.lists.config' => array(
87
			'code'=>'customer.lists.config',
88
			'internalcode'=>'ezuli."config"',
89
			'label'=>'Customer list position',
90
			'type'=> 'string',
91
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
92
		),
93
		'customer.lists.position' => array(
94
			'code'=>'customer.lists.position',
95
			'internalcode'=>'ezuli."pos"',
96
			'label'=>'Customer list position',
97
			'type'=> 'integer',
98
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
99
		),
100
		'customer.lists.status' => array(
101
			'code'=>'customer.lists.status',
102
			'internalcode'=>'ezuli."status"',
103
			'label'=>'Customer list status',
104
			'type'=> 'integer',
105
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
106
		),
107
		'customer.lists.ctime'=> array(
108
			'code'=>'customer.lists.ctime',
109
			'internalcode'=>'ezuli."ctime"',
110
			'label'=>'Customer list create date/time',
111
			'type'=> 'datetime',
112
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
113
		),
114
		'customer.lists.mtime'=> array(
115
			'code'=>'customer.lists.mtime',
116
			'internalcode'=>'ezuli."mtime"',
117
			'label'=>'Customer list modification date/time',
118
			'type'=> 'datetime',
119
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
120
		),
121
		'customer.lists.editor'=> array(
122
			'code'=>'customer.lists.editor',
123
			'internalcode'=>'ezuli."editor"',
124
			'label'=>'Customer list editor',
125
			'type'=> 'string',
126
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
127
		),
128
	);
129
130
131
	/**
132
	 * Removes old entries from the storage.
133
	 *
134
	 * @param array $siteids List of IDs for sites whose entries should be deleted
135
	 */
136
	public function cleanup( array $siteids )
137
	{
138
		$path = 'mshop/customer/manager/lists/submanagers';
139
		foreach( $this->getContext()->getConfig()->get( $path, array( 'type' ) ) as $domain ) {
140
			$this->getSubManager( $domain )->cleanup( $siteids );
141
		}
142
143
		$this->cleanupBase( $siteids, $this->getConfigPath() . 'delete' );
144
	}
145
146
147
	/**
148
	 * Returns the list attributes that can be used for searching.
149
	 *
150
	 * @param boolean $withsub Return also attributes of sub-managers if true
151
	 * @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface
152
	 */
153
	public function getSearchAttributes( $withsub = true )
154
	{
155
		$path = 'mshop/customer/manager/lists/submanagers';
156
157
		return $this->getSearchAttributesBase( $this->getSearchConfig(), $path, array( 'type' ), $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( $manager, $name = null )
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 boolean $fetch True if the new ID should be returned in the item
179
	 */
180
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
181
	{
182
		$iface = '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface';
183
		if( !( $item instanceof $iface ) ) {
184
			throw new \Aimeos\MShop\Exception( sprintf( 'Object is not of required type "%1$s"', $iface ) );
185
		}
186
187
		if( $item->getDomain() === 'customer/group' ) {
188
			throw new \Aimeos\MShop\Customer\Exception( sprintf( 'Adding groups to customers is not supported, please use the eZ Publish backend' ) );
189
		}
190
191
		parent::saveItem( $item, $fetch );
192
	}
193
194
195
	/**
196
	 * Returns the config path for retrieving the configuration values.
197
	 *
198
	 * @return string Configuration path (mshop/customer/manager/lists/ezpublish/)
199
	 */
200
	protected function getConfigPath()
201
	{
202
		return 'mshop/customer/manager/lists/ezpublish/';
203
	}
204
205
206
	/**
207
	 * Returns the search configuration for searching items.
208
	 *
209
	 * @return array Associative list of search keys and search definitions
210
	 */
211
	protected function getSearchConfig()
212
	{
213
		return $this->searchConfig;
214
	}
215
}
216