Completed
Push — master ( 38eb28...99d1f3 )
by Aimeos
02:23
created

Support::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015
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 $groupcode Unique user/customer group code
43
	 * @return boolean True if user is part of the group, false if not
44
	 */
45
	public function checkGroup( $userid, $groupcode )
46
	{
47
		$context = $this->context->get();
48
		$group = \Aimeos\MShop\Factory::createManager( $context, 'customer/group' )->getItem( $groupcode );
49
		$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer/lists' );
50
51
		$search = $manager->createSearch();
52
		$expr = array(
53
			$search->compare( '==', 'customer.lists.parentid', $userid ),
54
			$search->compare( '==', 'customer.lists.refid', $group->getId() ),
55
			$search->compare( '==', 'customer.lists.domain', 'customer/group' ),
56
		);
57
		$search->setConditions( $search->combine( '&&', $expr ) );
58
		$search->setSlice( 0, 1 );
59
60
		return (bool) count( $manager->searchItems( $search ) );
61
	}
62
}