Completed
Push — master ( af5cb4...f7d729 )
by Tim
12s
created

findOneByAttributeIdAndValue()   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\Product\Media\Repositories\ProductMediaGalleryRepository
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-media
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Media\Repositories;
22
23
use TechDivision\Import\Product\Media\Utils\MemberNames;
24
use TechDivision\Import\Repositories\AbstractRepository;
25
26
/**
27
 * Repository implementation to load product media gallery 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-product-media
33
 * @link      http://www.techdivision.com
34
 */
35
class ProductMediaGalleryRepository extends AbstractRepository
36
{
37
38
    /**
39
     * The prepared statement to load an existing product media gallery entity.
40
     *
41
     * @var \PDOStatement
42
     */
43
    protected $productMediaGalleryStmt;
44
45
    /**
46
     * The prepared statement to load the existing product media gallery entities by the given SKU.
47
     *
48
     * @var \PDOStatement
49
     */
50
    protected $productMediaGalleriesBySkuStmt;
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->productMediaGalleryStmt =
65
            $this->getConnection()->prepare($this->getUtilityClass()->find($utilityClassName::PRODUCT_MEDIA_GALLERY));
66
        $this->productMediaGalleriesBySkuStmt =
67
            $this->getConnection()->prepare($this->getUtilityClass()->find($utilityClassName::PRODUCT_MEDIA_GALLERIES_BY_SKU));
68
    }
69
70
    /**
71
     * Load's the product media gallery with the passed attribute ID + value.
72
     *
73
     * @param integer $attributeId The attribute ID of the product media gallery to load
74
     * @param string  $value       The value of the product media gallery to load
75
     *
76
     * @return array The product media gallery
77
     */
78
    public function findOneByAttributeIdAndValue($attributeId, $value)
79
    {
80
81
        // initialize the params
82
        $params = array(
83
            MemberNames::ATTRIBUTE_ID => $attributeId,
84
            MemberNames::VALUE        => $value
85
        );
86
87
        // load and return the prodcut media gallery with the passed attribute ID + value
88
        $this->productMediaGalleryStmt->execute($params);
89
        return $this->productMediaGalleryStmt->fetch(\PDO::FETCH_ASSOC);
90
    }
91
92
    /**
93
     * Load's the product media gallery entities with the passed SKU.
94
     *
95
     * @param string $sku The SKU to load the media gallery entities for
96
     *
97
     * @return array The product media gallery entities
98
     */
99
    public function findAllBySku($sku)
100
    {
101
102
        // initialize the params
103
        $params = array(MemberNames::SKU => $sku);
104
105
        // load and return the prodcut media gallery entities with the passed SKU
106
        $this->productMediaGalleriesBySkuStmt->execute($params);
107
        return $this->productMediaGalleriesBySkuStmt->fetchAll(\PDO::FETCH_ASSOC);
108
    }
109
}
110