Completed
Push — 17.x ( 3fdb9b...8eca03 )
by Tim
02:21
created

findOneByAttributeCodeAndStoreIdAndValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 10
cp 0
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Repositories\AttributeOptionRepository
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-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Repositories;
22
23
use TechDivision\Import\Attribute\Utils\MemberNames;
24
use TechDivision\Import\Attribute\Utils\SqlStatementKeys;
25
use TechDivision\Import\Repositories\AbstractRepository;
26
27
/**
28
 * Repository implementation to load EAV attribute option data.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/techdivision/import-attribute
34
 * @link      http://www.techdivision.com
35
 */
36
class AttributeOptionRepository extends AbstractRepository implements AttributeOptionRepositoryInterface
37
{
38
39
    /**
40
     * The prepared statement to load an existing EAV attribute option by its entity type ID, attribute code, store ID and value.
41
     *
42
     * @var \PDOStatement
43
     */
44
    protected $attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValueStmt;
45
46
    /**
47
     * The prepared statement to load an existing EAV attribute option by its entity type ID, attribute code, store ID and swatch.
48
     *
49
     * @var \PDOStatement
50
     */
51
    protected $attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndTypeStmt;
52
53
    /**
54
     * The prepared statement to load the EAV attribute option with the given attribute ID and the highest sort order.
55
     *
56
     * @var \PDOStatement
57
     */
58
    protected $attributeOptionByAttributeIdOrderBySortOrderDescStmt;
59
60
    /**
61
     * Initializes the repository's prepared statements.
62
     *
63
     * @return void
64
     */
65
    public function init()
66
    {
67
68
        // initialize the prepared statements
69
        $this->attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValueStmt =
70
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ATTRIBUTE_OPTION_BY_ENTITY_TYPE_ID_AND_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE));
71
        $this->attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndTypeStmt =
72
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ATTRIBUTE_OPTION_BY_ENTITY_TYPE_ID_AND_ATTRIBUTE_CODE_AND_STORE_ID_AND_SWATCH_AND_TYPE));
73
        $this->attributeOptionByAttributeIdOrderBySortOrderDescStmt =
74
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ATTRIBUTE_OPTION_BY_ATTRIBUTE_ID_ORDER_BY_SORT_ORDER_DESC));
75
    }
76
77
    /**
78
     * Load's and return's the EAV attribute option with the passed entity type ID and code, store ID and value.
79
     *
80
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load the option for
81
     * @param string  $attributeCode The code of the EAV attribute option to load
82
     * @param integer $storeId       The store ID of the attribute option to load
83
     * @param string  $value         The value of the attribute option to load
84
     *
85
     * @return array The EAV attribute option
86
     */
87
    public function findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value)
88
    {
89
90
        // the parameters of the EAV attribute option to load
91
        $params = array(
92
            MemberNames::ENTITY_TYPE_ID => $entityTypeId,
93
            MemberNames::ATTRIBUTE_CODE => $attributeCode,
94
            MemberNames::STORE_ID       => $storeId,
95
            MemberNames::VALUE          => $value
96
        );
97
98
        // load and return the EAV attribute option with the passed parameters
99
        $this->attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValueStmt->execute($params);
100
        return $this->attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValueStmt->fetch(\PDO::FETCH_ASSOC);
101
    }
102
103
    /**
104
     * Load's and return's the EAV attribute option with the passed entity type ID and code, store ID, swatch and type.
105
     *
106
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load the option for
107
     * @param string  $attributeCode The code of the EAV attribute option to load
108
     * @param integer $storeId       The store ID of the attribute option to load
109
     * @param string  $swatch        The swatch of the attribute option to load
110
     * @param string  $type          The swatch type of the attribute option to load
111
     *
112
     * @return array The EAV attribute option
113
     */
114 View Code Duplication
    public function findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndType($entityTypeId, $attributeCode, $storeId, $swatch, $type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
115
    {
116
117
        // the parameters of the EAV attribute option to load
118
        $params = array(
119
            MemberNames::ENTITY_TYPE_ID => $entityTypeId,
120
            MemberNames::ATTRIBUTE_CODE => $attributeCode,
121
            MemberNames::STORE_ID       => $storeId,
122
            MemberNames::VALUE          => $swatch,
123
            MemberNames::TYPE           => $type
124
        );
125
126
        // load and return the EAV attribute option with the passed parameters
127
        $this->attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndTypeStmt->execute($params);
128
        return $this->attributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndTypeStmt->fetch(\PDO::FETCH_ASSOC);
129
    }
130
131
    /**
132
     * Returns the EAV attribute option of attribute with the passed ID with the highest sort order.
133
     *
134
     * @param integer $attributeId The ID of the attribute to return the EAV option with the highest sort order for
135
     *
136
     * @return array|null The EAV attribute option with the highest sort order
137
     */
138
    public function findOneByAttributeIdAndHighestSortOrder($attributeId)
139
    {
140
141
        // load and return the EAV attribute option with the passed parameters
142
        $this->attributeOptionByAttributeIdOrderBySortOrderDescStmt->execute(array(MemberNames::ATTRIBUTE_ID => $attributeId));
143
        return $this->attributeOptionByAttributeIdOrderBySortOrderDescStmt->fetch(\PDO::FETCH_ASSOC);
144
    }
145
}
146