1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Repositories\ProductVarcharRepository |
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-product |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Repositories; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Utils\CacheKeys; |
24
|
|
|
use TechDivision\Import\Product\Utils\MemberNames; |
25
|
|
|
use TechDivision\Import\Product\Utils\SqlStatementKeys; |
26
|
|
|
use TechDivision\Import\Repositories\AbstractFinderRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Repository implementation to load product varchar attribute data. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/techdivision/import-product |
35
|
|
|
* @link http://www.techdivision.com |
36
|
|
|
*/ |
37
|
|
|
class ProductVarcharRepository extends AbstractFinderRepository implements ProductVarcharRepositoryInterface |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Initializes the repository's prepared statements. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function init() |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
// initialize the prepared statements |
49
|
|
|
$this->addFinder($this->finderFactory->createFinder($this, SqlStatementKeys::PRODUCT_VARCHARS)); |
50
|
|
|
$this->addFinder($this->finderFactory->createFinder($this, SqlStatementKeys::PRODUCT_VARCHARS_BY_PK_AND_STORE_ID)); |
51
|
|
|
$this->addFinder($this->finderFactory->createFinder($this, SqlStatementKeys::PRODUCT_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_STORE_ID)); |
52
|
|
|
$this->addFinder($this->finderFactory->createFinder($this, SqlStatementKeys::PRODUCT_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_STORE_ID_AND_VALUE)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return's the primary key name of the entity. |
57
|
|
|
* |
58
|
|
|
* @return string The name of the entity's primary key |
59
|
|
|
*/ |
60
|
|
|
public function getPrimaryKeyName() |
61
|
|
|
{ |
62
|
|
|
return MemberNames::VALUE_ID; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Return's the finder's entity name. |
67
|
|
|
* |
68
|
|
|
* @return string The finder's entity name |
69
|
|
|
*/ |
70
|
|
|
public function getEntityName() |
71
|
|
|
{ |
72
|
|
|
return CacheKeys::PRODUCT_VARCHAR; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Load's and return's the available varchar attributes. |
77
|
|
|
* |
78
|
|
|
* @return array The varchar attributes |
79
|
|
|
*/ |
80
|
|
|
public function findAll() |
81
|
|
|
{ |
82
|
|
|
|
83
|
|
|
// load the entities and return them |
84
|
|
|
foreach ($this->getFinder(SqlStatementKeys::PRODUCT_VARCHARS)->find() as $result) { |
85
|
|
|
yield $result; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Load's and return's the varchar attributes with the passed primary key/store ID. |
91
|
|
|
* |
92
|
|
|
* @param integer $pk The primary key of the attributes |
93
|
|
|
* @param integer $storeId The store ID of the attributes |
94
|
|
|
* |
95
|
|
|
* @return array The varchar attributes |
96
|
|
|
*/ |
97
|
|
|
public function findAllByPrimaryKeyAndStoreId($pk, $storeId) |
98
|
|
|
{ |
99
|
|
|
|
100
|
|
|
// prepare the params |
101
|
|
|
$params = array(MemberNames::PK => $pk, MemberNames::STORE_ID => $storeId); |
102
|
|
|
|
103
|
|
|
// load the entities and return them |
104
|
|
|
foreach ($this->getFinder(SqlStatementKeys::PRODUCT_VARCHARS_BY_PK_AND_STORE_ID)->find($params) as $result) { |
105
|
|
|
yield $result; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Load's and return's the varchar attributes with the passed params. |
111
|
|
|
* |
112
|
|
|
* @param integer $attributeCode The attribute code of the varchar attribute |
113
|
|
|
* @param integer $entityTypeId The entity type ID of the varchar attribute |
114
|
|
|
* @param integer $storeId The store ID of the varchar attribute |
115
|
|
|
* |
116
|
|
|
* @return array The varchar attributes |
117
|
|
|
*/ |
118
|
|
View Code Duplication |
public function findAllByAttributeCodeAndEntityTypeIdAndStoreId($attributeCode, $entityTypeId, $storeId) |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
|
121
|
|
|
// prepare the params |
122
|
|
|
$params = array( |
123
|
|
|
MemberNames::ATTRIBUTE_CODE => $attributeCode, |
124
|
|
|
MemberNames::ENTITY_TYPE_ID => $entityTypeId, |
125
|
|
|
MemberNames::STORE_ID => $storeId, |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
// load the entities and return them |
129
|
|
|
foreach ($this->getFinder(SqlStatementKeys::PRODUCT_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_STORE_ID)->find($params) as $result) { |
130
|
|
|
yield $result; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Load's and return's the varchar attribute with the passed params. |
136
|
|
|
* |
137
|
|
|
* @param integer $attributeCode The attribute code of the varchar attribute |
138
|
|
|
* @param integer $entityTypeId The entity type ID of the varchar attribute |
139
|
|
|
* @param integer $storeId The store ID of the varchar attribute |
140
|
|
|
* @param string $value The value of the varchar attribute |
141
|
|
|
* |
142
|
|
|
* @return array|null The varchar attribute |
143
|
|
|
*/ |
144
|
|
View Code Duplication |
public function findOneByAttributeCodeAndEntityTypeIdAndStoreIdAndValue($attributeCode, $entityTypeId, $storeId, $value) |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
|
147
|
|
|
// prepare the params |
148
|
|
|
$params = array( |
149
|
|
|
MemberNames::ATTRIBUTE_CODE => $attributeCode, |
150
|
|
|
MemberNames::ENTITY_TYPE_ID => $entityTypeId, |
151
|
|
|
MemberNames::STORE_ID => $storeId, |
152
|
|
|
MemberNames::VALUE => $value |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
// load and return the entity |
156
|
|
|
return $this->getFinder(SqlStatementKeys::PRODUCT_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_STORE_ID_AND_VALUE)->find($params); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
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.