1 <?php
2 /* --------------------------------------------------------------
3 CustomerService.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('CustomerServiceInterface');
13
14 /**
15 * Class CustomerService
16 *
17 * This class provides methods for creating and deleting customer data
18 *
19 * @category System
20 * @package Customer
21 * @implements CustomerServiceInterface
22 */
23 class CustomerService implements CustomerServiceInterface
24 {
25 /**
26 * Customer read service.
27 * @var CustomerReadServiceInterface
28 */
29 protected $customerReadService;
30
31 /**
32 * Customer write service.
33 * @var CustomerWriteServiceInterface
34 */
35 protected $customerWriteService;
36
37
38 /**
39 * Constructor of the class CustomerService.
40 *
41 * @param CustomerReadServiceInterface $customerReadService Customer read service.
42 * @param CustomerWriteServiceInterface $customerWriteService Customer write service.
43 */
44 public function __construct(CustomerReadServiceInterface $customerReadService,
45 CustomerWriteServiceInterface $customerWriteService)
46 {
47 $this->customerReadService = $customerReadService;
48 $this->customerWriteService = $customerWriteService;
49 }
50
51
52 /**
53 * Creates a new customer with the given parameters.
54 *
55 * @param CustomerEmailInterface $email Customer's E-Mail address.
56 * @param CustomerPasswordInterface $password Customer's password.
57 * @param DateTime $dateOfBirth Customer's date of birth.
58 * @param CustomerVatNumberInterface $vatNumber Customer's VAT number.
59 * @param CustomerCallNumberInterface $telephoneNumber Customer's telephone number.
60 * @param CustomerCallNumberInterface $faxNumber Customer's fax number.
61 * @param AddressBlockInterface $addressBlock Customer's address.
62 *
63 * @return Customer Created customer.
64 * @throws UnexpectedValueException On invalid arguments.
65 *
66 * TODO Replaced by VAT Check
67 * TODO Rename to createNewRegistree
68 */
69 public function createNewCustomer(CustomerEmailInterface $email,
70 CustomerPasswordInterface $password,
71 DateTime $dateOfBirth,
72 CustomerVatNumberInterface $vatNumber,
73 CustomerCallNumberInterface $telephoneNumber,
74 CustomerCallNumberInterface $faxNumber,
75 AddressBlockInterface $addressBlock)
76 {
77 return $this->customerWriteService->createNewRegistree($email, $password, $dateOfBirth, $vatNumber,
78 $telephoneNumber, $faxNumber, $addressBlock);
79 }
80
81
82 /**
83 * Creates a new guest account with the given parameters.
84 *
85 * @param CustomerEmailInterface $email Customer's E-Mail address.
86 * @param DateTime $dateOfBirth Customer's date of birth.
87 * @param CustomerVatNumberInterface $vatNumber Customer's VAT number.
88 * @param CustomerCallNumberInterface $telephoneNumber Customer's telephone number.
89 * @param CustomerCallNumberInterface $faxNumber Customer's fax number.
90 * @param AddressBlockInterface $addressBlock Customer's address.
91 *
92 * @return Customer Created guest customer.
93 * @throws UnexpectedValueException On invalid arguments.
94 */
95 public function createNewGuest(CustomerEmailInterface $email,
96 DateTime $dateOfBirth,
97 CustomerVatNumberInterface $vatNumber,
98 CustomerCallNumberInterface $telephoneNumber,
99 CustomerCallNumberInterface $faxNumber,
100 AddressBlockInterface $addressBlock)
101 {
102 return $this->customerWriteService->createNewGuest($email, $dateOfBirth, $vatNumber, $telephoneNumber,
103 $faxNumber, $addressBlock);
104 }
105
106
107 /**
108 * Finds a customer by its ID.
109 *
110 * @param IdType $customerId Customer's ID.
111 *
112 * @return Customer Customer.
113 */
114 public function getCustomerById(IdType $customerId)
115 {
116 return $this->customerReadService->getCustomerById($customerId);
117 }
118
119
120 /**
121 * Deletes the customer by its ID.
122 *
123 * @param IdType $customerId Customer's ID.
124 */
125 public function deleteCustomerById(IdType $customerId)
126 {
127 return $this->customerWriteService->deleteCustomerById($customerId);
128 }
129
130
131 /**
132 * Checks if the email address of the registree already exists.
133 *
134 * @param CustomerEmailInterface $email Customer's E-Mail address.
135 *
136 * @return bool Does the provided E-Mail address already exist?
137 */
138 public function registreeEmailExists(CustomerEmailInterface $email)
139 {
140 return $this->customerReadService->registreeEmailExists($email);
141 }
142
143
144 /**
145 * Updates customer data.
146 *
147 * @param CustomerInterface $customer Customer.
148 *
149 * @return CustomerInterface Updated customer.
150 */
151 public function updateCustomer(CustomerInterface $customer)
152 {
153 return $this->customerWriteService->updateCustomer($customer);
154 }
155
156
157 /**
158 * Checks if address is the default address of the customer.
159 *
160 * @param CustomerAddressInterface $customerAddress Customer's address.
161 *
162 * @return bool Is the provided address the customer's default address?
163 */
164 public function addressIsDefaultCustomerAddress(CustomerAddressInterface $customerAddress)
165 {
166 return $this->customerReadService->addressIsDefaultCustomerAddress($customerAddress);
167 }
168
169
170 /**
171 * Filters customer records and returns an array with results.
172 *
173 * Example:
174 * $service->filterCustomers('customers_id' => 1);
175 *
176 * @param array $conditions Associative array containing the desired field and value.
177 * @param int $limit MySQL limit applied to the records.
178 * @param int $offset MySQL offset applied to the records.
179 *
180 * @return array Returns an array that contains customer objects.
181 */
182 public function filterCustomers(array $conditions = array(), $limit = null, $offset = null)
183 {
184 return $this->customerReadService->filterCustomers($conditions, $limit, $offset);
185 }
186 }