1 <?php
2 /* --------------------------------------------------------------
3 CustomerReadService.inc.php 2015-02-18 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('CustomerReadServiceInterface');
13
14 /**
15 * Class CustomerReadService
16 *
17 * This class provides methods for creating and deleting customer data
18 *
19 * @category System
20 * @package Customer
21 * @implements CustomerReadServiceInterface
22 */
23 class CustomerReadService implements CustomerReadServiceInterface
24 {
25 /**
26 * Customer repository.
27 * @var CustomerRepositoryInterface
28 */
29 protected $customerRepository;
30
31
32 /**
33 * Constructor of the class CustomerService.
34 *
35 * @param CustomerRepositoryInterface $customerRepository Customer repository.
36 */
37 public function __construct(CustomerRepositoryInterface $customerRepository)
38 {
39 $this->customerRepository = $customerRepository;
40 }
41
42
43 /**
44 * Finds a customer by an entered ID.
45 *
46 * @param IdType $customerId Customer ID.
47 *
48 * @return Customer Customer.
49 */
50 public function getCustomerById(IdType $customerId)
51 {
52 return $this->customerRepository->getCustomerById($customerId);
53 }
54
55
56 /**
57 * Checks if the email address of the registree already exists.
58 *
59 * @param CustomerEmailInterface $email Customer's E-Mail address.
60 *
61 * @return bool Does the E-Mail address already exist?
62 */
63 public function registreeEmailExists(CustomerEmailInterface $email)
64 {
65 $customer = $this->customerRepository->getRegistreeByEmail($email);
66 if($customer === null)
67 {
68 return false;
69 }
70
71 return true;
72 }
73
74
75 /**
76 * Checks if address is the default address of the customer.
77 *
78 * @param CustomerAddressInterface $customerAddress Customer's address.
79 *
80 * @return bool Is provided address the customer's default address?
81 */
82 public function addressIsDefaultCustomerAddress(CustomerAddressInterface $customerAddress)
83 {
84 $customer = $this->getCustomerById(new IdType((string)$customerAddress->getCustomerId()));
85
86 return $customer->getDefaultAddress()->getId() == new IdType((string)$customerAddress->getCustomerId());
87 }
88
89
90 /**
91 * Filters customer records and returns an array with results.
92 *
93 * Example:
94 * $service->filterCustomers('customers_id' => 1);
95 *
96 * @param array $conditions Associative array containing the desired field and value.
97 * @param int $limit MySQL limit applied to the records.
98 * @param int $offset MySQL offset applied to the records.
99 *
100 * @return array Returns an array that contains customer objects.
101 */
102 public function filterCustomers(array $conditions = array(), $limit = null, $offset = null)
103 {
104 return $this->customerRepository->filterCustomers($conditions, $limit, $offset);
105 }
106 }