Failed Conditions
Push — master ( ae631c...a04781 )
by
unknown
52:50 queued 12:37
created

getProductAbstractIdTimestampMap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 1
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Zed\ProductLabelSearch\Persistence;
9
10
use Orm\Zed\ProductLabel\Persistence\Map\SpyProductLabelProductAbstractTableMap;
11
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
12
13
/**
14
 * @method \Spryker\Zed\ProductLabelSearch\Persistence\ProductLabelSearchPersistenceFactory getFactory()
15
 */
16
class ProductLabelSearchRepository extends AbstractRepository implements ProductLabelSearchRepositoryInterface
17
{
18
    /**
19
     * @param array<int> $productAbstractIds
20
     *
21
     * @return array<\Generated\Shared\Transfer\SpyProductLabelEntityTransfer>
22
     */
23
    public function getProductLabelsByIdProductAbstractIn(array $productAbstractIds): array
24
    {
25
        $query = $this->getFactory()
26
            ->getPropelProductLabelQuery()
27
            ->filterByIsActive(true)
28
            ->innerJoinWithSpyProductLabelProductAbstract()
29
            ->useSpyProductLabelProductAbstractQuery()
30
                ->filterByFkProductAbstract_In($productAbstractIds)
31
            ->endUse();
32
33
        return $this->buildQueryFromCriteria($query)->find();
34
    }
35
36
    /**
37
     * @param array<int> $productLabelIds
38
     *
39
     * @return array<int>
40
     */
41
    public function getProductAbstractIdsByProductLabelIds(array $productLabelIds): array
42
    {
43
        $productAbstractIds = $this->getFactory()
44
            ->createSpyProductLabelProductAbstractQuery()
45
            ->filterByFkProductLabel_In($productLabelIds)
46
            ->select(SpyProductLabelProductAbstractTableMap::COL_FK_PRODUCT_ABSTRACT)
47
            ->find()
48
            ->getData();
49
50
        return array_unique($productAbstractIds);
51
    }
52
53
    /**
54
     * @param array<int, int> $productLabelIdsTimestampMap
55
     *
56
     * @return array<int, int>
57
     */
58
    public function getProductAbstractIdTimestampMap(array $productLabelIdsTimestampMap): array
59
    {
60
        $productAbstractIdTimestampMap = [];
61
62
        $productLabelData = $this->getFactory()
63
            ->createSpyProductLabelProductAbstractQuery()
64
            ->filterByFkProductLabel_In(array_keys($productLabelIdsTimestampMap))
65
            ->select([SpyProductLabelProductAbstractTableMap::COL_FK_PRODUCT_ABSTRACT, SpyProductLabelProductAbstractTableMap::COL_FK_PRODUCT_LABEL])
66
            ->find()
67
            ->getData();
68
69
        foreach ($productLabelData as $productLabel) {
70
            $productAbstractIdTimestampMap[(int)$productLabel[SpyProductLabelProductAbstractTableMap::COL_FK_PRODUCT_ABSTRACT]] =
71
                $productLabelIdsTimestampMap[$productLabel[SpyProductLabelProductAbstractTableMap::COL_FK_PRODUCT_LABEL]];
72
        }
73
74
        return $productAbstractIdTimestampMap;
75
    }
76
}
77