Failed Conditions
Push — master ( 999028...ace778 )
by
unknown
37:54
created

createSspInquiryFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
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 SprykerFeature\Zed\SelfServicePortal\Persistence;
9
10
use Generated\Shared\Transfer\FileAttachmentCollectionDeleteCriteriaTransfer;
11
use Generated\Shared\Transfer\FileAttachmentTransfer;
12
use Generated\Shared\Transfer\FileCollectionTransfer;
13
use Generated\Shared\Transfer\SalesOrderItemSspAssetTransfer;
14
use Generated\Shared\Transfer\SspAssetTransfer;
15
use Generated\Shared\Transfer\SspInquiryTransfer;
16
use LogicException;
17
use Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery;
18
use Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery;
19
use Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery;
20
use Orm\Zed\SelfServicePortal\Persistence\SpyProductAbstractToProductAbstractType;
21
use Orm\Zed\SelfServicePortal\Persistence\SpySalesOrderItemSspAsset;
22
use Orm\Zed\SelfServicePortal\Persistence\SpySspAsset;
23
use Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFileQuery;
24
use Orm\Zed\SelfServicePortal\Persistence\SpySspAssetToCompanyBusinessUnit;
25
use Orm\Zed\SelfServicePortal\Persistence\SpySspAssetToCompanyBusinessUnitQuery;
26
use Orm\Zed\SelfServicePortal\Persistence\SpySspInquiry;
27
use Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryFile;
28
use Orm\Zed\SelfServicePortal\Persistence\SpySspInquirySalesOrder;
29
use Orm\Zed\SelfServicePortal\Persistence\SpySspInquirySspAsset;
30
use Propel\Runtime\Exception\InvalidArgumentException;
31
use Spryker\Zed\Kernel\Persistence\AbstractEntityManager;
32
33
/**
34
 * @method \SprykerFeature\Zed\SelfServicePortal\Persistence\SelfServicePortalPersistenceFactory getFactory()
35
 */
