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\CommentMerchantRelationRequestConnector\Business\Expander; |
||
9 | |||
10 | use Generated\Shared\Transfer\MerchantRelationRequestCollectionTransfer; |
||
11 | use Spryker\Zed\CommentMerchantRelationRequestConnector\Business\Reader\CommentReaderInterface; |
||
12 | use Spryker\Zed\CommentMerchantRelationRequestConnector\CommentMerchantRelationRequestConnectorConfig; |
||
13 | |||
14 | class CommentThreadExpander implements CommentThreadExpanderInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var \Spryker\Zed\CommentMerchantRelationRequestConnector\Business\Reader\CommentReaderInterface |
||
18 | */ |
||
19 | protected CommentReaderInterface $commentReader; |
||
20 | |||
21 | /** |
||
22 | * @param \Spryker\Zed\CommentMerchantRelationRequestConnector\Business\Reader\CommentReaderInterface $commentReader |
||
23 | */ |
||
24 | public function __construct(CommentReaderInterface $commentReader) |
||
25 | { |
||
26 | $this->commentReader = $commentReader; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param \Generated\Shared\Transfer\MerchantRelationRequestCollectionTransfer $merchantRelationRequestCollectionTransfer |
||
31 | * |
||
32 | * @return \Generated\Shared\Transfer\MerchantRelationRequestCollectionTransfer |
||
33 | */ |
||
34 | public function expandMerchantRelationRequestCollection( |
||
35 | MerchantRelationRequestCollectionTransfer $merchantRelationRequestCollectionTransfer |
||
36 | ): MerchantRelationRequestCollectionTransfer { |
||
37 | $indexedCommentThreadTransfers = $this->commentReader->getCommentThreadsIndexedByOwnerId( |
||
38 | CommentMerchantRelationRequestConnectorConfig::COMMENT_THREAD_MERCHANT_RELATION_REQUEST_OWNER_TYPE, |
||
39 | $this->extractMerchantRelationRequestIds($merchantRelationRequestCollectionTransfer), |
||
40 | ); |
||
41 | |||
42 | foreach ($merchantRelationRequestCollectionTransfer->getMerchantRelationRequests() as $merchantRelationRequestTransfer) { |
||
43 | $idMerchantRelationRequest = $merchantRelationRequestTransfer->getIdMerchantRelationRequestOrFail(); |
||
44 | $commentThreadTransfer = $indexedCommentThreadTransfers[$idMerchantRelationRequest] ?? null; |
||
45 | |||
46 | if ($commentThreadTransfer) { |
||
47 | $merchantRelationRequestTransfer->setCommentThread($commentThreadTransfer); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | return $merchantRelationRequestCollectionTransfer; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param \Generated\Shared\Transfer\MerchantRelationRequestCollectionTransfer $merchantRelationRequestCollectionTransfer |
||
56 | * |
||
57 | * @return list<int> |
||
58 | */ |
||
59 | protected function extractMerchantRelationRequestIds( |
||
60 | MerchantRelationRequestCollectionTransfer $merchantRelationRequestCollectionTransfer |
||
61 | ): array { |
||
62 | $merchantRelationRequestIds = []; |
||
63 | foreach ($merchantRelationRequestCollectionTransfer->getMerchantRelationRequests() as $merchantRelationRequestTransfer) { |
||
64 | $merchantRelationRequestIds[] = $merchantRelationRequestTransfer->getIdMerchantRelationRequestOrFail(); |
||
65 | } |
||
66 | |||
67 | return array_unique($merchantRelationRequestIds); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
68 | } |
||
69 | } |
||
70 |