1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Repositories\ProductIntRepository |
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 integer 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
|
|
View Code Duplication |
class ProductIntRepository extends AbstractFinderRepository implements ProductIntRepositoryInterface |
|
|
|
|
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_INTS)); |
50
|
|
|
$this->addFinder($this->finderFactory->createFinder($this, SqlStatementKeys::PRODUCT_INTS_BY_PK_AND_STORE_ID)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Return's the primary key name of the entity. |
55
|
|
|
* |
56
|
|
|
* @return string The name of the entity's primary key |
57
|
|
|
*/ |
58
|
|
|
public function getPrimaryKeyName() |
59
|
|
|
{ |
60
|
|
|
return MemberNames::VALUE_ID; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Return's the finder's entity name. |
65
|
|
|
* |
66
|
|
|
* @return string The finder's entity name |
67
|
|
|
*/ |
68
|
|
|
public function getEntityName() |
69
|
|
|
{ |
70
|
|
|
return CacheKeys::PRODUCT_INT; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Load's and return's the available integer attributes. |
75
|
|
|
* |
76
|
|
|
* @return array The integer attributes |
77
|
|
|
*/ |
78
|
|
|
public function findAll() |
79
|
|
|
{ |
80
|
|
|
foreach ($this->getFinder(SqlStatementKeys::PRODUCT_INTS)->find() as $result) { |
81
|
|
|
yield $result; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Load's and return's the text attributes with the passed primary key/store ID. |
87
|
|
|
* |
88
|
|
|
* @param integer $pk The primary key of the attributes |
89
|
|
|
* @param integer $storeId The store ID of the attributes |
90
|
|
|
* |
91
|
|
|
* @return array The text attributes |
92
|
|
|
*/ |
93
|
|
|
public function findAllByPrimaryKeyAndStoreId($pk, $storeId) |
94
|
|
|
{ |
95
|
|
|
|
96
|
|
|
// prepare the params |
97
|
|
|
$params = array(MemberNames::PK => $pk, MemberNames::STORE_ID => $storeId); |
98
|
|
|
|
99
|
|
|
// load the entities and return them |
100
|
|
|
foreach ($this->getFinder(SqlStatementKeys::PRODUCT_INTS_BY_PK_AND_STORE_ID)->find($params) as $result) { |
101
|
|
|
yield $result; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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.