|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Repositories\EavAttributeRepository |
|
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 Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Repositories; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\MemberNames; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Repository implementation to load EAV attribute data. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Tim Wagner <[email protected]> |
|
29
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link https://github.com/techdivision/import |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class EavAttributeRepository extends AbstractRepository |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The prepared statement to load the attributes by the passed is user defined flag. |
|
39
|
|
|
* |
|
40
|
|
|
* @var \PDOStatement |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $eavAttributesByUserDefinedStmt; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The prepared statement to load the attributes for a specifc option value and store ID. |
|
46
|
|
|
* |
|
47
|
|
|
* @var \PDOStatement |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $eavAttributesByOptionValueAndStoreIdStmt; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The prepared statement to load the attributes for a specific entity type ID and name. |
|
53
|
|
|
* |
|
54
|
|
|
* @var \PDOStatement |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $eavAttributesByEntityTypeIdAndAttributeSetNameStmt; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Initializes the repository's prepared statements. |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
|
|
public function init() |
|
64
|
|
|
{ |
|
65
|
|
|
|
|
66
|
|
|
// load the utility class name |
|
67
|
|
|
$utilityClassName = $this->getUtilityClassName(); |
|
68
|
|
|
|
|
69
|
|
|
// initialize the prepared statements |
|
70
|
|
|
$this->eavAttributesByEntityTypeIdAndAttributeSetNameStmt = $this->getConnection()->prepare($utilityClassName::EAV_ATTRIBUTES_BY_ENTITY_TYPE_ID_AND_ATTRIBUTE_SET_NAME); |
|
71
|
|
|
$this->eavAttributesByOptionValueAndStoreIdStmt = $this->getConnection()->prepare($utilityClassName::EAV_ATTRIBUTES_BY_OPTION_VALUE_AND_STORE_ID); |
|
72
|
|
|
$this->eavAttributesByUserDefinedStmt = $this->getConnection()->prepare($utilityClassName::EAV_ATTRIBUTES_BY_IS_USER_DEFINED); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Return's an array with the available EAV attributes for the passed entity type ID and attribute set name. |
|
77
|
|
|
* |
|
78
|
|
|
* @param integer $entityTypeId The entity type ID of the EAV attributes to return |
|
79
|
|
|
* @param string $attributeSetName The attribute set name of the EAV attributes to return |
|
80
|
|
|
* |
|
81
|
|
|
* @return array The array with all available EAV attributes |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
public function findAllByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
|
|
86
|
|
|
// initialize the params |
|
87
|
|
|
$params = array( |
|
88
|
|
|
MemberNames::ENTITY_TYPE_ID => $entityTypeId, |
|
89
|
|
|
MemberNames::ATTRIBUTE_SET_NAME => $attributeSetName |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
// initialize the array for the EAV attributes |
|
93
|
|
|
$eavAttributes = array(); |
|
94
|
|
|
|
|
95
|
|
|
// execute the prepared statement and return the array with the EAV attributes |
|
96
|
|
|
$this->eavAttributesByEntityTypeIdAndAttributeSetNameStmt->execute($params); |
|
97
|
|
|
foreach ($this->eavAttributesByEntityTypeIdAndAttributeSetNameStmt->fetchAll(\PDO::FETCH_ASSOC) as $eavAttribute) { |
|
98
|
|
|
$eavAttributes[$eavAttribute[MemberNames::ATTRIBUTE_CODE]] = $eavAttribute; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// return the array with the EAV attributes |
|
102
|
|
|
return $eavAttributes; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Return's an array with the available EAV attributes for the passed option value and store ID. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $optionValue The option value of the EAV attributes |
|
109
|
|
|
* @param string $storeId The store ID of the EAV attribues |
|
110
|
|
|
* |
|
111
|
|
|
* @return array The array with all available EAV attributes |
|
112
|
|
|
*/ |
|
113
|
|
|
public function findAllByOptionValueAndStoreId($optionValue, $storeId) |
|
114
|
|
|
{ |
|
115
|
|
|
|
|
116
|
|
|
// initialize the params |
|
117
|
|
|
$params = array( |
|
118
|
|
|
MemberNames::VALUE => $optionValue, |
|
119
|
|
|
MemberNames::STORE_ID => $storeId |
|
120
|
|
|
); |
|
121
|
|
|
|
|
122
|
|
|
// execute the prepared statement and return the array with the EAV attributes |
|
123
|
|
|
$this->eavAttributesByOptionValueAndStoreIdStmt->execute($params); |
|
124
|
|
|
return $this->eavAttributesByOptionValueAndStoreIdStmt->fetchAll(\PDO::FETCH_ASSOC); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Return's an array with the available EAV attributes for the passed is user defined flag. |
|
129
|
|
|
* |
|
130
|
|
|
* @param integer $isUserDefined The flag itself |
|
131
|
|
|
* |
|
132
|
|
|
* @return array The array with the EAV attributes matching the passed flag |
|
133
|
|
|
*/ |
|
134
|
|
View Code Duplication |
public function findAllByIsUserDefined($isUserDefined = 1) |
|
|
|
|
|
|
135
|
|
|
{ |
|
136
|
|
|
|
|
137
|
|
|
// initialize the array for the EAV attributes |
|
138
|
|
|
$eavAttributes = array(); |
|
139
|
|
|
|
|
140
|
|
|
// initialize the params |
|
141
|
|
|
$params = array(MemberNames::ID_USER_DEFINED => $isUserDefined); |
|
142
|
|
|
|
|
143
|
|
|
// execute the prepared statement and return the array with the EAV attributes |
|
144
|
|
|
$this->eavAttributesByUserDefinedStmt->execute($params); |
|
145
|
|
|
foreach ($this->eavAttributesByUserDefinedStmt->fetchAll(\PDO::FETCH_ASSOC) as $eavAttribute) { |
|
146
|
|
|
$eavAttributes[$eavAttribute[MemberNames::ATTRIBUTE_CODE]] = $eavAttribute; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
// return the array with the EAV attributes |
|
150
|
|
|
return $eavAttributes; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Return's the first EAV attribute for the passed option value and store ID. |
|
155
|
|
|
* |
|
156
|
|
|
* @param string $optionValue The option value of the EAV attributes |
|
157
|
|
|
* @param string $storeId The store ID of the EAV attribues |
|
158
|
|
|
* |
|
159
|
|
|
* @return array The array with the EAV attribute |
|
160
|
|
|
* @see \Importer\Csv\Repositories\Pdo\EavAttributeRepository::findAllByOptionValueAndStoreId() |
|
161
|
|
|
*/ |
|
162
|
|
|
public function findOneByOptionValueAndStoreId($optionValue, $storeId) |
|
163
|
|
|
{ |
|
164
|
|
|
|
|
165
|
|
|
// execute the prepared statement and return the array with the fail EAV attributes |
|
166
|
|
|
if (sizeof($eavAttributes = $this->findAllByOptionValueAndStoreId($optionValue, $storeId)) > 0) { |
|
167
|
|
|
return reset($eavAttributes); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
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.