Ezpublish::deleteItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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\Group;
12
13
14
/**
15
 * eZPublish implementation of the customer group class
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class Ezpublish
21
	extends \Aimeos\MShop\Customer\Manager\Group\Standard
22
	implements \Aimeos\MShop\Customer\Manager\Group\Iface
23
{
24
	private $searchConfig = array(
25
		'customer.group.id' => array(
26
			'code' => 'customer.group.id',
27
			'internalcode' => 'ezro."id"',
28
			'label' => 'Customer group ID',
29
			'type' => 'integer',
30
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
31
		),
32
		'customer.group.code' => array(
33
			'code' => 'customer.group.code',
34
			'internalcode' => 'ezro."id"',
35
			'label' => 'Customer group code',
36
			'type' => 'string',
37
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
38
		),
39
		'customer.group.label' => array(
40
			'code' => 'customer.group.label',
41
			'internalcode' => 'ezro."name"',
42
			'label' => 'Customer group label',
43
			'type' => 'string',
44
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
45
		),
46
		'customer.group.ctime'=> array(
47
			'code' => 'customer.group.ctime',
48
			'internalcode' => null,
49
			'label' => 'Customer group creation time',
50
			'type' => 'datetime',
51
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
52
		),
53
		'customer.group.mtime'=> array(
54
			'code' => 'customer.group.mtime',
55
			'internalcode' => null,
56
			'label' => 'Customer group modification time',
57
			'type' => 'datetime',
58
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
59
		),
60
		'customer.group.editor'=> array(
61
			'code' => 'customer.group.editor',
62
			'internalcode' => null,
63
			'label' => 'Customer group editor',
64
			'type' => 'string',
65
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
66
		),
67
	);
68
69
70
	/**
71
	 * Removes old entries from the database
72
	 *
73
	 * @param string[] $siteids List of IDs for sites whose entries should be deleted
74
	 * @return \Aimeos\MShop\Common\Manager\Iface Same object for fluent interface
75
	 */
76
	public function clear( array $siteids ) : \Aimeos\MShop\Common\Manager\Iface
77
	{
78
		return $this;
79
	}
80
81
82
	/**
83
	 * Removes multiple items.
84
	 *
85
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
86
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
87
	 */
88
	public function deleteItems( array $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
89
	{
90
		throw new \Aimeos\MShop\Customer\Exception( sprintf( 'Deleting groups is not supported, please use the eZ Publish backend' ) );
91
	}
92
93
94
	/**
95
	 * Returns the attributes that can be used for searching.
96
	 *
97
	 * @param bool $withsub Return also attributes of sub-managers if true
98
	 * @return array Returns a list of attribtes implementing \Aimeos\MW\Criteria\Attribute\Iface
99
	 */
100
	public function getSearchAttributes( bool $withsub = true ) : array
101
	{
102
		$path = 'mshop/customer/manager/group/submanagers';
103
104
		return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
105
	}
106
107
108
	/**
109
	 * Returns a new manager for customer group extensions
110
	 *
111
	 * @param string $manager Name of the sub manager type in lower case
112
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
113
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions
114
	 */
115
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
116
	{
117
		return $this->getSubManagerBase( 'customer/group', $manager, ( $name === null ? 'Ezpublish' : $name ) );
118
	}
119
120
121
	/**
122
	 * Inserts a new or updates an existing customer group item
123
	 *
124
	 * @param \Aimeos\MShop\Customer\Item\Group\Iface $item Customer group item
125
	 * @param bool $fetch True if the new ID should be returned in the item
126
	 */
127
	public function saveItem( \Aimeos\MShop\Customer\Item\Group\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Customer\Item\Group\Iface
128
	{
129
		throw new \Aimeos\MShop\Customer\Exception( sprintf( 'Saving groups is not supported, please use the eZ Publish backend' ) );
130
	}
131
132
133
	/**
134
	 * Returns the item objects matched by the given search criteria.
135
	 *
136
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
137
	 * @param array $ref List of domain items that should be fetched too
138
	 * @param int &$total Number of items that are available in total
139
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Customer\Item\Group\Iface
140
	 * @throws \Aimeos\MShop\Exception If retrieving items failed
141
	 */
142
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
143
	{
144
		$map = [];
145
		$context = $this->getContext();
146
147
		$dbm = $context->getDatabaseManager();
148
		$dbname = $this->getResourceName();
149
		$conn = $dbm->acquire( $dbname );
150
151
		try
152
		{
153
			$required = array( 'customer.group' );
154
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
155
			$cfgPathSearch = 'mshop/customer/manager/group/ezpublish/search';
156
			$cfgPathCount = 'mshop/customer/manager/group/ezpublish/count';
157
158
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
159
160
			while( ( $row = $results->fetch() ) !== null ) {
161
				$map[(string) $row['customer.group.id']] = $this->createItemBase( $row );
162
			}
163
164
			$dbm->release( $conn, $dbname );
165
		}
166
		catch( \Exception $e )
167
		{
168
			$dbm->release( $conn, $dbname );
169
			throw $e;
170
		}
171
172
		return map( $map );
173
	}
174
}
175