1 <?php
2 /* --------------------------------------------------------------
3 CustomerStatusProvider.inc.php 2016-02-12
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2016 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 /**
13 * Class CustomerStatusProvider
14 *
15 * @category System
16 * @package Shared
17 */
18 class CustomerStatusProvider implements CustomerStatusProviderInterface
19 {
20 /**
21 * @var CI_DB_query_builder $db
22 */
23 protected $db;
24
25
26 /**
27 * @param CI_DB_query_builder $db The database to fetch the customer status data from.
28 */
29 public function __construct(CI_DB_query_builder $db)
30 {
31 $this->db = $db;
32 }
33
34
35 /**
36 * Get All Customer Status Ids
37 *
38 * Returns all available customer status IDs.
39 *
40 * @throws UnexpectedValueException
41 *
42 * @return array All customer status ids
43 */
44 public function getCustomerStatusIds()
45 {
46 $query = $this->db->select('customers_status_id')->from('customers_status');
47 $groupPermissionIds = array();
48
49 foreach($query->get()->result_array() as $row)
50 {
51 $groupPermissionIds[] = $row['customers_status_id'];
52 }
53
54 if(count($groupPermissionIds) === 0)
55 {
56 throw new UnexpectedValueException('No customer status ids were found in the database');
57 }
58
59 return array_values(array_unique($groupPermissionIds));
60 }
61 }