1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Repositories\CustomerGroupRepository |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Klaas-Tido Rühl <[email protected]> |
15
|
|
|
* @author Tim Wagner <[email protected]> |
16
|
|
|
* @copyright 2019 REFUSiON GmbH <[email protected]> |
17
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
18
|
|
|
* @link https://github.com/techdivision/import |
19
|
|
|
* @link https://www.techdivision.com |
20
|
|
|
* @link https://www.refusion.com |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace TechDivision\Import\Repositories; |
24
|
|
|
|
25
|
|
|
use TechDivision\Import\Utils\MemberNames; |
26
|
|
|
use TechDivision\Import\Utils\SqlStatementKeys; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The default repository implementation for loading customer groups. |
30
|
|
|
* |
31
|
|
|
* @author Klaas-Tido Rühl <[email protected]> |
32
|
|
|
* @author Tim Wagner <[email protected]> |
33
|
|
|
* @copyright 2019 REFUSiON GmbH <[email protected]> |
34
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
35
|
|
|
* @link https://github.com/techdivision/import |
36
|
|
|
* @link https://www.techdivision.com |
37
|
|
|
* @link https://www.refusion.com |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
class CustomerGroupRepository extends AbstractRepository implements CustomerGroupRepositoryInterface |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The prepared statement to load the customer groups. |
44
|
|
|
* |
45
|
|
|
* @var \PDOStatement |
46
|
|
|
*/ |
47
|
|
|
protected $customerGroupsStmt; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Initializes the repository's prepared statements. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function init() |
55
|
|
|
{ |
56
|
|
|
// initialize the prepared statements |
57
|
|
|
$this->customerGroupsStmt = |
58
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_GROUPS)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns an array with the available customer groups and their code as keys. |
63
|
|
|
* |
64
|
|
|
* @return array The array with the customer groups |
65
|
|
|
*/ |
66
|
|
|
public function findAll() |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
// initialize the array for the customer groups |
70
|
|
|
$customerGroups = []; |
71
|
|
|
|
72
|
|
|
// execute the prepared statement |
73
|
|
|
$this->customerGroupsStmt->execute(); |
74
|
|
|
|
75
|
|
|
// fetch the customer groups and assemble them as array with the codes as key |
76
|
|
|
foreach ($this->customerGroupsStmt->fetchAll() as $customerGroup) { |
77
|
|
|
$customerGroups[$customerGroup[MemberNames::CUSTOMER_GROUP_CODE]] = $customerGroup; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// return the customer groups |
81
|
|
|
return $customerGroups; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.