36
class SelfServicePortalEntityManager extends AbstractEntityManager implements SelfServicePortalEntityManagerInterface
37
{
38
    /**
39
     * @param int $idProductConcrete
40
     * @param int $idShipmentType
41
     *
42
     * @return void
43
     */
44
    public function createProductShipmentType(int $idProductConcrete, int $idShipmentType): void
45
    {
46
        $productShipmentTypeEntity = $this->getFactory()
47
            ->createProductShipmentTypeQuery()
48
            ->filterByFkProduct($idProductConcrete)
49
            ->filterByFkShipmentType($idShipmentType)
50
            ->findOneOrCreate();
51
52
        $productShipmentTypeEntity->save();
53
    }
54
55
    /**
56
     * @param int $idProductConcrete
57
     * @param list<int> $shipmentTypeIds
58
     *
59
     * @return void
60
     */
61
    public function deleteProductShipmentTypesByIdProductConcreteAndShipmentTypeIds(
62
        int $idProductConcrete,
63
        array $shipmentTypeIds
64
    ): void {
65
        $this->getFactory()
66
            ->createProductShipmentTypeQuery()
67
            ->filterByFkProduct($idProductConcrete)
68
            ->filterByFkShipmentType_In($shipmentTypeIds)
69
            ->delete();
70
    }
71
72
    /**
73
     * @param int $idProductAbstract
74
     * @param array<int> $productAbstractTypeIds
75
     *
76
     * @return void
77
     */
78
    public function updateProductAbstractTypesForProductAbstract(int $idProductAbstract, array $productAbstractTypeIds): void
79
    {
80
        $this->deleteProductAbstractTypesByProductAbstractId($idProductAbstract);
81
82
        foreach ($productAbstractTypeIds as $idProductAbstractType) {
83
            $productAbstractToProductAbstractTypeEntity = new SpyProductAbstractToProductAbstractType();
84
            $productAbstractToProductAbstractTypeEntity
85
                ->setFkProductAbstract($idProductAbstract)
86
                ->setFkProductAbstractType($idProductAbstractType)
87
                ->save();
88
        }
89
    }
90
91
    /**
92
     * @param int $idProductAbstract
93
     *
94
     * @return void
95
     */
96
    public function deleteProductAbstractTypesByProductAbstractId(int $idProductAbstract): void
97
    {
98
        /**
99
         * @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpyProductAbstractToProductAbstractType> $productAbstractTypesProductAbstractRelations
100
         */
101
        $productAbstractTypesProductAbstractRelations = $this->getFactory()
102
            ->createProductAbstractToProductAbstractTypeQuery()
103
            ->filterByFkProductAbstract($idProductAbstract)
104
            ->find();
105
106
        $productAbstractTypesProductAbstractRelations->delete();
107
    }
108
109
    /**
110
     * @param int $idSalesOrderItem
111
     * @param string $productTypeName
112
     *
113
     * @return void
114
     */
115
    public function saveSalesOrderItemProductType(int $idSalesOrderItem, string $productTypeName): void
116
    {
117
        $salesProductAbstractTypeEntity = $this->getFactory()
118
            ->createSalesProductAbstractTypeQuery()
119
            ->filterByName($productTypeName)
120
            ->findOneOrCreate();
121
122
        if ($salesProductAbstractTypeEntity->isNew()) {
123
            $salesProductAbstractTypeEntity->save();
124
        }
125
126
        $salesOrderItemProductAbstractTypeEntity = $this->getFactory()
127
            ->createSalesOrderItemProductAbstractTypeQuery()
128
            ->filterByFkSalesOrderItem($idSalesOrderItem)
129
            ->filterByFkSalesProductAbstractType($salesProductAbstractTypeEntity->getIdSalesProductAbstractType())
130
            ->findOneOrCreate();
131
132
        if ($salesOrderItemProductAbstractTypeEntity->isNew()) {
133
            $salesOrderItemProductAbstractTypeEntity->save();
134
        }
135
    }
136
137
    /**
138
     * @param int $idSalesOrderItem
139
     * @param bool $isServiceDateTimeEnabled
140
     *
141
     * @return void
142
     */
143
    public function saveIsServiceDateTimeEnabledForSalesOrderItem(int $idSalesOrderItem, bool $isServiceDateTimeEnabled): void
144
    {
145
        $salesOrderItemEntity = $this->getFactory()
146
            ->getSalesOrderItemPropelQuery()
147
            ->filterByIdSalesOrderItem($idSalesOrderItem)
148
            ->findOne();
149
150
        if ($salesOrderItemEntity) {
151
            $salesOrderItemEntity->setIsServiceDateTimeEnabled($isServiceDateTimeEnabled);
152
            $salesOrderItemEntity->save();
153
        }
154
    }
155
156
    /**
157
     * @param \Generated\Shared\Transfer\FileAttachmentCollectionDeleteCriteriaTransfer $fileAttachmentCollectionDeleteCriteriaTransfer
158
     *
159
     * @throws \LogicException
160
     *
161
     * @return void
162
     */
163
    public function deleteFileAttachmentCollection(
164
        FileAttachmentCollectionDeleteCriteriaTransfer $fileAttachmentCollectionDeleteCriteriaTransfer
165
    ): void {
166
        /** @var list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery> $fileAttachmentQueryList */
167
        $fileAttachmentQueryList = $this->getFactory()->getFileAttachmentQueryList();
168
        $isUnconditionalDeletion = true;
169
170
        if ($fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyIds() !== []) {
171
            $isUnconditionalDeletion = false;
172
            $fileAttachmentQueryList = $this->applyFileAttachmentByCompanyIdsCondition($fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyIds());
0 ignored issues
show
Bug introduced by
$fileAttachmentQueryList of type SprykerFeature\Zed\SelfS...Portal\Persistence\list is incompatible with the type array expected by parameter $fileAttachmentQueryList of SprykerFeature\Zed\SelfS...ByCompanyIdsCondition(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

172
            $fileAttachmentQueryList = $this->applyFileAttachmentByCompanyIdsCondition(/** @scrutinizer ignore-type */ $fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyIds());
Loading history...
173
        }
174
175
        if ($fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyUserIds() !== []) {
176
            $isUnconditionalDeletion = false;
177
            $fileAttachmentQueryList = $this->applyFileAttachmentByCompanyUserIdsCondition($fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyUserIds());
0 ignored issues
show
Bug introduced by
It seems like $fileAttachmentQueryList can also be of type SprykerFeature\Zed\SelfS...Portal\Persistence\list; however, parameter $fileAttachmentQueryList of SprykerFeature\Zed\SelfS...mpanyUserIdsCondition() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

177
            $fileAttachmentQueryList = $this->applyFileAttachmentByCompanyUserIdsCondition(/** @scrutinizer ignore-type */ $fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyUserIds());
Loading history...
178
        }
179
180
        if ($fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyBusinessUnitIds() !== []) {
181
            $isUnconditionalDeletion = false;
182
            $fileAttachmentQueryList = $this->applyFileAttachmentByCompanyBusinessUnitIdsCondition($fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyBusinessUnitIds());
0 ignored issues
show
Bug introduced by
It seems like $fileAttachmentQueryList can also be of type SprykerFeature\Zed\SelfS...Portal\Persistence\list; however, parameter $fileAttachmentQueryList of SprykerFeature\Zed\SelfS...inessUnitIdsCondition() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

182
            $fileAttachmentQueryList = $this->applyFileAttachmentByCompanyBusinessUnitIdsCondition(/** @scrutinizer ignore-type */ $fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getCompanyBusinessUnitIds());
Loading history...
183
        }
184
185
        if ($fileAttachmentCollectionDeleteCriteriaTransfer->getSspAssetIds() !== []) {
186
            $isUnconditionalDeletion = false;
187
            $fileAttachmentQueryList = $this->applyFileAttachmentByAssetIdsCondition($fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getSspAssetIds());
0 ignored issues
show
Bug introduced by
It seems like $fileAttachmentQueryList can also be of type SprykerFeature\Zed\SelfS...Portal\Persistence\list; however, parameter $fileAttachmentQueryList of SprykerFeature\Zed\SelfS...ntByAssetIdsCondition() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

187
            $fileAttachmentQueryList = $this->applyFileAttachmentByAssetIdsCondition(/** @scrutinizer ignore-type */ $fileAttachmentQueryList, $fileAttachmentCollectionDeleteCriteriaTransfer->getSspAssetIds());
Loading history...
188
        }
189
190
        if ($fileAttachmentCollectionDeleteCriteriaTransfer->getFileIds() !== []) {
191
            $isUnconditionalDeletion = false;
192
            $fileAttachmentQueryList = $this->applyFileAttachmentByFileIdsCondition(
193
                $fileAttachmentQueryList,
0 ignored issues
show
Bug introduced by
It seems like $fileAttachmentQueryList can also be of type SprykerFeature\Zed\SelfS...Portal\Persistence\list; however, parameter $fileAttachmentQueryList of SprykerFeature\Zed\SelfS...entByFileIdsCondition() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

193
                /** @scrutinizer ignore-type */ $fileAttachmentQueryList,
Loading history...
194
                $fileAttachmentCollectionDeleteCriteriaTransfer->getFileIds(),
195
                count($fileAttachmentCollectionDeleteCriteriaTransfer->modifiedToArray()) > 1,
196
            );
197
        }
198
199
        if ($isUnconditionalDeletion && !$fileAttachmentCollectionDeleteCriteriaTransfer->getIsUnconditionalDeletionAllowed()) {
200
            throw new LogicException('Unconditional deletion is not allowed.');
201
        }
202
203
        $this->deleteFileAttachments($fileAttachmentQueryList);
0 ignored issues
show
Bug introduced by
It seems like $fileAttachmentQueryList can also be of type SprykerFeature\Zed\SelfS...Portal\Persistence\list; however, parameter $fileAttachmentQueryList of SprykerFeature\Zed\SelfS...deleteFileAttachments() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

203
        $this->deleteFileAttachments(/** @scrutinizer ignore-type */ $fileAttachmentQueryList);
Loading history...
204
    }
205
206
    /**
207
     * @param list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFileQuery> $fileAttachmentQueryList
208
     * @param list<int> $fileIds
209
     * @param bool $applyOnlyToModifiedQueries
210
     *
211
     * @return list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFileQuery>
212
     */
213
    protected function applyFileAttachmentByFileIdsCondition(
214
        array $fileAttachmentQueryList,
215
        array $fileIds,
216
        bool $applyOnlyToModifiedQueries
217
    ): array {
218
        foreach ($fileAttachmentQueryList as $fileAttachmentQuery) {
219
            if ($applyOnlyToModifiedQueries && !$fileAttachmentQuery->hasWhereClause()) {
220
                continue;
221
            }
222
223
            $fileAttachmentQuery->filterByFkFile_In($fileIds);
224
        }
225
226
        return $fileAttachmentQueryList;
227
    }
228
229
    /**
230
     * @param list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery> $fileAttachmentQueryList
231
     * @param list<int> $companyIds
232
     *
233
     * @return list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery>
234
     */
235
    protected function applyFileAttachmentByCompanyIdsCondition(
236
        array $fileAttachmentQueryList,
237
        array $companyIds
238
    ): array {
239
        foreach ($fileAttachmentQueryList as $fileAttachmentQuery) {
240
            if ($fileAttachmentQuery instanceof SpyCompanyFileQuery) {
241
                $fileAttachmentQuery->filterByFkCompany_In($companyIds);
242
            }
243
        }
244
245
        return $fileAttachmentQueryList;
246
    }
247
248
    /**
249
     * @param list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery> $fileAttachmentQueryList
250
     * @param list<int> $companyUserIds
251
     *
252
     * @return list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery>
253
     */
254
    protected function applyFileAttachmentByCompanyUserIdsCondition(
255
        array $fileAttachmentQueryList,
256
        array $companyUserIds
257
    ): array {
258
        foreach ($fileAttachmentQueryList as $fileAttachmentQuery) {
259
            if ($fileAttachmentQuery instanceof SpyCompanyUserFileQuery) {
260
                $fileAttachmentQuery->filterByFkCompanyUser_In($companyUserIds);
261
            }
262
        }
263
264
        return $fileAttachmentQueryList;
265
    }
266
267
    /**
268
     * @param list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery> $fileAttachmentQueryList
269
     * @param list<int> $companyBusinessUnitIds
270
     *
271
     * @return list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery>
272
     */
273
    protected function applyFileAttachmentByCompanyBusinessUnitIdsCondition(
274
        array $fileAttachmentQueryList,
275
        array $companyBusinessUnitIds
276
    ): array {
277
        foreach ($fileAttachmentQueryList as $fileAttachmentQuery) {
278
            if ($fileAttachmentQuery instanceof SpyCompanyBusinessUnitFileQuery) {
279
                $fileAttachmentQuery->filterByFkCompanyBusinessUnit_In($companyBusinessUnitIds);
280
            }
281
        }
282
283
        return $fileAttachmentQueryList;
284
    }
285
286
    /**
287
     * @param list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFileQuery> $fileAttachmentQueryList
288
     * @param list<int> $assetIds
289
     *
290
     * @return list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFileQuery>
291
     */
292
    protected function applyFileAttachmentByAssetIdsCondition(
293
        array $fileAttachmentQueryList,
294
        array $assetIds
295
    ): array {
296
        foreach ($fileAttachmentQueryList as $fileAttachmentQuery) {
297
            if ($fileAttachmentQuery instanceof SpySspAssetFileQuery) {
298
                $fileAttachmentQuery->filterByFkSspAsset_In($assetIds);
299
            }
300
        }
301
302
        return $fileAttachmentQueryList;
303
    }
304
305
    /**
306
     * @param list<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery|\Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFileQuery> $fileAttachmentQueryList
307
     *
308
     * @return void
309
     */
310
    protected function deleteFileAttachments(array $fileAttachmentQueryList): void
311
    {
312
        foreach ($fileAttachmentQueryList as $fileAttachmentQuery) {
313
            if (!$fileAttachmentQuery->hasWhereClause()) {
314
                continue;
315
            }
316
317
            $fileAttachmentQuery->delete();
318
        }
319
    }
320
321
    /**
322
     * @param \Generated\Shared\Transfer\FileAttachmentTransfer $fileAttachmentTransfer
323
     *
324
     * @throws \LogicException
325
     *
326
     * @return \Generated\Shared\Transfer\FileAttachmentTransfer
327
     */
328
    public function saveFileAttachment(FileAttachmentTransfer $fileAttachmentTransfer): FileAttachmentTransfer
329
    {
330
        $fileAttachmentSaver = null;
331
332
        foreach ($this->getFactory()->createFileAttachmentSavers() as $fileAttachmentSaverOption) {
333
            if ($fileAttachmentSaverOption->isApplicable($fileAttachmentTransfer)) {
334
                $fileAttachmentSaver = $fileAttachmentSaverOption;
335
            }
336
        }
337
338
        if (!$fileAttachmentSaver) {
339
            throw new LogicException(sprintf('Saver for entity "%s" is not implemented.', $fileAttachmentTransfer->getEntityName()));
340
        }
341
342
        return $fileAttachmentSaver->save($fileAttachmentTransfer);
343
    }
344
345
    /**
346
     * @param \Generated\Shared\Transfer\SspInquiryTransfer $sspInquiryTransfer
347
     *
348
     * @return \Generated\Shared\Transfer\SspInquiryTransfer
349
     */
350
    public function createSspInquiry(SspInquiryTransfer $sspInquiryTransfer): SspInquiryTransfer
351
    {
352
        return $this->saveSspInquiry($sspInquiryTransfer, new SpySspInquiry());
353
    }
354
355
    /**
356
     * @param \Generated\Shared\Transfer\SspInquiryTransfer $sspInquiryTransfer
357
     *
358
     * @return \Generated\Shared\Transfer\SspInquiryTransfer|null
359
     */
360
    public function updateSspInquiry(SspInquiryTransfer $sspInquiryTransfer): ?SspInquiryTransfer
361
    {
362
        $sspInquiryQuery = $this->getFactory()->createSspInquiryQuery();
363
364
        $sspInquiryEntity = $sspInquiryQuery->filterByIdSspInquiry($sspInquiryTransfer->getIdSspInquiry())->findOne();
365
366
        if (!$sspInquiryEntity) {
367
            return null;
368
        }
369
370
        return $this->saveSspInquiry($sspInquiryTransfer, $sspInquiryEntity);
371
    }
372
373
    /**
374
     * @param \Generated\Shared\Transfer\SspInquiryTransfer $sspInquiryTransfer
375
     * @param \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiry $sspInquiryEntity
376
     *
377
     * @return \Generated\Shared\Transfer\SspInquiryTransfer
378
     */
379
    protected function saveSspInquiry(SspInquiryTransfer $sspInquiryTransfer, SpySspInquiry $sspInquiryEntity): SspInquiryTransfer
380
    {
381
        $sspInquiryEntity = $this->getFactory()->createSspInquiryMapper()->mapSspInquiryTransferToSspInquiryEntity($sspInquiryTransfer, $sspInquiryEntity);
382
383
        if ($sspInquiryTransfer->getStatus()) {
384
            $stateMachineItemState = $this->getFactory()->getStateMachineItemStatePropelQuery()->findOneByName($sspInquiryTransfer->getStatus());
385
            if ($stateMachineItemState) {
386
                $sspInquiryEntity->setFkStateMachineItemState($stateMachineItemState->getIdStateMachineItemState());
387
            }
388
        }
389
390
        if ($sspInquiryEntity->isNew() || $sspInquiryEntity->isModified()) {
391
            $sspInquiryEntity->save();
392
        }
393
394
        $sspInquiryTransfer = $this->getFactory()->createSspInquiryMapper()->mapSspInquiryEntityToSspInquiryTransfer($sspInquiryEntity, $sspInquiryTransfer);
395
396
        return $sspInquiryTransfer;
397
    }
398
399
    /**
400
     * @param \Generated\Shared\Transfer\SspInquiryTransfer $sspInquiryTransfer
401
     *
402
     * @return \Generated\Shared\Transfer\SspInquiryTransfer
403
     */
404
    public function createSspInquiryFiles(SspInquiryTransfer $sspInquiryTransfer): SspInquiryTransfer
405
    {
406
        foreach ($sspInquiryTransfer->getFiles() as $fileTransfer) {
407
            $sspInquiryFileEntity = (new SpySspInquiryFile())
408
                ->setFkFile($fileTransfer->getIdFileOrFail())
409
                ->setFkSspInquiry($sspInquiryTransfer->getIdSspInquiryOrFail());
410
411
            $sspInquiryFileEntity->save();
412
        }
413
414
        return $sspInquiryTransfer;
415
    }
416
417
    /**
418
     * @param \Generated\Shared\Transfer\SspInquiryTransfer $sspInquiryTransfer
419
     *
420
     * @return \Generated\Shared\Transfer\SspInquiryTransfer
421
     */
422
    public function createSspInquirySalesOrder(SspInquiryTransfer $sspInquiryTransfer): SspInquiryTransfer
423
    {
424
        $sspInquirySalesOrderEntity = (new SpySspInquirySalesOrder())
425
            ->setFkSspInquiry($sspInquiryTransfer->getIdSspInquiryOrFail())
426
            ->setFkSalesOrder($sspInquiryTransfer->getOrderOrFail()->getIdSalesOrderOrFail());
427
428
        $sspInquirySalesOrderEntity->save();
429
430
        return $sspInquiryTransfer;
431
    }
432
433
    /**
434
     * @param \Generated\Shared\Transfer\SspInquiryTransfer $sspInquiryTransfer
435
     *
436
     * @return \Generated\Shared\Transfer\SspInquiryTransfer
437
     */
438
    public function createSspInquirySspAsset(SspInquiryTransfer $sspInquiryTransfer): SspInquiryTransfer
439
    {
440
        $sspInquirySspAssetEntity = (new SpySspInquirySspAsset())
441
            ->setFkSspInquiry($sspInquiryTransfer->getIdSspInquiryOrFail())
442
            ->setFkSspAsset($sspInquiryTransfer->getSspAssetOrFail()->getIdSspAssetOrFail());
443
444
        $sspInquirySspAssetEntity->save();
445
446
        return $sspInquiryTransfer;
447
    }
448
449
    /**
450
     * @param \Generated\Shared\Transfer\FileCollectionTransfer $fileCollectionTransfer
451
     *
452
     * @return void
453
     */
454
    public function deleteSspInquiryFileRelation(FileCollectionTransfer $fileCollectionTransfer): void
455
    {
456
        $fileIds = [];
457
458
        foreach ($fileCollectionTransfer->getFiles() as $fileTransfer) {
459
            $fileIds[] = $fileTransfer->getIdFileOrFail();
460
        }
461
462
        if (!$fileIds) {
463
            return;
464
        }
465
466
        $this->getFactory()->createSspInquiryFileQuery()->filterByFkFile_In($fileIds)->delete();
467
    }
468
469
    /**
470
     * @param \Generated\Shared\Transfer\SspAssetTransfer $sspAssetTransfer
471
     *
472
     * @return \Generated\Shared\Transfer\SspAssetTransfer
473
     */
474
    public function createSspAsset(SspAssetTransfer $sspAssetTransfer): SspAssetTransfer
475
    {
476
        $spySspAssetEntity = $this->getFactory()
477
            ->createAssetMapper()
478
            ->mapSspAssetTransferToSpySspAssetEntity($sspAssetTransfer, new SpySspAsset());
479
480
        $spySspAssetEntity->save();
481
        $sspAssetTransfer->setIdSspAsset($spySspAssetEntity->getIdSspAsset());
482
483
        return $this->getFactory()
484
            ->createAssetMapper()
485
            ->mapSpySspAssetEntityToSspAssetTransfer($spySspAssetEntity, $sspAssetTransfer);
486
    }
487
488
    /**
489
     * @param \Generated\Shared\Transfer\SspAssetTransfer $sspAssetTransfer
490
     *
491
     * @throws \Propel\Runtime\Exception\InvalidArgumentException
492
     *
493
     * @return \Generated\Shared\Transfer\SspAssetTransfer
494
     */
495
    public function updateSspAsset(SspAssetTransfer $sspAssetTransfer): SspAssetTransfer
496
    {
497
        $spySspAssetEntity = $this->getFactory()
498
            ->createSspAssetQuery()
499
            ->findOneByIdSspAsset($sspAssetTransfer->getIdSspAssetOrFail());
500
501
        if (!$spySspAssetEntity) {
502
            throw new InvalidArgumentException('Ssp Asset not found');
503
        }
504
505
        $spySspAssetEntity = $this->getFactory()
506
            ->createAssetMapper()
507
            ->mapSspAssetTransferToSpySspAssetEntity($sspAssetTransfer, $spySspAssetEntity);
508
509
        if ($spySspAssetEntity->isModified()) {
510
            $spySspAssetEntity->save();
511
        }
512
513
        return $this->getFactory()
514
            ->createAssetMapper()
515
            ->mapSpySspAssetEntityToSspAssetTransfer($spySspAssetEntity, $sspAssetTransfer);
516
    }
517
518
    /**
519
     * @param \Generated\Shared\Transfer\SalesOrderItemSspAssetTransfer $salesOrderItemSspAssetTransfer
520
     *
521
     * @return void
522
     */
523
    public function createSalesOrderItemSspAsset(SalesOrderItemSspAssetTransfer $salesOrderItemSspAssetTransfer): void
524
    {
525
        $salesOrderItemSspAssetEntity = new SpySalesOrderItemSspAsset();
526
        $salesOrderItemSspAssetEntity->fromArray($salesOrderItemSspAssetTransfer->toArray());
527
        $salesOrderItemSspAssetEntity->setFkSalesOrderItem($salesOrderItemSspAssetTransfer->getSalesOrderItemOrFail()->getIdSalesOrderItemOrFail());
528
        $salesOrderItemSspAssetEntity->save();
529
    }
530
531
    /**
532
     * @param int $idSspAsset
533
     * @param array<int> $businessUnitIds
534
     *
535
     * @return void
536
     */
537
    public function deleteAssetToCompanyBusinessUnitRelations(int $idSspAsset, array $businessUnitIds): void
538
    {
539
        SpySspAssetToCompanyBusinessUnitQuery::create()
540
            ->filterByFkSspAsset($idSspAsset)
541
            ->filterByFkCompanyBusinessUnit_In($businessUnitIds)
542
            ->delete();
543
    }
544
545
    /**
546
     * @param int $idSspAsset
547
     * @param array<int> $businessUnitIds
548
     *
549
     * @return void
550
     */
551
    public function createAssetToCompanyBusinessUnitRelation(int $idSspAsset, array $businessUnitIds): void
552
    {
553
        foreach ($businessUnitIds as $businessUnitId) {
554
            $spySspAssetToCompanyBusinessUnit = new SpySspAssetToCompanyBusinessUnit();
555
            $spySspAssetToCompanyBusinessUnit
556
                ->setFkSspAsset($idSspAsset)
557
                ->setFkCompanyBusinessUnit($businessUnitId)
558
                ->save();
559
        }
560
    }
561
562
    /**
563
     * @param array<int> $salesOrderItemIds
564
     *
565
     * @return void
566
     */
567
    public function deleteSalesOrderItemProductAbstractTypesBySalesOrderItemIds(array $salesOrderItemIds): void
568
    {
569
        if (!$salesOrderItemIds) {
570
            return;
571
        }
572
573
        /**
574
         * @var \Propel\Runtime\Collection\ObjectCollection $salesOrderItemProductAbstractTypeEntityCollection
575
         */
576
        $salesOrderItemProductAbstractTypeEntityCollection = $this->getFactory()
577
            ->createSalesOrderItemProductAbstractTypeQuery()
578
            ->filterByFkSalesOrderItem_In($salesOrderItemIds)
579
            ->find();
580
581
        $salesOrderItemProductAbstractTypeEntityCollection->delete();
582
    }
583
}
584