Completed
Pull Request — master (#24)
by
unknown
02:12
created

findOneByOptionIdAndStoreId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository
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\Repositories\AbstractRepository;
25
26
/**
27
 * Repository implementation to load EAV attribute option swatch data.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-attribute
33
 * @link      http://www.techdivision.com
34
 */
35
class AttributeOptionSwatchRepository extends AbstractRepository
36
{
37
38
    /**
39
     * The prepared statement to load an existing EAV attribute option swatch by its attribute code, store ID. value and type.
40
     *
41
     * @var \PDOStatement
42
     */
43
    protected $attributeOptionSwatchByAttributeCodeAndStoreIdAndValueAndTypeStmt;
44
45
    /**
46
     * The prepared statement to load an existing EAV attribute option swatch by its option ID and store ID
47
     *
48
     * @var \PDOStatement
49
     */
50
    protected $attributeOptionSwatchByOptionIdAndStoreIdStmt;
51
52
    /**
53
     * Initializes the repository's prepared statements.
54
     *
55
     * @return void
56
     */
57
    public function init()
58
    {
59
60
        // load the utility class name
61
        $utilityClassName = $this->getUtilityClassName();
62
63
        // initialize the prepared statements
64
        $this->attributeOptionSwatchByAttributeCodeAndStoreIdAndValueAndTypeStmt =
65
            $this->getConnection()->prepare($this->getUtilityClass()->find($utilityClassName::ATTRIBUTE_OPTION_SWATCH_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE_AND_TYPE));
66
67
        $this->attributeOptionSwatchByOptionIdAndStoreIdStmt =
68
            $this->getConnection()->prepare($this->getUtilityClass()->find($utilityClassName::ATTRIBUTE_OPTION_SWATCH_BY_OPTION_ID_AND_STORE_ID));
69
    }
70
71
    /**
72
     * Load's and return's the EAV attribute option swatch with the passed code, store ID, value and type.
73
     *
74
     * @param string  $attributeCode The code of the EAV attribute option swatch to load
75
     * @param integer $storeId       The store ID of the attribute option swatch to load
76
     * @param string  $value         The value of the attribute option swatch to load
77
     * @param string  $type          The type of the attribute option swatch to load
78
     *
79
     * @return array The EAV attribute option swatch
80
     */
81
    public function findOneByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value, $type)
82
    {
83
84
        // the parameters of the EAV attribute option to load
85
        $params = array(
86
            MemberNames::ATTRIBUTE_CODE => $attributeCode,
87
            MemberNames::STORE_ID       => $storeId,
88
            MemberNames::VALUE          => $value,
89
            MemberNames::TYPE           => $type
90
        );
91
92
        // load and return the EAV attribute option swatch with the passed parameters
93
        $this->attributeOptionSwatchByAttributeCodeAndStoreIdAndValueAndTypeStmt->execute($params);
94
        return $this->attributeOptionSwatchByAttributeCodeAndStoreIdAndValueAndTypeStmt->fetch(\PDO::FETCH_ASSOC);
95
    }
96
97
    /**
98
     * Load's and return's the EAV attribute option swatch with the passed option ID and store ID
99
     *
100
     * @param string  $optionId The option ID of the attribute option swatch to load
101
     * @param integer $storeId  The store ID of the attribute option swatch to load
102
     *
103
     * @return array The EAV attribute option swatch
104
     */
105
    public function findOneByOptionIdAndStoreId($optionId, $storeId)
106
    {
107
108
        // the parameters of the EAV attribute option to load
109
        $params = array(
110
            MemberNames::OPTION_ID => $optionId,
111
            MemberNames::STORE_ID  => $storeId,
112
        );
113
114
        // load and return the EAV attribute option swatch with the passed parameters
115
        $this->attributeOptionSwatchByOptionIdAndStoreIdStmt->execute($params);
116
        return $this->attributeOptionSwatchByOptionIdAndStoreIdStmt->fetch(\PDO::FETCH_ASSOC);
117
    }
118
}
119