Passed
Pull Request — master (#4)
by Tim
04:21
created

EntityAttributeRepository::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Set\Repositories\EntityAttributeRepository
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 2019 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-set
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Set\Repositories;
22
23
use TechDivision\Import\Attribute\Set\Utils\SqlStatementKeys;
24
use TechDivision\Import\Attribute\Set\Utils\MemberNames;
25
26
/**
27
 * Repository implementation to load EAV entity attribute data.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2019 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-set
33
 * @link      http://www.techdivision.com
34
 */
35
class EntityAttributeRepository extends \TechDivision\Import\Attribute\Repositories\EntityAttributeRepository implements EntityAttributeRepositoryInterface
36
{
37
38
    /**
39
     * The prepared statement to load an existing EAV entity attributes for the given attribute group ID.
40
     *
41
     * @var \PDOStatement
42
     */
43
    protected $entityAttributeByAttributeGroupId;
44
45
    /**
46
     * The prepared statement to load an existing EAV entity attributes for the given entity type ID and attribute set name.
47
     *
48
     * @var \PDOStatement
49
     */
50
    protected $entityAttributeByEntityTypeIdAndAttributeSetNameStmt;
51
52
    /**
53
     * Initializes the repository's prepared statements.
54
     *
55
     * @return void
56
     */
57
    public function init()
58
    {
59
60
        // invoke the parent instance
61
        parent::init();
62
63
        // initialize the prepared statements
64
        $this->entityAttributeByAttributeGroupId =
65
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ENTITY_ATTRIBUTES_BY_ATTRIBUTE_GROUP_ID));
66
        $this->entityAttributeByEntityTypeIdAndAttributeSetNameStmt =
67
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ENTITY_ATTRIBUTES_BY_ENTITY_TYPE_ID_AND_ATTRIBUTE_SET_NAME));
68
    }
69
70
    /**
71
     * Returns the EAV entity attributes for the attribute group with the passed ID.
72
     *
73
     * @param integer $attributeGroupId The attribute group ID to load the EAV entity attributes for
74
     *
75
     * @return array|null The EAV attributes with for the passed attribute group ID
76
     */
77
    public function findAllByAttributeGroupId($attributeGroupId)
78
    {
79
80
        // load and return the EAV attribute options with the passed parameters
81
        $this->entityAttributeByAttributeGroupId->execute(array(MemberNames::ATTRIBUTE_GROUP_ID => $attributeGroupId));
82
        return $this->entityAttributeByAttributeGroupId->fetchAll(\PDO::FETCH_ASSOC);
83
    }
84
85
    /**
86
     * Returns the EAV entity attributes for the entity type ID and attribute set with the passed name.
87
     *
88
     * @param integer $entityTypeId     The entity type ID to load the EAV entity attributes for
89
     * @param string  $attributeSetName The attribute set name to return the EAV entity attributes for
90
     *
91
     * @return array|null The EAV attributes with for the passed entity type ID and attribute set name
92
     */
93
    public function findAllByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
94
    {
95
96
        // initialize the params
97
        $params = array(
98
            MemberNames::ENTITY_TYPE_ID     => $entityTypeId,
99
            MemberNames::ATTRIBUTE_SET_NAME => $attributeSetName
100
        );
101
102
        // load and return the EAV attribute options with the passed parameters
103
        $this->entityAttributeByEntityTypeIdAndAttributeSetNameStmt->execute($params);
104
        return $this->entityAttributeByEntityTypeIdAndAttributeSetNameStmt->fetchAll(\PDO::FETCH_ASSOC);
105
    }
106
}
107