Completed
Push — master ( e5b919...026cf7 )
by Tim
05:11
created

loadProductMediaGalleryValueToEntityByValueIdAndRowId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Media\Ee\Observers\EeMediaGalleryUpdateObserver
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-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Media\Ee\Observers;
22
23
use TechDivision\Import\Product\Media\Ee\Utils\MemberNames;
24
25
/**
26
 * Observer that provides extended mapping functionality to map a SKU to a row ID (EE Feature).
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product-media-ee
32
 * @link      http://www.techdivision.com
33
 */
34
class EeMediaGalleryUpdateObserver extends EeMediaGalleryObserver
35
{
36
37
    /**
38
     * Initialize the product media gallery value to entity with the passed attributes and returns an instance.
39
     *
40
     * @param array $attr The product media gallery value to entity attributes
41
     *
42
     * @return array|null The initialized product media gallery value to entity, or NULL if the product media gallery value to entity already exists
43
     */
44
    protected function initializeProductMediaGalleryValueToEntity(array $attr)
45
    {
46
47
        // load the row/value ID
48
        $rowId = $attr[MemberNames::ROW_ID];
49
        $valueId = $attr[MemberNames::VALUE_ID];
50
51
        // query whether the product media gallery value to entity entity already exists or not
52
        if ($this->loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId)) {
53
            return;
54
        }
55
56
        // simply return the attributes
57
        return $attr;
58
    }
59
60
    /**
61
     * Load's the product media gallery with the passed value/entity ID.
62
     *
63
     * @param integer $valueId The value ID of the product media gallery value to entity to load
64
     * @param integer $rowId   The row ID of the product media gallery value to entity to load
65
     *
66
     * @return array The product media gallery
67
     */
68
    protected function loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId)
69
    {
70
        return $this->getSubject()->loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId);
71
    }
72
}
73