|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
|
6
|
|
|
* @package laravel |
|
7
|
|
|
* @subpackage Base |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Shop\Base; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Service providing the supporting functionality |
|
15
|
|
|
* |
|
16
|
|
|
* @package laravel |
|
17
|
|
|
* @subpackage Base |
|
18
|
|
|
*/ |
|
19
|
|
|
class Support |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var \Aimeos\Shop\Base\Context |
|
23
|
|
|
*/ |
|
24
|
|
|
private $context; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Initializes the object |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Aimeos\Shop\Base\Context $context Context object |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( \Aimeos\Shop\Base\Context $context ) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->context = $context; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Checks if the user with the given ID is in the specified group |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $userid Unique user ID |
|
42
|
|
|
* @param string|array $groupcodes Unique user/customer group codes that are allowed |
|
43
|
|
|
* @return boolean True if user is part of the group, false if not |
|
44
|
|
|
*/ |
|
45
|
|
|
public function checkGroup( $userid, $groupcodes ) |
|
46
|
|
|
{ |
|
47
|
|
|
$groupItems = $this->getGroups( (array) $groupcodes ); |
|
48
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context->get(), 'customer/lists' ); |
|
49
|
|
|
|
|
50
|
|
|
$search = $manager->createSearch(); |
|
51
|
|
|
$expr = array( |
|
52
|
|
|
$search->compare( '==', 'customer.lists.parentid', $userid ), |
|
53
|
|
|
$search->compare( '==', 'customer.lists.refid', array_keys( $groupItems ) ), |
|
54
|
|
|
$search->compare( '==', 'customer.lists.domain', 'customer/group' ), |
|
55
|
|
|
); |
|
56
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
|
57
|
|
|
$search->setSlice( 0, 1 ); |
|
58
|
|
|
|
|
59
|
|
|
return (bool) count( $manager->searchItems( $search ) ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the groups items for the given codes |
|
65
|
|
|
* |
|
66
|
|
|
* @param array $codes List of group codes |
|
67
|
|
|
* @return array Associative list of group IDs as keys and \Aimeos\MShop\Customer\Item\Group\Iface as values |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function getGroups( array $codes ) |
|
70
|
|
|
{ |
|
71
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context->get(), 'customer/group' ); |
|
72
|
|
|
|
|
73
|
|
|
$search = $manager->createSearch(); |
|
74
|
|
|
$search->setConditions( $search->compare( '==', 'customer.group.code', $codes ) ); |
|
75
|
|
|
|
|
76
|
|
|
return $manager->searchItems( $search ); |
|
77
|
|
|
} |
|
78
|
|
|
} |