|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
6
|
|
|
* @package MShop |
|
7
|
|
|
* @subpackage Customer |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\MShop\Customer\Manager; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Base class with common methods for all customer implementations. |
|
16
|
|
|
* |
|
17
|
|
|
* @package MShop |
|
18
|
|
|
* @subpackage Customer |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class Base |
|
21
|
|
|
extends \Aimeos\MShop\Common\Manager\Base |
|
22
|
|
|
{ |
|
23
|
|
|
/* @deprecated 2025.01 Use $this->context()->password() instead */ |
|
24
|
|
|
private ?\Aimeos\MShop\Common\Helper\Password\Iface $helper = null; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Counts the number items that are available for the values of the given key. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Aimeos\Base\Criteria\Iface $search Search criteria |
|
31
|
|
|
* @param array|string $key Search key or list of key to aggregate items for |
|
32
|
|
|
* @param string|null $value Search key for aggregating the value column |
|
33
|
|
|
* @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average) |
|
34
|
|
|
* @return \Aimeos\Map List of the search keys as key and the number of counted items as value |
|
35
|
|
|
*/ |
|
36
|
|
|
public function aggregate( \Aimeos\Base\Criteria\Iface $search, $key, ?string $value = null, ?string $type = null ) : \Aimeos\Map |
|
37
|
|
|
{ |
|
38
|
|
|
/** mshop/customer/manager/aggregate/mysql |
|
39
|
|
|
* Counts the number of records grouped by the values in the key column and matched by the given criteria |
|
40
|
|
|
* |
|
41
|
|
|
* @see mshop/customer/manager/aggregate/ansi |
|
42
|
|
|
*/ |
|
43
|
|
|
|
|
44
|
|
|
/** mshop/customer/manager/aggregate/ansi |
|
45
|
|
|
* Counts the number of records grouped by the values in the key column and matched by the given criteria |
|
46
|
|
|
* |
|
47
|
|
|
* Groups all records by the values in the key column and counts their |
|
48
|
|
|
* occurence. The matched records can be limited by the given criteria |
|
49
|
|
|
* from the customer database. The records must be from one of the sites |
|
50
|
|
|
* that are configured via the context item. If the current site is part |
|
51
|
|
|
* of a tree of sites, the statement can count all records from the |
|
52
|
|
|
* current site and the complete sub-tree of sites. |
|
53
|
|
|
* |
|
54
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
|
55
|
|
|
* their tables must be joined in the SQL context. This is done by |
|
56
|
|
|
* using the "internaldeps" property from the definition of the ID |
|
57
|
|
|
* column of the sub-managers. These internal dependencies specify |
|
58
|
|
|
* the JOIN between the tables and the used columns for joining. The |
|
59
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
|
60
|
|
|
* the sub-managers. |
|
61
|
|
|
* |
|
62
|
|
|
* To limit the records matched, conditions can be added to the given |
|
63
|
|
|
* criteria object. It can contain comparisons like column names that |
|
64
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
|
65
|
|
|
* operators. The resulting string of SQL conditions replaces the |
|
66
|
|
|
* ":cond" placeholder before the statement is sent to the database |
|
67
|
|
|
* server. |
|
68
|
|
|
* |
|
69
|
|
|
* This statement doesn't return any records. Instead, it returns pairs |
|
70
|
|
|
* of the different values found in the key column together with the |
|
71
|
|
|
* number of records that have been found for that key values. |
|
72
|
|
|
* |
|
73
|
|
|
* The SQL statement should conform to the ANSI standard to be |
|
74
|
|
|
* compatible with most relational database systems. This also |
|
75
|
|
|
* includes using double quotes for table and column names. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string SQL statement for aggregating customer items |
|
78
|
|
|
* @since 2021.04 |
|
79
|
|
|
* @see mshop/customer/manager/insert/ansi |
|
80
|
|
|
* @see mshop/customer/manager/update/ansi |
|
81
|
|
|
* @see mshop/customer/manager/newid/ansi |
|
82
|
|
|
* @see mshop/customer/manager/delete/ansi |
|
83
|
|
|
* @see mshop/customer/manager/search/ansi |
|
84
|
|
|
* @see mshop/customer/manager/count/ansi |
|
85
|
|
|
*/ |
|
86
|
|
|
|
|
87
|
|
|
$cfgkey = 'mshop/customer/manager/aggregate'; |
|
88
|
|
|
return $this->aggregateBase( $search, $key, $cfgkey, ['customer'], $value, $type ); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Creates a filter object. |
|
94
|
|
|
* |
|
95
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
|
96
|
|
|
* @param bool $site TRUE for adding site criteria to limit items by the site of related items |
|
97
|
|
|
* @return \Aimeos\Base\Criteria\Iface Returns the filter object |
|
98
|
|
|
*/ |
|
99
|
|
|
public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->filterBase( 'customer', $default ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Returns the item specified by its code and domain/type if necessary |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $code Code of the item |
|
109
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
|
110
|
|
|
* @param string|null $domain Domain of the item if necessary to identify the item uniquely |
|
111
|
|
|
* @param string|null $type Type code of the item if necessary to identify the item uniquely |
|
112
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
|
113
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface Item object |
|
114
|
|
|
*/ |
|
115
|
|
|
public function find( string $code, array $ref = [], ?string $domain = null, ?string $type = null, |
|
116
|
|
|
?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->findBase( ['customer.code' => $code], $ref, $default ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Returns the customer item object specificed by its ID. |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $id Unique customer ID referencing an existing customer |
|
126
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
|
127
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
|
128
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface Returns the customer item of the given id |
|
129
|
|
|
* @throws \Aimeos\MShop\Exception If item couldn't be found |
|
130
|
|
|
*/ |
|
131
|
|
|
public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->getItemBase( 'customer.id', $id, $ref, $default ); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Adds the customer to the groups listed in the customer item |
|
139
|
|
|
* |
|
140
|
|
|
* @param \Aimeos\MShop\Customer\Item\Iface $item Customer item |
|
141
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface $item Modified customer item |
|
142
|
|
|
*/ |
|
143
|
|
|
protected function addGroups( \Aimeos\MShop\Customer\Item\Iface $item ): \Aimeos\MShop\Customer\Item\Iface |
|
144
|
|
|
{ |
|
145
|
|
|
$pos = 0; |
|
146
|
|
|
$groupIds = []; |
|
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
$manager = $this->object()->getSubManager( 'lists' ); |
|
149
|
|
|
$listItems = $item->getListItems( 'group', 'default', null, false ); |
|
150
|
|
|
|
|
151
|
|
|
foreach( $item->getGroups() as $refId ) |
|
152
|
|
|
{ |
|
153
|
|
|
if( ( $litem = $item->getListItem( 'group', 'default', $refId, false ) ) !== null ) { |
|
154
|
|
|
unset( $listItems[$litem->getId()], $listItems['__group_default_' . $refId] ); |
|
155
|
|
|
} else { |
|
156
|
|
|
$litem = $manager->create()->setType( 'default' ); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$item->addListItem( 'group', $litem->setRefId( $refId )->setPosition( $pos++ ) ); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $item->deleteListItems( $listItems ); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Creates a new customer item. |
|
168
|
|
|
* |
|
169
|
|
|
* @param array $values List of attributes for customer item |
|
170
|
|
|
* @param \Aimeos\MShop\Common\Item\Lists\Iface[] $listItems List of list items |
|
171
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items |
|
172
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface[] $addrItems List of address items |
|
173
|
|
|
* @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items |
|
174
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface New customer item |
|
175
|
|
|
*/ |
|
176
|
|
|
protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [], |
|
177
|
|
|
array $addrItems = [], array $propItems = [] ) : \Aimeos\MShop\Common\Item\Iface |
|
178
|
|
|
{ |
|
179
|
|
|
$values['.listitems'] = $listItems; |
|
180
|
|
|
$values['.propitems'] = $propItems; |
|
181
|
|
|
$values['.addritems'] = $addrItems; |
|
182
|
|
|
|
|
183
|
|
|
return $this->create( $values ); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Deletes items. |
|
189
|
|
|
* |
|
190
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface|\Aimeos\Map|array|string $items List of item objects or IDs of the items |
|
191
|
|
|
* @param string $cfgpath Configuration path to the SQL statement |
|
192
|
|
|
* @param bool $siteid If siteid should be used in the statement |
|
193
|
|
|
* @param string $name Name of the ID column |
|
194
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls |
|
195
|
|
|
*/ |
|
196
|
|
|
protected function deleteItemsBase( $items, string $cfgpath, bool $siteid = true, |
|
197
|
|
|
string $name = 'id' ) : \Aimeos\MShop\Common\Manager\Iface |
|
198
|
|
|
{ |
|
199
|
|
|
if( map( $items )->isEmpty() ) { |
|
200
|
|
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
$search = $this->object()->filter(); |
|
204
|
|
|
$search->setConditions( $search->compare( '==', $name, $items ) ); |
|
205
|
|
|
|
|
206
|
|
|
$types = array( $name => \Aimeos\Base\DB\Statement\Base::PARAM_STR ); |
|
207
|
|
|
$translations = array( $name => '"' . $name . '"' ); |
|
208
|
|
|
|
|
209
|
|
|
$cond = $search->getConditionSource( $types, $translations ); |
|
210
|
|
|
$sql = str_replace( ':cond', $cond, $this->getSqlConfig( $cfgpath ) ); |
|
211
|
|
|
|
|
212
|
|
|
$context = $this->context(); |
|
213
|
|
|
$conn = $context->db( $this->getResourceName() ); |
|
214
|
|
|
|
|
215
|
|
|
$stmt = $conn->create( $sql ); |
|
216
|
|
|
|
|
217
|
|
|
if( $siteid ) |
|
218
|
|
|
{ |
|
219
|
|
|
$stmt->bind( 1, $context->locale()->getSiteId() . '%' ); |
|
220
|
|
|
$stmt->bind( 2, $context->user()?->getSiteId() ); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
$stmt->execute()->finish(); |
|
224
|
|
|
|
|
225
|
|
|
return $this; |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths