Completed
Push — master ( 8d486f...f6c714 )
by Aimeos
01:43
created
controller/frontend/src/Controller/Frontend/Customer/Standard.php 1 patch
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -28,29 +28,29 @@  discard block
 block discarded – undo
28 28
 	 * @return \Aimeos\MShop\Customer\Item\Iface Customer item
29 29
 	 * @since 2017.04
30 30
 	 */
31
-	public function addItem( array $values )
31
+	public function addItem(array $values)
32 32
 	{
33 33
 		$list = [];
34 34
 		$context = $this->getContext();
35 35
 		$config = $context->getConfig();
36 36
 
37
-		foreach( $values as $key => $val ) {
38
-			$list[str_replace( 'order.base.address', 'customer', $key )] = $val;
37
+		foreach ($values as $key => $val) {
38
+			$list[str_replace('order.base.address', 'customer', $key)] = $val;
39 39
 		}
40 40
 
41
-		$manager = \Aimeos\MShop::create( $context, 'customer' );
42
-		$list = $this->addItemDefaults( $list );
41
+		$manager = \Aimeos\MShop::create($context, 'customer');
42
+		$list = $this->addItemDefaults($list);
43 43
 		$passwd = $list['customer.password'];
44 44
 
45 45
 		try
46 46
 		{
47
-			$item = $manager->findItem( $list['customer.code'], [], true );
47
+			$item = $manager->findItem($list['customer.code'], [], true);
48 48
 		}
49
-		catch( \Aimeos\MShop\Exception $e )
49
+		catch (\Aimeos\MShop\Exception $e)
50 50
 		{
51
-			$this->checkLimit( $list );
51
+			$this->checkLimit($list);
52 52
 
53
-			$item = $manager->createItem()->fromArray( $list )->setId( null );
53
+			$item = $manager->createItem()->fromArray($list)->setId(null);
54 54
 
55 55
 			/** controller/frontend/customer/groupids
56 56
 			 * List of groups new customers should be assigned to
@@ -64,14 +64,14 @@  discard block
 block discarded – undo
64 64
 			 * @category User
65 65
 			 * @category Developer
66 66
 			 */
67
-			$item->setGroups( (array) $config->get( 'controller/frontend/customer/groupids', [] ) );
67
+			$item->setGroups((array) $config->get('controller/frontend/customer/groupids', []));
68 68
 
69
-			$item = $manager->saveItem( $item );
69
+			$item = $manager->saveItem($item);
70 70
 
71 71
 			$msg = $item->toArray();
72 72
 			// Show only generated passwords in account creation e-mails
73
-			$msg['customer.password'] = ( isset( $values['customer.password'] ) ? null : $passwd );
74
-			$context->getMessageQueue( 'mq-email', 'customer/email/account' )->add( json_encode( $msg ) );
73
+			$msg['customer.password'] = (isset($values['customer.password']) ? null : $passwd);
74
+			$context->getMessageQueue('mq-email', 'customer/email/account')->add(json_encode($msg));
75 75
 		}
76 76
 
77 77
 		return $item;
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @return \Aimeos\MShop\Customer\Item\Iface Customer item
85 85
 	 */
86
-	public function createItem( array $values = [] )
86
+	public function createItem(array $values = [])
87 87
 	{
88
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' );
89
-		return $manager->createItem()->fromArray( $values )->setId( null );
88
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer');
89
+		return $manager->createItem()->fromArray($values)->setId(null);
90 90
 	}
91 91
 
92 92
 
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 	 * @param string $id Unique customer ID
97 97
 	 * @since 2017.04
98 98
 	 */
99
-	public function deleteItem( $id )
99
+	public function deleteItem($id)
100 100
 	{
101
-		$this->checkUser( $id );
101
+		$this->checkUser($id);
102 102
 
103
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' );
104
-		$manager->deleteItem( $id );
103
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer');
104
+		$manager->deleteItem($id);
105 105
 	}
106 106
 
107 107
 
@@ -113,15 +113,15 @@  discard block
 block discarded – undo
113 113
 	 * @return \Aimeos\MShop\Customer\Item\Iface Customer item
114 114
 	 * @since 2017.04
115 115
 	 */
116
-	public function editItem( $id, array $values )
116
+	public function editItem($id, array $values)
117 117
 	{
118
-		$this->checkUser( $id );
119
-		unset( $values['customer.id'] );
118
+		$this->checkUser($id);
119
+		unset($values['customer.id']);
120 120
 
121
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' );
122
-		$item = $manager->getItem( $id, ['customer/group'], true )->fromArray( $values );
121
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer');
122
+		$item = $manager->getItem($id, ['customer/group'], true)->fromArray($values);
123 123
 
124
-		return $manager->saveItem( $item );
124
+		return $manager->saveItem($item);
125 125
 	}
126 126
 
127 127
 
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
 	 * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items
134 134
 	 * @since 2017.04
135 135
 	 */
136
-	public function getItem( $id = null, array $domains = [] )
136
+	public function getItem($id = null, array $domains = [])
137 137
 	{
138
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' );
138
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer');
139 139
 
140
-		if( $id == null ) {
141
-			return $manager->getItem( $this->getContext()->getUserId(), $domains, true );
140
+		if ($id == null) {
141
+			return $manager->getItem($this->getContext()->getUserId(), $domains, true);
142 142
 		}
143 143
 
144
-		$this->checkUser( $id );
144
+		$this->checkUser($id);
145 145
 
146
-		return $manager->getItem( $id, $domains, true );
146
+		return $manager->getItem($id, $domains, true);
147 147
 	}
148 148
 
149 149
 
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 	 * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items
158 158
 	 * @since 2017.04
159 159
 	 */
160
-	public function findItem( $code, array $domains = [] )
160
+	public function findItem($code, array $domains = [])
161 161
 	{
162
-		return \Aimeos\MShop::create( $this->getContext(), 'customer' )->findItem( $code, $domains, true );
162
+		return \Aimeos\MShop::create($this->getContext(), 'customer')->findItem($code, $domains, true);
163 163
 	}
164 164
 
165 165
 
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item
170 170
 	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item including the generated ID
171 171
 	 */
172
-	public function saveItem( \Aimeos\MShop\Customer\Item\Iface $item )
172
+	public function saveItem(\Aimeos\MShop\Customer\Item\Iface $item)
173 173
 	{
174
-		return \Aimeos\MShop::create( $this->getContext(), 'customer' )->saveItem( $item );
174
+		return \Aimeos\MShop::create($this->getContext(), 'customer')->saveItem($item);
175 175
 	}
176 176
 
177 177
 
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item
183 183
 	 * @since 2017.04
184 184
 	 */
185
-	public function addAddressItem( array $values )
185
+	public function addAddressItem(array $values)
186 186
 	{
187 187
 		$context = $this->getContext();
188
-		$manager = \Aimeos\MShop::create( $context, 'customer/address' );
188
+		$manager = \Aimeos\MShop::create($context, 'customer/address');
189 189
 
190
-		$item = $manager->createItem()->fromArray( $values )->setId( null )->setParentId( $context->getUserId() );
191
-		return $manager->saveItem( $item );
190
+		$item = $manager->createItem()->fromArray($values)->setId(null)->setParentId($context->getUserId());
191
+		return $manager->saveItem($item);
192 192
 	}
193 193
 
194 194
 
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item
199 199
 	 */
200
-	public function createAddressItem( array $values = [] )
200
+	public function createAddressItem(array $values = [])
201 201
 	{
202 202
 		$context = $this->getContext();
203
-		$manager = \Aimeos\MShop::create( $context, 'customer/address' );
203
+		$manager = \Aimeos\MShop::create($context, 'customer/address');
204 204
 
205
-		return $manager->createItem()->fromArray( $values )->setId( null )->setParentId( $context->getUserId() );
205
+		return $manager->createItem()->fromArray($values)->setId(null)->setParentId($context->getUserId());
206 206
 	}
207 207
 
208 208
 
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
 	 * @param string $id Unique customer address ID
213 213
 	 * @since 2017.04
214 214
 	 */
215
-	public function deleteAddressItem( $id )
215
+	public function deleteAddressItem($id)
216 216
 	{
217
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/address' );
217
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer/address');
218 218
 
219
-		$this->checkUser( $manager->getItem( $id, [], true )->getParentId() );
219
+		$this->checkUser($manager->getItem($id, [], true)->getParentId());
220 220
 
221
-		$manager->deleteItem( $id );
221
+		$manager->deleteItem($id);
222 222
 	}
223 223
 
224 224
 
@@ -230,15 +230,15 @@  discard block
 block discarded – undo
230 230
 	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item
231 231
 	 * @since 2017.04
232 232
 	 */
233
-	public function editAddressItem( $id, array $values )
233
+	public function editAddressItem($id, array $values)
234 234
 	{
235
-		unset( $values['customer.address.id'] );
236
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/address' );
235
+		unset($values['customer.address.id']);
236
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer/address');
237 237
 
238
-		$item = $manager->getItem( $id, [], true );
239
-		$this->checkUser( $item->getParentId() );
238
+		$item = $manager->getItem($id, [], true);
239
+		$this->checkUser($item->getParentId());
240 240
 
241
-		return $manager->saveItem( $item->fromArray( $values ) );
241
+		return $manager->saveItem($item->fromArray($values));
242 242
 	}
243 243
 
244 244
 
@@ -249,12 +249,12 @@  discard block
 block discarded – undo
249 249
 	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item
250 250
 	 * @since 2017.04
251 251
 	 */
252
-	public function getAddressItem( $id )
252
+	public function getAddressItem($id)
253 253
 	{
254
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/address' );
254
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer/address');
255 255
 
256
-		$item = $manager->getItem( $id );
257
-		$this->checkUser( $item->getParentId() );
256
+		$item = $manager->getItem($id);
257
+		$this->checkUser($item->getParentId());
258 258
 
259 259
 		return $item;
260 260
 	}
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 	 * @param \Aimeos\MShop\Customer\Item\Address\Iface $item Customer address item
267 267
 	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item including the generated ID
268 268
 	 */
269
-	public function saveAddressItem( \Aimeos\MShop\Customer\Item\Address\Iface $item )
269
+	public function saveAddressItem(\Aimeos\MShop\Customer\Item\Address\Iface $item)
270 270
 	{
271
-		return \Aimeos\MShop::create( $this->getContext(), 'customer/address' )->saveItem( $item );
271
+		return \Aimeos\MShop::create($this->getContext(), 'customer/address')->saveItem($item);
272 272
 	}
273 273
 
274 274
 
@@ -279,13 +279,13 @@  discard block
 block discarded – undo
279 279
 	 * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item
280 280
 	 * @since 2017.06
281 281
 	 */
282
-	public function addListItem( array $values )
282
+	public function addListItem(array $values)
283 283
 	{
284 284
 		$context = $this->getContext();
285
-		$manager = \Aimeos\MShop::create( $context, 'customer/lists' );
285
+		$manager = \Aimeos\MShop::create($context, 'customer/lists');
286 286
 
287
-		$item = $manager->createItem()->fromArray( $values )->setId( null )->setParentId( $context->getUserId() );
288
-		return $manager->saveItem( $item );
287
+		$item = $manager->createItem()->fromArray($values)->setId(null)->setParentId($context->getUserId());
288
+		return $manager->saveItem($item);
289 289
 	}
290 290
 
291 291
 
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 	public function createListsFilter()
299 299
 	{
300 300
 		$context = $this->getContext();
301
-		$manager = \Aimeos\MShop::create( $context, 'customer/lists' );
301
+		$manager = \Aimeos\MShop::create($context, 'customer/lists');
302 302
 
303 303
 		$filter = $manager->createSearch();
304
-		$filter->setConditions( $filter->compare( '==', 'customer.lists.parentid', $context->getUserId() ) );
304
+		$filter->setConditions($filter->compare('==', 'customer.lists.parentid', $context->getUserId()));
305 305
 
306 306
 		return $filter;
307 307
 	}
@@ -313,13 +313,13 @@  discard block
 block discarded – undo
313 313
 	 * @param string $id Unique customer address ID
314 314
 	 * @since 2017.06
315 315
 	 */
316
-	public function deleteListItem( $id )
316
+	public function deleteListItem($id)
317 317
 	{
318
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/lists' );
318
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer/lists');
319 319
 
320
-		$this->checkUser( $manager->getItem( $id )->getParentId() );
320
+		$this->checkUser($manager->getItem($id)->getParentId());
321 321
 
322
-		$manager->deleteItem( $id );
322
+		$manager->deleteItem($id);
323 323
 	}
324 324
 
325 325
 
@@ -331,16 +331,16 @@  discard block
 block discarded – undo
331 331
 	 * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item
332 332
 	 * @since 2017.06
333 333
 	 */
334
-	public function editListItem( $id, array $values )
334
+	public function editListItem($id, array $values)
335 335
 	{
336 336
 		$context = $this->getContext();
337
-		$manager = \Aimeos\MShop::create( $context, 'customer/lists' );
337
+		$manager = \Aimeos\MShop::create($context, 'customer/lists');
338 338
 
339
-		$item = $manager->getItem( $id, [], true );
340
-		$this->checkUser( $item->getParentId() );
341
-		unset( $values['customer.lists.id'] );
339
+		$item = $manager->getItem($id, [], true);
340
+		$this->checkUser($item->getParentId());
341
+		unset($values['customer.lists.id']);
342 342
 
343
-		return $manager->saveItem( $item->fromArray( $values ) );
343
+		return $manager->saveItem($item->fromArray($values));
344 344
 	}
345 345
 
346 346
 
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
 	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item
352 352
 	 * @since 2017.06
353 353
 	 */
354
-	public function getListItem( $id )
354
+	public function getListItem($id)
355 355
 	{
356
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/lists' );
357
-		$item = $manager->getItem( $id );
356
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer/lists');
357
+		$item = $manager->getItem($id);
358 358
 
359
-		$this->checkUser( $item->getParentId() );
359
+		$this->checkUser($item->getParentId());
360 360
 
361 361
 		return $item;
362 362
 	}
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
 	 * @return \Aimeos\MShop\Common\Item\Lists\Iface[] Customer list items
371 371
 	 * @since 2017.06
372 372
 	 */
373
-	public function searchListItems( \Aimeos\MW\Criteria\Iface $filter, &$total = null )
373
+	public function searchListItems(\Aimeos\MW\Criteria\Iface $filter, &$total = null)
374 374
 	{
375
-		$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/lists' );
375
+		$manager = \Aimeos\MShop::create($this->getContext(), 'customer/lists');
376 376
 
377
-		return $manager->searchItems( $filter, [], $total );
377
+		return $manager->searchItems($filter, [], $total);
378 378
 	}
379 379
 
380 380
 
@@ -384,33 +384,33 @@  discard block
 block discarded – undo
384 384
 	 * @param string[] $values Associative list of customer keys (e.g. "customer.label") and their values
385 385
 	 * @return string[] Associative list of customer key/value pairs with default values set
386 386
 	 */
387
-	protected function addItemDefaults( array $values )
387
+	protected function addItemDefaults(array $values)
388 388
 	{
389
-		if( !isset( $values['customer.label'] ) || $values['customer.label'] == '' )
389
+		if (!isset($values['customer.label']) || $values['customer.label'] == '')
390 390
 		{
391 391
 			$label = '';
392 392
 
393
-			if( isset( $values['customer.lastname'] ) ) {
393
+			if (isset($values['customer.lastname'])) {
394 394
 				$label = $values['customer.lastname'];
395 395
 			}
396 396
 
397
-			if( isset( $values['customer.firstname'] ) && $values['customer.firstname'] != '' ) {
397
+			if (isset($values['customer.firstname']) && $values['customer.firstname'] != '') {
398 398
 				$label = $values['customer.firstname'] . ' ' . $label;
399 399
 			}
400 400
 
401
-			if( isset( $values['customer.company'] ) && $values['customer.company'] != '' ) {
401
+			if (isset($values['customer.company']) && $values['customer.company'] != '') {
402 402
 				$label .= ' (' . $values['customer.company'] . ')';
403 403
 			}
404 404
 
405 405
 			$values['customer.label'] = $label;
406 406
 		}
407 407
 
408
-		if( !isset( $values['customer.code'] ) && isset( $values['customer.email'] ) ) {
408
+		if (!isset($values['customer.code']) && isset($values['customer.email'])) {
409 409
 			$values['customer.code'] = $values['customer.email'];
410 410
 		}
411 411
 
412
-		if( !isset( $values['customer.password'] ) ) {
413
-			$values['customer.password'] = substr( md5( microtime( true ) . getmypid() . rand() ), -8 );
412
+		if (!isset($values['customer.password'])) {
413
+			$values['customer.password'] = substr(md5(microtime(true) . getmypid() . rand()), -8);
414 414
 		}
415 415
 
416 416
 		return $values;
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 	 * @param string[] $values Associative list of customer keys (e.g. "customer.label") and their values
424 424
 	 * @throws \Aimeos\Controller\Frontend\Customer\Exception If access isn't allowed
425 425
 	 */
426
-	protected function checkLimit( array $values )
426
+	protected function checkLimit(array $values)
427 427
 	{
428 428
 		$total = 0;
429 429
 		$context = $this->getContext();
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 		 * @category Developer
445 445
 		 * @see controller/frontend/customer/limit-seconds
446 446
 		 */
447
-		$count = $config->get( 'controller/frontend/customer/limit-count', 5 );
447
+		$count = $config->get('controller/frontend/customer/limit-count', 5);
448 448
 
449 449
 		/** controller/frontend/customer/limit-seconds
450 450
 		 * Customer account limitation time frame in seconds
@@ -462,22 +462,22 @@  discard block
 block discarded – undo
462 462
 		 * @category Developer
463 463
 		 * @see controller/frontend/customer/limit-count
464 464
 		 */
465
-		$seconds = $config->get( 'controller/frontend/customer/limit-seconds', 300 );
465
+		$seconds = $config->get('controller/frontend/customer/limit-seconds', 300);
466 466
 
467
-		$manager = \Aimeos\MShop::create( $context, 'customer' );
467
+		$manager = \Aimeos\MShop::create($context, 'customer');
468 468
 
469 469
 		$search = $manager->createSearch();
470 470
 		$expr = [
471
-			$search->compare( '==', 'customer.editor', $context->getEditor() ),
472
-			$search->compare( '>=', 'customer.ctime', date( 'Y-m-d H:i:s', time() - $seconds ) ),
471
+			$search->compare('==', 'customer.editor', $context->getEditor()),
472
+			$search->compare('>=', 'customer.ctime', date('Y-m-d H:i:s', time() - $seconds)),
473 473
 		];
474
-		$search->setConditions( $search->combine( '&&', $expr ) );
475
-		$search->setSlice( 0, 0 );
474
+		$search->setConditions($search->combine('&&', $expr));
475
+		$search->setSlice(0, 0);
476 476
 
477
-		$manager->searchItems( $search, [], $total );
477
+		$manager->searchItems($search, [], $total);
478 478
 
479
-		if( $total > $count ) {
480
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Temporary limit reached' ) );
479
+		if ($total > $count) {
480
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Temporary limit reached'));
481 481
 		}
482 482
 	}
483 483
 
@@ -488,12 +488,12 @@  discard block
 block discarded – undo
488 488
 	 * @param string $id Unique customer ID
489 489
 	 * @throws \Aimeos\Controller\Frontend\Customer\Exception If access isn't allowed
490 490
 	 */
491
-	protected function checkUser( $id )
491
+	protected function checkUser($id)
492 492
 	{
493
-		if( $id != $this->getContext()->getUserId() )
493
+		if ($id != $this->getContext()->getUserId())
494 494
 		{
495
-			$msg = sprintf( 'Not allowed to access customer data for ID "%1$s"', $id );
496
-			throw new \Aimeos\Controller\Frontend\Customer\Exception( $msg );
495
+			$msg = sprintf('Not allowed to access customer data for ID "%1$s"', $id);
496
+			throw new \Aimeos\Controller\Frontend\Customer\Exception($msg);
497 497
 		}
498 498
 	}
499 499
 }
Please login to merge, or discard this patch.