Total Complexity | 133 |
Total Lines | 1326 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like SelfServicePortalRepository often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SelfServicePortalRepository, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
54 | class SelfServicePortalRepository extends AbstractRepository implements SelfServicePortalRepositoryInterface |
||
55 | { |
||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | protected const FIELD_ORDER_REFERENCE = 'order_reference'; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected const FIELD_SCHEDULED_AT = 'scheduled_at'; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | */ |
||
69 | protected const FIELD_CREATED_AT = 'created_at'; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | protected const FIELD_ID_SALES_ORDER = 'id_sales_order'; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | protected const FIELD_STATE_NAME = 'state_name'; |
||
80 | |||
81 | /** |
||
82 | * @var string |
||
83 | */ |
||
84 | protected const FIELD_PRODUCT_NAME = 'product_name'; |
||
85 | |||
86 | /** |
||
87 | * @var string |
||
88 | */ |
||
89 | protected const FIELD_ID_SALES_ORDER_ITEM = 'id_sales_order_item'; |
||
90 | |||
91 | /** |
||
92 | * @var string |
||
93 | */ |
||
94 | protected const SORT_DIRECTION_ASC = 'ASC'; |
||
95 | |||
96 | /** |
||
97 | * @var string |
||
98 | */ |
||
99 | protected const SORT_DIRECTION_DESC = 'DESC'; |
||
100 | |||
101 | /** |
||
102 | * @var array<string, string> |
||
103 | */ |
||
104 | protected const SERVICE_SORT_FIELD_MAPPING = [ |
||
105 | 'order_reference' => SpySalesOrderTableMap::COL_ORDER_REFERENCE, |
||
106 | 'scheduled_at' => SpySalesOrderItemMetadataTableMap::COL_SCHEDULED_AT, |
||
107 | 'product_name' => SpySalesOrderItemTableMap::COL_NAME, |
||
108 | 'created_at' => SpySalesOrderItemTableMap::COL_CREATED_AT, |
||
109 | 'state' => SpyOmsOrderItemStateTableMap::COL_NAME, |
||
110 | ]; |
||
111 | |||
112 | /** |
||
113 | * @param list<int> $productConcreteIds |
||
114 | * |
||
115 | * @return array<int, list<int>> |
||
|
|||
116 | */ |
||
117 | public function getShipmentTypeIdsGroupedByIdProductConcrete(array $productConcreteIds): array |
||
118 | { |
||
119 | $productShipmentTypeEntities = $this->getFactory() |
||
120 | ->createProductShipmentTypeQuery() |
||
121 | ->filterByFkProduct_In($productConcreteIds) |
||
122 | ->find(); |
||
123 | |||
124 | $groupedShipmentTypeIds = []; |
||
125 | foreach ($productShipmentTypeEntities as $productShipmentTypeEntity) { |
||
126 | $groupedShipmentTypeIds[$productShipmentTypeEntity->getFkProduct()][] = $productShipmentTypeEntity->getFkShipmentType(); |
||
127 | } |
||
128 | |||
129 | /** @var array<int, list<int>> $groupedShipmentTypeIds */ |
||
130 | return $groupedShipmentTypeIds; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @param list<int> $productConcreteIds |
||
135 | * @param string $shipmentTypeName |
||
136 | * |
||
137 | * @return array<int, list<int>> |
||
138 | */ |
||
139 | public function getProductIdsWithShipmentType(array $productConcreteIds, string $shipmentTypeName): array |
||
140 | { |
||
141 | $productShipmentTypeEntities = $this->getFactory() |
||
142 | ->createProductShipmentTypeQuery() |
||
143 | ->useSpyShipmentTypeQuery() |
||
144 | ->filterByName($shipmentTypeName) |
||
145 | ->endUse() |
||
146 | ->filterByFkProduct_In($productConcreteIds) |
||
147 | ->select(SpyProductShipmentTypeTableMap::COL_FK_PRODUCT) |
||
148 | ->find(); |
||
149 | |||
150 | /** @var array<int, list<int>> $productConcreteIdsWithShipmentType */ |
||
151 | $productConcreteIdsWithShipmentType = $productShipmentTypeEntities->getData(); |
||
152 | |||
153 | return $productConcreteIdsWithShipmentType; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param int $idProductAbstract |
||
158 | * |
||
159 | * @return array<\Generated\Shared\Transfer\ProductAbstractTypeTransfer> |
||
160 | */ |
||
161 | public function getProductAbstractTypesByIdProductAbstract(int $idProductAbstract): array |
||
162 | { |
||
163 | $productAbstractTypeEntities = $this->getFactory() |
||
164 | ->createProductAbstractTypeQuery() |
||
165 | ->useProductAbstractToProductAbstractTypeQuery() |
||
166 | ->filterByFkProductAbstract($idProductAbstract) |
||
167 | ->endUse() |
||
168 | ->find(); |
||
169 | |||
170 | return $this->getFactory() |
||
171 | ->createProductAbstractTypeMapper() |
||
172 | ->mapProductAbstractTypeEntitiesToProductAbstractTypeTransfers($productAbstractTypeEntities); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @return \Generated\Shared\Transfer\ProductAbstractTypeCollectionTransfer |
||
177 | */ |
||
178 | public function getProductAbstractTypeCollection(): ProductAbstractTypeCollectionTransfer |
||
179 | { |
||
180 | $productAbstractTypeEntities = $this->getFactory() |
||
181 | ->createProductAbstractTypeQuery() |
||
182 | ->find(); |
||
183 | |||
184 | $productAbstractTypeCollectionTransfer = new ProductAbstractTypeCollectionTransfer(); |
||
185 | |||
186 | foreach ($productAbstractTypeEntities as $productAbstractTypeEntity) { |
||
187 | $productAbstractTypeTransfer = (new ProductAbstractTypeTransfer()) |
||
188 | ->setIdProductAbstractType($productAbstractTypeEntity->getIdProductAbstractType()) |
||
189 | ->setKey($productAbstractTypeEntity->getKey()) |
||
190 | ->setName($productAbstractTypeEntity->getName()); |
||
191 | |||
192 | $productAbstractTypeCollectionTransfer->addProductAbstractType($productAbstractTypeTransfer); |
||
193 | } |
||
194 | |||
195 | return $productAbstractTypeCollectionTransfer; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @param array<int> $productAbstractIds |
||
200 | * |
||
201 | * @return array<\Generated\Shared\Transfer\ProductAbstractTypeTransfer> |
||
202 | */ |
||
203 | public function getProductAbstractTypesByProductAbstractIds(array $productAbstractIds): array |
||
204 | { |
||
205 | if (!$productAbstractIds) { |
||
206 | return []; |
||
207 | } |
||
208 | |||
209 | $productAbstractTypeQuery = $this->getFactory() |
||
210 | ->createProductAbstractTypeQuery() |
||
211 | ->useProductAbstractToProductAbstractTypeQuery() |
||
212 | ->filterByFkProductAbstract_In($productAbstractIds) |
||
213 | ->endUse() |
||
214 | ->joinWithProductAbstractToProductAbstractType() |
||
215 | ->withColumn('spy_product_abstract_to_product_abstract_type.fk_product_abstract', 'fk_product_abstract') |
||
216 | ->groupBy(['spy_product_abstract_type.id_product_abstract_type', 'fk_product_abstract']); |
||
217 | |||
218 | $productAbstractTypeEntities = $productAbstractTypeQuery->find(); |
||
219 | |||
220 | return $this->getFactory() |
||
221 | ->createProductAbstractTypeMapper() |
||
222 | ->mapProductAbstractTypeEntitiesWithVirtualColumnsToProductAbstractTypeTransfers($productAbstractTypeEntities); |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * @param \Generated\Shared\Transfer\SspServiceCriteriaTransfer $sspServiceCriteriaTransfer |
||
227 | * |
||
228 | * @return \Generated\Shared\Transfer\SspServiceCollectionTransfer |
||
229 | */ |
||
230 | public function getServiceCollection(SspServiceCriteriaTransfer $sspServiceCriteriaTransfer): SspServiceCollectionTransfer |
||
231 | { |
||
232 | $serviceCollectionTransfer = new SspServiceCollectionTransfer(); |
||
233 | |||
234 | $query = $this->getFactory()->getSalesOrderItemPropelQuery(); |
||
235 | |||
236 | $query = $this->joinServiceOrderData($query); |
||
237 | |||
238 | $query->joinSalesOrderItemSspAsset(null, Criteria::LEFT_JOIN); |
||
239 | |||
240 | $query = $this->applyServiceFilters($query, $sspServiceCriteriaTransfer); |
||
241 | $query = $this->applyServiceSorting($query, $sspServiceCriteriaTransfer); |
||
242 | |||
243 | $query = $query->groupByIdSalesOrderItem(); |
||
244 | |||
245 | $serviceEntities = $this->getServicePaginatedCollection($query, $sspServiceCriteriaTransfer); |
||
246 | |||
247 | $sspServiceMapper = $this->getFactory()->createSspServiceMapper(); |
||
248 | $serviceTransfers = $sspServiceMapper->mapSalesOrderItemEntitiesToSspServiceTransfers($serviceEntities->getData()); |
||
249 | |||
250 | foreach ($serviceTransfers as $serviceTransfer) { |
||
251 | $serviceCollectionTransfer->addService($serviceTransfer); |
||
252 | } |
||
253 | |||
254 | $serviceCollectionTransfer->setPagination($sspServiceCriteriaTransfer->getPagination()); |
||
255 | |||
256 | return $serviceCollectionTransfer; |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery $query |
||
261 | * |
||
262 | * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery |
||
263 | */ |
||
264 | protected function joinServiceOrderData(SpySalesOrderItemQuery $query): SpySalesOrderItemQuery |
||
265 | { |
||
266 | $query |
||
267 | ->useMetadataQuery(null, Criteria::LEFT_JOIN) |
||
268 | ->withColumn(SpySalesOrderItemMetadataTableMap::COL_SCHEDULED_AT, static::FIELD_SCHEDULED_AT) |
||
269 | ->endUse() |
||
270 | ->useOrderQuery() |
||
271 | ->withColumn(SpySalesOrderTableMap::COL_ORDER_REFERENCE, static::FIELD_ORDER_REFERENCE) |
||
272 | ->withColumn(SpySalesOrderTableMap::COL_ID_SALES_ORDER, static::FIELD_ID_SALES_ORDER) |
||
273 | ->withColumn(SpySalesOrderTableMap::COL_FIRST_NAME, 'first_name') |
||
274 | ->withColumn(SpySalesOrderTableMap::COL_LAST_NAME, 'last_name') |
||
275 | ->addJoin( |
||
276 | SpySalesOrderTableMap::COL_COMPANY_UUID, |
||
277 | 'spy_company.uuid', |
||
278 | Criteria::LEFT_JOIN, |
||
279 | ) |
||
280 | ->withColumn('spy_company.name', 'company_name') |
||
281 | ->endUse(); |
||
282 | |||
283 | $query |
||
284 | ->useStateQuery() |
||
285 | ->withColumn(SpyOmsOrderItemStateTableMap::COL_NAME, static::FIELD_STATE_NAME) |
||
286 | ->endUse() |
||
287 | ->withColumn(SpySalesOrderItemTableMap::COL_NAME, static::FIELD_PRODUCT_NAME) |
||
288 | ->withColumn(SpySalesOrderItemTableMap::COL_ID_SALES_ORDER_ITEM, static::FIELD_ID_SALES_ORDER_ITEM) |
||
289 | ->withColumn(SpySalesOrderItemTableMap::COL_CREATED_AT, static::FIELD_CREATED_AT); |
||
290 | |||
291 | return $query; |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery $query |
||
296 | * @param \Generated\Shared\Transfer\SspServiceCriteriaTransfer $sspServiceCriteriaTransfer |
||
297 | * |
||
298 | * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery |
||
299 | */ |
||
300 | protected function applyServiceFilters(SpySalesOrderItemQuery $query, SspServiceCriteriaTransfer $sspServiceCriteriaTransfer): SpySalesOrderItemQuery |
||
301 | { |
||
302 | if (!$sspServiceCriteriaTransfer->getServiceConditions()) { |
||
303 | return $query; |
||
304 | } |
||
305 | |||
306 | $serviceConditionsTransfer = $sspServiceCriteriaTransfer->getServiceConditionsOrFail(); |
||
307 | |||
308 | $productTypeNameToFilter = $serviceConditionsTransfer->getProductType() ?: $this->getFactory()->getConfig()->getServiceProductTypeName(); |
||
309 | |||
310 | if ($productTypeNameToFilter) { |
||
311 | $query->useSpySalesOrderItemProductAbstractTypeQuery() |
||
312 | ->useSpySalesProductAbstractTypeQuery() |
||
313 | ->filterByName($productTypeNameToFilter) |
||
314 | ->endUse() |
||
315 | ->endUse(); |
||
316 | } |
||
317 | |||
318 | if ($serviceConditionsTransfer->getServicesSearchConditionGroup()) { |
||
319 | $servicesSearchConditionGroup = $serviceConditionsTransfer->getServicesSearchConditionGroup(); |
||
320 | |||
321 | if ($servicesSearchConditionGroup->getProductName()) { |
||
322 | $query->filterByName_Like(sprintf('%%%s%%', $servicesSearchConditionGroup->getProductName())); |
||
323 | } |
||
324 | |||
325 | if ($servicesSearchConditionGroup->getSku()) { |
||
326 | $query->filterBySku_Like(sprintf('%%%s%%', $servicesSearchConditionGroup->getSku())); |
||
327 | } |
||
328 | |||
329 | if ($servicesSearchConditionGroup->getOrderReference()) { |
||
330 | $query->useOrderQuery() |
||
331 | ->filterByOrderReference_Like(sprintf('%%%s%%', $servicesSearchConditionGroup->getOrderReference())) |
||
332 | ->endUse(); |
||
333 | } |
||
334 | } |
||
335 | |||
336 | if ($serviceConditionsTransfer->getCompanyBusinessUnitUuid()) { |
||
337 | $query->useOrderQuery() |
||
338 | ->filterByCompanyBusinessUnitUuid($serviceConditionsTransfer->getCompanyBusinessUnitUuid()) |
||
339 | ->endUse(); |
||
340 | } |
||
341 | |||
342 | if ($serviceConditionsTransfer->getCompanyUuid()) { |
||
343 | $query->useOrderQuery() |
||
344 | ->filterByCompanyUuid($serviceConditionsTransfer->getCompanyUuid()) |
||
345 | ->endUse(); |
||
346 | } |
||
347 | |||
348 | if ($serviceConditionsTransfer->getCustomerReference()) { |
||
349 | $query->useOrderQuery() |
||
350 | ->filterByCustomerReference($serviceConditionsTransfer->getCustomerReference()) |
||
351 | ->endUse(); |
||
352 | } |
||
353 | |||
354 | if ($serviceConditionsTransfer->getSspAssetReferences() !== []) { |
||
355 | $query->useSalesOrderItemSspAssetQuery() |
||
356 | ->filterByReference_In($serviceConditionsTransfer->getSspAssetReferences()) |
||
357 | ->endUse(); |
||
358 | } |
||
359 | |||
360 | return $query; |
||
361 | } |
||
362 | |||
363 | /** |
||
364 | * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery $query |
||
365 | * @param \Generated\Shared\Transfer\SspServiceCriteriaTransfer $sspServiceCriteriaTransfer |
||
366 | * |
||
367 | * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery |
||
368 | */ |
||
369 | protected function applyServiceSorting(SpySalesOrderItemQuery $query, SspServiceCriteriaTransfer $sspServiceCriteriaTransfer): SpySalesOrderItemQuery |
||
370 | { |
||
371 | if (count($sspServiceCriteriaTransfer->getSortCollection()) === 0) { |
||
372 | return $query->orderBy(static::FIELD_SCHEDULED_AT, Criteria::DESC) |
||
373 | ->orderBy(SpySalesOrderItemTableMap::COL_ID_SALES_ORDER_ITEM, Criteria::ASC); |
||
374 | } |
||
375 | |||
376 | $serviceSortFieldMapping = static::SERVICE_SORT_FIELD_MAPPING; |
||
377 | foreach ($sspServiceCriteriaTransfer->getSortCollection() as $sortTransfer) { |
||
378 | $direction = $sortTransfer->getDirection() === static::SORT_DIRECTION_ASC |
||
379 | ? Criteria::ASC |
||
380 | : Criteria::DESC; |
||
381 | |||
382 | if (isset($serviceSortFieldMapping[$sortTransfer->getField()])) { |
||
383 | $query->orderBy($serviceSortFieldMapping[$sortTransfer->getField()], $direction); |
||
384 | } |
||
385 | } |
||
386 | |||
387 | $query->orderBy(SpySalesOrderItemTableMap::COL_ID_SALES_ORDER_ITEM, Criteria::ASC); |
||
388 | |||
389 | return $query; |
||
390 | } |
||
391 | |||
392 | /** |
||
393 | * @param array<int> $productAbstractIds |
||
394 | * |
||
395 | * @return array<\Orm\Zed\SelfServicePortal\Persistence\SpyProductAbstractToProductAbstractType> |
||
396 | */ |
||
397 | public function findProductAbstractTypesByProductAbstractIds(array $productAbstractIds): array |
||
398 | { |
||
399 | return $this->getFactory() |
||
400 | ->createProductAbstractToProductAbstractTypeQuery() |
||
401 | ->filterByFkProductAbstract_In($productAbstractIds) |
||
402 | ->joinWithProductAbstractType() |
||
403 | ->find() |
||
404 | ->getData(); |
||
405 | } |
||
406 | |||
407 | /** |
||
408 | * @param array<int> $salesOrderItemIds |
||
409 | * |
||
410 | * @return array<int, array<string>> |
||
411 | */ |
||
412 | public function getProductTypesGroupedBySalesOrderItemIds(array $salesOrderItemIds): array |
||
413 | { |
||
414 | if (!$salesOrderItemIds) { |
||
415 | return []; |
||
416 | } |
||
417 | |||
418 | $salesOrderItemProductAbstractTypeQuery = $this->getFactory() |
||
419 | ->createSalesOrderItemProductAbstractTypeQuery() |
||
420 | ->filterByFkSalesOrderItem_In($salesOrderItemIds) |
||
421 | ->joinWithSpySalesProductAbstractType(); |
||
422 | |||
423 | $salesOrderItemProductAbstractTypeEntities = $salesOrderItemProductAbstractTypeQuery->find(); |
||
424 | |||
425 | return $this->groupProductTypesBySalesOrderItemId($salesOrderItemProductAbstractTypeEntities); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * @param \Propel\Runtime\Collection\Collection<\Orm\Zed\SelfServicePortal\Persistence\SpySalesOrderItemProductAbstractType> $salesOrderItemProductAbstractTypeEntities |
||
430 | * |
||
431 | * @return array<int, array<string>> |
||
432 | */ |
||
433 | protected function groupProductTypesBySalesOrderItemId(Collection $salesOrderItemProductAbstractTypeEntities): array |
||
434 | { |
||
435 | $productTypesBySalesOrderItemId = []; |
||
436 | |||
437 | foreach ($salesOrderItemProductAbstractTypeEntities as $salesOrderItemProductAbstractTypeEntity) { |
||
438 | /** |
||
439 | * @var \Orm\Zed\SelfServicePortal\Persistence\SpySalesOrderItemProductAbstractType $salesOrderItemProductAbstractTypeEntity |
||
440 | */ |
||
441 | $idSalesOrderItem = $salesOrderItemProductAbstractTypeEntity->getFkSalesOrderItem(); |
||
442 | $productTypeName = $salesOrderItemProductAbstractTypeEntity->getSpySalesProductAbstractType()->getName(); |
||
443 | |||
444 | if (!isset($productTypesBySalesOrderItemId[$idSalesOrderItem])) { |
||
445 | $productTypesBySalesOrderItemId[$idSalesOrderItem] = []; |
||
446 | } |
||
447 | |||
448 | if (!in_array($productTypeName, $productTypesBySalesOrderItemId[$idSalesOrderItem])) { |
||
449 | $productTypesBySalesOrderItemId[$idSalesOrderItem][] = $productTypeName; |
||
450 | } |
||
451 | } |
||
452 | |||
453 | return $productTypesBySalesOrderItemId; |
||
454 | } |
||
455 | |||
456 | /** |
||
457 | * @param \Generated\Shared\Transfer\FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer |
||
458 | * |
||
459 | * @return \Generated\Shared\Transfer\FileAttachmentCollectionTransfer |
||
460 | */ |
||
461 | public function getFileAttachmentCollection(FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer): FileAttachmentCollectionTransfer |
||
462 | { |
||
463 | $fileAttachmentCollectionTransfer = new FileAttachmentCollectionTransfer(); |
||
464 | |||
465 | $companyFiles = $this->getCompanyFiles($fileAttachmentCriteriaTransfer); |
||
466 | $companyUserFiles = $this->getCompanyUserFiles($fileAttachmentCriteriaTransfer); |
||
467 | $companyBusinessUnitFiles = $this->getCompanyBusinessUnitFiles($fileAttachmentCriteriaTransfer); |
||
468 | $sspAssetFiles = $this->getSspAssetFiles($fileAttachmentCriteriaTransfer); |
||
469 | |||
470 | $fileAttachmentTransfers = array_merge( |
||
471 | $this->getFactory()->createCompanyFileMapper()->mapCompanyFileEntitiesToFileAttachmentTransfers($companyFiles), |
||
472 | $this->getFactory()->createCompanyUserFileMapper()->mapCompanyUserFileEntitiesToFileAttachmentTransfers($companyUserFiles), |
||
473 | $this->getFactory()->createCompanyBusinessUnitFileMapper()->mapCompanyBusinessUnitFileEntitiesToFileAttachmentTransfers($companyBusinessUnitFiles), |
||
474 | $this->getFactory()->createSspAssetFileMapper()->mapSspAssetFileEntitiesToFileAttachmentTransfers($sspAssetFiles), |
||
475 | ); |
||
476 | |||
477 | return $fileAttachmentCollectionTransfer->setFileAttachments(new ArrayObject($fileAttachmentTransfers)); |
||
478 | } |
||
479 | |||
480 | /** |
||
481 | * @param \Generated\Shared\Transfer\FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer |
||
482 | * |
||
483 | * @return \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFile> |
||
484 | */ |
||
485 | protected function getCompanyFiles(FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer): ObjectCollection |
||
486 | { |
||
487 | $query = $this->getFactory() |
||
488 | ->createCompanyFileQuery(); |
||
489 | |||
490 | $idFiles = $fileAttachmentCriteriaTransfer->getFileAttachmentConditionsOrFail()->getIdFiles(); |
||
491 | |||
492 | if ($idFiles !== null) { |
||
493 | $query->filterByFkFile_In($idFiles); |
||
494 | } |
||
495 | |||
496 | /** @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFile> $companyFilesCollection */ |
||
497 | $companyFilesCollection = $query->find(); |
||
498 | |||
499 | return $companyFilesCollection; |
||
500 | } |
||
501 | |||
502 | /** |
||
503 | * @param \Generated\Shared\Transfer\FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer |
||
504 | * |
||
505 | * @return \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFile> |
||
506 | */ |
||
507 | protected function getCompanyUserFiles(FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer): ObjectCollection |
||
508 | { |
||
509 | $query = $this->getFactory() |
||
510 | ->createCompanyUserFileQuery(); |
||
511 | |||
512 | $idFiles = $fileAttachmentCriteriaTransfer->getFileAttachmentConditionsOrFail()->getIdFiles(); |
||
513 | |||
514 | if ($idFiles !== null) { |
||
515 | $query->filterByFkFile_In($idFiles); |
||
516 | } |
||
517 | |||
518 | /** @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFile> $companyUserFilesCollection */ |
||
519 | $companyUserFilesCollection = $query->find(); |
||
520 | |||
521 | return $companyUserFilesCollection; |
||
522 | } |
||
523 | |||
524 | /** |
||
525 | * @param \Generated\Shared\Transfer\FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer |
||
526 | * |
||
527 | * @return \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFile> |
||
528 | */ |
||
529 | protected function getCompanyBusinessUnitFiles(FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer): ObjectCollection |
||
530 | { |
||
531 | $query = $this->getFactory() |
||
532 | ->createCompanyBusinessUnitFileQuery(); |
||
533 | |||
534 | $idFiles = $fileAttachmentCriteriaTransfer->getFileAttachmentConditionsOrFail()->getIdFiles(); |
||
535 | |||
536 | if ($idFiles !== null) { |
||
537 | $query->filterByFkFile_In($idFiles); |
||
538 | } |
||
539 | |||
540 | /** @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFile> $companyBusinessUnitFilesCollection */ |
||
541 | $companyBusinessUnitFilesCollection = $query->find(); |
||
542 | |||
543 | return $companyBusinessUnitFilesCollection; |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * @param \Generated\Shared\Transfer\FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer |
||
548 | * |
||
549 | * @return \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFile> |
||
550 | */ |
||
551 | protected function getSspAssetFiles(FileAttachmentCriteriaTransfer $fileAttachmentCriteriaTransfer): ObjectCollection |
||
552 | { |
||
553 | $query = $this->getFactory() |
||
554 | ->createSspAssetFileQuery(); |
||
555 | |||
556 | $idFiles = $fileAttachmentCriteriaTransfer->getFileAttachmentConditionsOrFail()->getIdFiles(); |
||
557 | |||
558 | if ($idFiles !== null) { |
||
559 | $query->filterByFkFile_In($idFiles); |
||
560 | } |
||
561 | |||
562 | /** @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFile> $assetFilesCollection */ |
||
563 | $assetFilesCollection = $query->find(); |
||
564 | |||
565 | return $assetFilesCollection; |
||
566 | } |
||
567 | |||
568 | /** |
||
569 | * @param \Generated\Shared\Transfer\FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
570 | * @param array<\SprykerFeature\Zed\SelfServicePortal\Persistence\QueryStrategy\FilePermissionQueryStrategyInterface> $queryStrategies |
||
571 | * |
||
572 | * @return \Generated\Shared\Transfer\FileAttachmentFileCollectionTransfer |
||
573 | */ |
||
574 | public function getFileAttachmentFileCollectionAccordingToPermissions( |
||
575 | FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer, |
||
576 | array $queryStrategies |
||
577 | ): FileAttachmentFileCollectionTransfer { |
||
578 | $query = $this->getFactory() |
||
579 | ->getFilePropelQuery() |
||
580 | ->leftJoinSpyFileInfo() |
||
581 | ->groupBy(SpyFileTableMap::COL_ID_FILE); |
||
582 | |||
583 | $query = $this->applyFileAttachmentPermissionStrategies($query, $fileAttachmentFileCriteriaTransfer, $queryStrategies); |
||
584 | $query = $this->applyFileAttachmentSearch($query, $fileAttachmentFileCriteriaTransfer); |
||
585 | $query = $this->applyFileAttachmentTypeFilter($query, $fileAttachmentFileCriteriaTransfer); |
||
586 | $query = $this->applyFileAttachmentDateRangeFilter($query, $fileAttachmentFileCriteriaTransfer); |
||
587 | $query = $this->applyFileAttachmentUuidFilter($query, $fileAttachmentFileCriteriaTransfer); |
||
588 | |||
589 | /** @var \ArrayObject<array-key, \Generated\Shared\Transfer\SortTransfer> $sortTransfers */ |
||
590 | $sortTransfers = $fileAttachmentFileCriteriaTransfer->getSortCollection(); |
||
591 | $query = $this->applyFileAttachmentSorting($query, $sortTransfers); |
||
592 | |||
593 | $fileAttachmentFileCollectionTransfer = new FileAttachmentFileCollectionTransfer(); |
||
594 | $paginationTransfer = $fileAttachmentFileCriteriaTransfer->getPagination(); |
||
595 | if ($paginationTransfer !== null) { |
||
596 | $query = $this->applyPagination($query, $paginationTransfer); |
||
597 | $fileAttachmentFileCollectionTransfer->setPagination($paginationTransfer); |
||
598 | } |
||
599 | |||
600 | return $this->getFactory() |
||
601 | ->createFileMapper() |
||
602 | ->mapEntityCollectionToTransferCollection( |
||
603 | $query->find(), |
||
604 | $fileAttachmentFileCollectionTransfer, |
||
605 | ); |
||
606 | } |
||
607 | |||
608 | /** |
||
609 | * @param \Orm\Zed\FileManager\Persistence\SpyFileQuery $query |
||
610 | * @param \Generated\Shared\Transfer\FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
611 | * @param array<\SprykerFeature\Zed\SelfServicePortal\Persistence\QueryStrategy\FilePermissionQueryStrategyInterface> $queryStrategies |
||
612 | * |
||
613 | * @return \Orm\Zed\FileManager\Persistence\SpyFileQuery |
||
614 | */ |
||
615 | protected function applyFileAttachmentPermissionStrategies( |
||
616 | SpyFileQuery $query, |
||
617 | FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer, |
||
618 | array $queryStrategies |
||
619 | ): SpyFileQuery { |
||
620 | foreach ($queryStrategies as $strategy) { |
||
621 | $query = $strategy->apply($query, $fileAttachmentFileCriteriaTransfer); |
||
622 | } |
||
623 | |||
624 | return $query; |
||
625 | } |
||
626 | |||
627 | /** |
||
628 | * @param \Orm\Zed\FileManager\Persistence\SpyFileQuery $query |
||
629 | * @param \Generated\Shared\Transfer\FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
630 | * |
||
631 | * @return \Orm\Zed\FileManager\Persistence\SpyFileQuery |
||
632 | */ |
||
633 | protected function applyFileAttachmentSearch( |
||
634 | SpyFileQuery $query, |
||
635 | FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
636 | ): SpyFileQuery { |
||
637 | $searchString = $fileAttachmentFileCriteriaTransfer->getFileAttachmentFileSearchConditionsOrFail()->getSearchString(); |
||
638 | if ($searchString) { |
||
639 | $query->filterByFileName_Like(sprintf('%%%s%%', $searchString)) |
||
640 | ->_or() |
||
641 | ->filterByFileReference_Like(sprintf('%%%s%%', $searchString)); |
||
642 | } |
||
643 | |||
644 | return $query; |
||
645 | } |
||
646 | |||
647 | /** |
||
648 | * @param \Orm\Zed\FileManager\Persistence\SpyFileQuery $query |
||
649 | * @param \Generated\Shared\Transfer\FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
650 | * |
||
651 | * @return \Orm\Zed\FileManager\Persistence\SpyFileQuery |
||
652 | */ |
||
653 | protected function applyFileAttachmentTypeFilter( |
||
654 | SpyFileQuery $query, |
||
655 | FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
656 | ): SpyFileQuery { |
||
657 | $fileTypes = $fileAttachmentFileCriteriaTransfer->getFileAttachmentFileConditionsOrFail()->getFileTypes(); |
||
658 | |||
659 | if (!$fileTypes) { |
||
660 | return $query; |
||
661 | } |
||
662 | |||
663 | return $query |
||
664 | ->useSpyFileInfoQuery() |
||
665 | ->filterByExtension_In($fileTypes) |
||
666 | ->endUse(); |
||
667 | } |
||
668 | |||
669 | /** |
||
670 | * @param \Orm\Zed\FileManager\Persistence\SpyFileQuery $query |
||
671 | * @param \Generated\Shared\Transfer\FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
672 | * |
||
673 | * @return \Orm\Zed\FileManager\Persistence\SpyFileQuery |
||
674 | */ |
||
675 | protected function applyFileAttachmentDateRangeFilter( |
||
676 | SpyFileQuery $query, |
||
677 | FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
678 | ): SpyFileQuery { |
||
679 | $rangeCreatedAt = $fileAttachmentFileCriteriaTransfer->getFileAttachmentFileConditionsOrFail()->getRangeCreatedAt(); |
||
680 | if (!$rangeCreatedAt) { |
||
681 | return $query; |
||
682 | } |
||
683 | |||
684 | if ($rangeCreatedAt->getFrom()) { |
||
685 | $query->useSpyFileInfoQuery() |
||
686 | ->filterByCreatedAt($rangeCreatedAt->getFrom(), Criteria::GREATER_EQUAL) |
||
687 | ->endUse(); |
||
688 | } |
||
689 | |||
690 | if ($rangeCreatedAt->getTo()) { |
||
691 | $query->useSpyFileInfoQuery() |
||
692 | ->filterByCreatedAt($rangeCreatedAt->getTo(), Criteria::LESS_EQUAL) |
||
693 | ->endUse(); |
||
694 | } |
||
695 | |||
696 | return $query; |
||
697 | } |
||
698 | |||
699 | /** |
||
700 | * @param \Orm\Zed\FileManager\Persistence\SpyFileQuery $query |
||
701 | * @param \Generated\Shared\Transfer\FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
702 | * |
||
703 | * @return \Orm\Zed\FileManager\Persistence\SpyFileQuery |
||
704 | */ |
||
705 | protected function applyFileAttachmentUuidFilter( |
||
706 | SpyFileQuery $query, |
||
707 | FileAttachmentFileCriteriaTransfer $fileAttachmentFileCriteriaTransfer |
||
708 | ): SpyFileQuery { |
||
709 | $uuids = $fileAttachmentFileCriteriaTransfer->getFileAttachmentFileConditionsOrFail()->getUuids(); |
||
710 | if ($uuids !== []) { |
||
711 | $query |
||
712 | ->filterByUuid_In($uuids); |
||
713 | } |
||
714 | |||
715 | return $query; |
||
716 | } |
||
717 | |||
718 | /** |
||
719 | * @param \Propel\Runtime\ActiveQuery\ModelCriteria $query |
||
720 | * @param \Generated\Shared\Transfer\PaginationTransfer $paginationTransfer |
||
721 | * |
||
722 | * @return \Propel\Runtime\ActiveQuery\ModelCriteria |
||
723 | */ |
||
724 | protected function applyPagination(ModelCriteria $query, PaginationTransfer $paginationTransfer): ModelCriteria |
||
725 | { |
||
726 | if ($paginationTransfer->getLimit() === null || $paginationTransfer->getOffset() === null) { |
||
727 | $paginationTransfer = $this->getPaginationTransfer($query, $paginationTransfer); |
||
728 | } |
||
729 | |||
730 | $query |
||
731 | ->setLimit($paginationTransfer->getLimitOrFail()) |
||
732 | ->setOffset($paginationTransfer->getOffsetOrFail()); |
||
733 | |||
734 | return $query; |
||
735 | } |
||
736 | |||
737 | /** |
||
738 | * @param \Propel\Runtime\ActiveQuery\ModelCriteria $query |
||
739 | * @param \Generated\Shared\Transfer\PaginationTransfer $paginationTransfer |
||
740 | * |
||
741 | * @return \Generated\Shared\Transfer\PaginationTransfer |
||
742 | */ |
||
743 | protected function getPaginationTransfer( |
||
744 | ModelCriteria $query, |
||
745 | PaginationTransfer $paginationTransfer |
||
746 | ): PaginationTransfer { |
||
747 | $page = $paginationTransfer->getPage() ?? 1; |
||
748 | $maxPerPage = $paginationTransfer->getMaxPerPage() ?? 10; |
||
749 | $paginationModel = $query->paginate($page, $maxPerPage); |
||
750 | $nbResults = $paginationModel->getNbResults(); |
||
751 | |||
752 | return $paginationTransfer |
||
753 | ->setNbResults($nbResults) |
||
754 | ->setFirstIndex($paginationModel->getFirstIndex()) |
||
755 | ->setLastIndex($paginationModel->getLastIndex()) |
||
756 | ->setFirstPage($paginationModel->getFirstPage()) |
||
757 | ->setLastPage($paginationModel->getLastPage()) |
||
758 | ->setNextPage($paginationModel->getNextPage()) |
||
759 | ->setPreviousPage($paginationModel->getPreviousPage()) |
||
760 | ->setOffset(($page - 1) * $maxPerPage) |
||
761 | ->setLimit($maxPerPage); |
||
762 | } |
||
763 | |||
764 | /** |
||
765 | * @param \Propel\Runtime\ActiveQuery\ModelCriteria $query |
||
766 | * @param \ArrayObject<array-key, \Generated\Shared\Transfer\SortTransfer> $sortTransfers |
||
767 | * |
||
768 | * @return \Propel\Runtime\ActiveQuery\ModelCriteria |
||
769 | */ |
||
770 | protected function applyFileAttachmentSorting(ModelCriteria $query, ArrayObject $sortTransfers): ModelCriteria |
||
771 | { |
||
772 | $fileAttachmentSortFieldMapping = $this->getFileAttachmentSortFieldMapping(); |
||
773 | foreach ($sortTransfers as $sortTransfer) { |
||
774 | $query |
||
775 | ->groupBy($fileAttachmentSortFieldMapping[$sortTransfer->getFieldOrFail()] ?? $sortTransfer->getFieldOrFail()) |
||
776 | ->orderBy( |
||
777 | $fileAttachmentSortFieldMapping[$sortTransfer->getFieldOrFail()] ?? $sortTransfer->getFieldOrFail(), |
||
778 | $sortTransfer->getIsAscending() ? Criteria::ASC : Criteria::DESC, |
||
779 | ); |
||
780 | } |
||
781 | |||
782 | return $query; |
||
783 | } |
||
784 | |||
785 | /** |
||
786 | * @param \Generated\Shared\Transfer\SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer |
||
787 | * |
||
788 | * @return \Generated\Shared\Transfer\SspInquiryCollectionTransfer |
||
789 | */ |
||
790 | public function getSspInquiryCollection( |
||
791 | SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer |
||
792 | ): SspInquiryCollectionTransfer { |
||
793 | $sspInquiryCollectionTransfer = new SspInquiryCollectionTransfer(); |
||
794 | |||
795 | $sspInquiryQuery = $this->getFactory()->createSspInquiryQuery() |
||
796 | ->joinWithStateMachineItemState(); |
||
797 | |||
798 | $sspInquiryQuery = $this->applyInquiryFilters($sspInquiryQuery, $sspInquiryCriteriaTransfer); |
||
799 | $sspInquiryEntities = $this->getPaginatedInquiryCollection($sspInquiryQuery, $sspInquiryCriteriaTransfer->getPagination()); |
||
800 | $sspInquiryMapper = $this->getFactory()->createSspInquiryMapper(); |
||
801 | |||
802 | foreach ($sspInquiryEntities as $sspInquiryEntity) { |
||
803 | $sspInquiryCollectionTransfer->addSspInquiry( |
||
804 | $sspInquiryMapper->mapSspInquiryEntityToSspInquiryTransfer($sspInquiryEntity, new SspInquiryTransfer()), |
||
805 | ); |
||
806 | } |
||
807 | |||
808 | $sspInquiryCollectionTransfer->setPagination($sspInquiryCriteriaTransfer->getPagination()); |
||
809 | |||
810 | return $sspInquiryCollectionTransfer; |
||
811 | } |
||
812 | |||
813 | /** |
||
814 | * @param \Generated\Shared\Transfer\SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer |
||
815 | * |
||
816 | * @return \Generated\Shared\Transfer\SspInquiryCollectionTransfer |
||
817 | */ |
||
818 | public function getSspInquiryFileCollection(SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer): SspInquiryCollectionTransfer |
||
819 | { |
||
820 | $sspInquiryFileQuery = $this->getFactory()->createSspInquiryFileQuery(); |
||
821 | |||
822 | $sspInquiryFileQuery->filterByFkSspInquiry_In($sspInquiryCriteriaTransfer->getSspInquiryConditionsOrFail()->getSspInquiryIds()); |
||
823 | |||
824 | $sspInquiryCollectionTransfer = new SspInquiryCollectionTransfer(); |
||
825 | |||
826 | /** |
||
827 | * @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryFile> $sspInquiryFileEntities |
||
828 | */ |
||
829 | $sspInquiryFileEntities = $sspInquiryFileQuery->find(); |
||
830 | |||
831 | if ($sspInquiryFileEntities->count() === 0) { |
||
832 | return $sspInquiryCollectionTransfer; |
||
833 | } |
||
834 | |||
835 | return $this->getFactory() |
||
836 | ->createSspInquiryMapper() |
||
837 | ->mapSspInquiryFileEntitiesToSspInquiryCollectionTransfer( |
||
838 | $sspInquiryFileEntities, |
||
839 | $sspInquiryCollectionTransfer, |
||
840 | ); |
||
841 | } |
||
842 | |||
843 | /** |
||
844 | * @param \Generated\Shared\Transfer\SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer |
||
845 | * |
||
846 | * @return \Generated\Shared\Transfer\SspInquiryCollectionTransfer |
||
847 | */ |
||
848 | public function getSspInquiryOrderCollection(SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer): SspInquiryCollectionTransfer |
||
849 | { |
||
850 | $sspInquiryOrderQuery = $this->getFactory()->createSspInquiryOrderQuery(); |
||
851 | |||
852 | $sspInquiryOrderQuery->filterByFkSspInquiry_In($sspInquiryCriteriaTransfer->getSspInquiryConditionsOrFail()->getSspInquiryIds()); |
||
853 | |||
854 | $sspInquiryCollectionTransfer = new SspInquiryCollectionTransfer(); |
||
855 | |||
856 | foreach ($sspInquiryOrderQuery->find() as $sspInquiryOrderEntity) { |
||
857 | $sspInquiryCollectionTransfer->addSspInquiry( |
||
858 | (new SspInquiryTransfer()) |
||
859 | ->setIdSspInquiry($sspInquiryOrderEntity->getFkSspInquiry()) |
||
860 | ->setOrder((new OrderTransfer())->setIdSalesOrder($sspInquiryOrderEntity->getFkSalesOrder())), |
||
861 | ); |
||
862 | } |
||
863 | |||
864 | return $sspInquiryCollectionTransfer; |
||
865 | } |
||
866 | |||
867 | /** |
||
868 | * @param \Generated\Shared\Transfer\SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer |
||
869 | * |
||
870 | * @return \Generated\Shared\Transfer\SspInquiryCollectionTransfer |
||
871 | */ |
||
872 | public function getSspInquirySspAssetCollection(SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer): SspInquiryCollectionTransfer |
||
873 | { |
||
874 | $sspInquirySspAssetQuery = $this->getFactory()->createSspInquirySspAssetQuery(); |
||
875 | |||
876 | $sspInquirySspAssetQuery->filterByFkSspInquiry_In($sspInquiryCriteriaTransfer->getSspInquiryConditionsOrFail()->getSspInquiryIds()); |
||
877 | |||
878 | $inquiryCollectionTransfer = new SspInquiryCollectionTransfer(); |
||
879 | |||
880 | foreach ($sspInquirySspAssetQuery->find() as $sspInquirySspAssetEntity) { |
||
881 | $inquiryCollectionTransfer->addSspInquiry( |
||
882 | (new SspInquiryTransfer()) |
||
883 | ->setIdSspInquiry($sspInquirySspAssetEntity->getFkSspInquiry()) |
||
884 | ->setSspAsset((new SspAssetTransfer())->setIdSspAsset($sspInquirySspAssetEntity->getFkSspAsset())), |
||
885 | ); |
||
886 | } |
||
887 | |||
888 | return $inquiryCollectionTransfer; |
||
889 | } |
||
890 | |||
891 | /** |
||
892 | * @param array<int> $stateIds |
||
893 | * |
||
894 | * @return array<\Generated\Shared\Transfer\StateMachineItemTransfer> |
||
895 | */ |
||
896 | public function getStateMachineItemsByStateIds(array $stateIds): array |
||
897 | { |
||
898 | /** @var \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryQuery<\Orm\Zed\SelfServicePortal\Persistence\SpySspInquiry> $sspInquiryQuery */ |
||
899 | $sspInquiryQuery = $this->getFactory() |
||
900 | ->createSspInquiryQuery() |
||
901 | ->joinWithStateMachineItemState() |
||
902 | ->useStateMachineItemStateQuery() |
||
903 | ->joinWithProcess() |
||
904 | ->endUse(); |
||
905 | |||
906 | /** @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\SelfServicePortal\Persistence\SpySspInquiry> $sspInquiryEntities */ |
||
907 | $sspInquiryEntities = $sspInquiryQuery |
||
908 | ->filterByFkStateMachineItemState_In($stateIds) |
||
909 | ->find(); |
||
910 | |||
911 | return $this->getFactory()->createSspInquiryMapper()->mapSspInquiryEntityCollectionToStateMachineItemTransfers( |
||
912 | $sspInquiryEntities, |
||
913 | ); |
||
914 | } |
||
915 | |||
916 | /** |
||
917 | * @param \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryQuery $sspInquiryQuery |
||
918 | * @param \Generated\Shared\Transfer\SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer |
||
919 | * |
||
920 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryQuery |
||
921 | */ |
||
922 | protected function applyInquiryFilters(SpySspInquiryQuery $sspInquiryQuery, SspInquiryCriteriaTransfer $sspInquiryCriteriaTransfer): SpySspInquiryQuery |
||
923 | { |
||
924 | $sspInquiryQuery = $this->applySspInquirySorting($sspInquiryQuery, $sspInquiryCriteriaTransfer->getSortCollection()); |
||
925 | |||
926 | $sspInquiryConditions = $sspInquiryCriteriaTransfer->getSspInquiryConditions(); |
||
927 | |||
928 | if (!$sspInquiryConditions) { |
||
929 | return $sspInquiryQuery; |
||
930 | } |
||
931 | |||
932 | if ($sspInquiryConditions->getSspInquiryIds() !== []) { |
||
933 | $sspInquiryQuery->filterByIdSspInquiry_In($sspInquiryConditions->getSspInquiryIds()); |
||
934 | } |
||
935 | |||
936 | if ($sspInquiryConditions->getReferences() !== []) { |
||
937 | $sspInquiryQuery->filterByReference_In($sspInquiryConditions->getReferences()); |
||
938 | } |
||
939 | |||
940 | if ($sspInquiryConditions->getType() !== null) { |
||
941 | $sspInquiryQuery->filterByType($sspInquiryConditions->getType()); |
||
942 | } |
||
943 | |||
944 | if ($sspInquiryConditions->getStatus() !== null) { |
||
945 | $sspInquiryQuery |
||
946 | ->useStateMachineItemStateQuery() |
||
947 | ->filterByName($sspInquiryConditions->getStatus()) |
||
948 | ->endUse(); |
||
949 | } |
||
950 | |||
951 | $this->applySspInquiryOwnerFilter($sspInquiryQuery, $sspInquiryConditions); |
||
952 | |||
953 | if ($sspInquiryConditions->getCreatedDateFrom() !== null) { |
||
954 | $sspInquiryQuery->filterByCreatedAt($sspInquiryConditions->getCreatedDateFrom(), ModelCriteria::GREATER_EQUAL); |
||
955 | } |
||
956 | |||
957 | if ($sspInquiryConditions->getCreatedDateTo() !== null) { |
||
958 | $sspInquiryQuery->filterByCreatedAt($sspInquiryConditions->getCreatedDateTo(), ModelCriteria::LESS_EQUAL); |
||
959 | } |
||
960 | |||
961 | if ($sspInquiryConditions->getIdStore() !== null) { |
||
962 | $sspInquiryQuery->filterByFkStore($sspInquiryConditions->getIdStore()); |
||
963 | } |
||
964 | |||
965 | if ($sspInquiryConditions->getStoreName() !== null) { |
||
966 | $sspInquiryQuery |
||
967 | ->useSpyStoreQuery() |
||
968 | ->filterByName($sspInquiryConditions->getStoreName()) |
||
969 | ->endUse(); |
||
970 | } |
||
971 | |||
972 | if ($sspInquiryConditions->getSspAssetIds() !== []) { |
||
973 | $sspInquiryQuery |
||
974 | ->joinSpySspInquirySspAsset() |
||
975 | ->withColumn(SpySspInquirySspAssetTableMap::COL_FK_SSP_ASSET, SspAssetTransfer::ID_SSP_ASSET) |
||
976 | ->useSpySspInquirySspAssetExistsQuery() |
||
977 | ->filterByFkSspAsset_In($sspInquiryConditions->getSspAssetIds()) |
||
978 | ->endUse(); |
||
979 | } |
||
980 | |||
981 | if ($sspInquiryConditions->getSspAssetReferences() !== []) { |
||
982 | $sspInquiryQuery |
||
983 | ->useSpySspInquirySspAssetExistsQuery() |
||
984 | ->useSpySspAssetQuery() |
||
985 | ->filterByReference_In($sspInquiryConditions->getSspAssetReferences()) |
||
986 | ->endUse() |
||
987 | ->endUse(); |
||
988 | } |
||
989 | |||
990 | return $sspInquiryQuery; |
||
991 | } |
||
992 | |||
993 | /** |
||
994 | * @param \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryQuery $sspInquiryQuery |
||
995 | * @param \Generated\Shared\Transfer\SspInquiryConditionsTransfer $sspInquiryConditions |
||
996 | * |
||
997 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryQuery |
||
998 | */ |
||
999 | public function applySspInquiryOwnerFilter(SpySspInquiryQuery $sspInquiryQuery, SspInquiryConditionsTransfer $sspInquiryConditions): SpySspInquiryQuery |
||
1033 | } |
||
1034 | |||
1035 | /** |
||
1036 | * @param \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryQuery $sspInquiryQuery |
||
1037 | * @param \ArrayObject<int, \Generated\Shared\Transfer\SortTransfer> $sortCollection |
||
1038 | * |
||
1039 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpySspInquiryQuery |
||
1040 | */ |
||
1041 | protected function applySspInquirySorting(SpySspInquiryQuery $sspInquiryQuery, ArrayObject $sortCollection): SpySspInquiryQuery |
||
1042 | { |
||
1043 | foreach ($sortCollection as $sort) { |
||
1044 | $field = $sort->getFieldOrFail(); |
||
1045 | if ($field === SspInquiryTransfer::CREATED_DATE) { |
||
1046 | $field = SpySspInquiryTableMap::COL_CREATED_AT; |
||
1047 | } |
||
1048 | $sspInquiryQuery->orderBy($field, $sort->getIsAscending() ? Criteria::ASC : Criteria::DESC); |
||
1049 | } |
||
1050 | |||
1051 | return $sspInquiryQuery; |
||
1052 | } |
||
1053 | |||
1054 | /** |
||
1055 | * @param \Propel\Runtime\ActiveQuery\ModelCriteria $query |
||
1056 | * @param \Generated\Shared\Transfer\PaginationTransfer|null $paginationTransfer |
||
1057 | * |
||
1058 | * @return \Propel\Runtime\Collection\Collection |
||
1059 | */ |
||
1060 | protected function getPaginatedInquiryCollection(ModelCriteria $query, ?PaginationTransfer $paginationTransfer = null): Collection |
||
1061 | { |
||
1062 | if ($paginationTransfer === null) { |
||
1063 | return $query->find(); |
||
1064 | } |
||
1065 | |||
1066 | $page = $paginationTransfer |
||
1067 | ->requirePage() |
||
1068 | ->getPageOrFail(); |
||
1069 | |||
1070 | $maxPerPage = $paginationTransfer |
||
1071 | ->requireMaxPerPage() |
||
1072 | ->getMaxPerPageOrFail(); |
||
1073 | |||
1074 | $paginationModel = $query->paginate($page, $maxPerPage); |
||
1075 | |||
1076 | $paginationTransfer->setNbResults($paginationModel->getNbResults()); |
||
1077 | $paginationTransfer->setFirstIndex($paginationModel->getFirstIndex()); |
||
1078 | $paginationTransfer->setLastIndex($paginationModel->getLastIndex()); |
||
1079 | $paginationTransfer->setFirstPage($paginationModel->getFirstPage()); |
||
1080 | $paginationTransfer->setLastPage($paginationModel->getLastPage()); |
||
1081 | $paginationTransfer->setNextPage($paginationModel->getNextPage()); |
||
1082 | $paginationTransfer->setPreviousPage($paginationModel->getPreviousPage()); |
||
1083 | |||
1084 | return $paginationModel->getResults(); |
||
1085 | } |
||
1086 | |||
1087 | /** |
||
1088 | * @return array<string, string> |
||
1089 | */ |
||
1090 | protected function getFileAttachmentSortFieldMapping(): array |
||
1091 | { |
||
1092 | return [ |
||
1093 | 'fileType' => SpyFileInfoTableMap::COL_EXTENSION, |
||
1094 | 'size' => SpyFileInfoTableMap::COL_SIZE, |
||
1095 | 'createdAt' => SpyFileInfoTableMap::COL_CREATED_AT, |
||
1096 | ]; |
||
1097 | } |
||
1098 | |||
1099 | /** |
||
1100 | * @param \Generated\Shared\Transfer\SspAssetCriteriaTransfer $sspAssetCriteriaTransfer |
||
1101 | * |
||
1102 | * @return \Generated\Shared\Transfer\SspAssetCollectionTransfer |
||
1103 | */ |
||
1104 | public function getSspAssetCollection(SspAssetCriteriaTransfer $sspAssetCriteriaTransfer): SspAssetCollectionTransfer |
||
1105 | { |
||
1106 | $sspAssetCollectionTransfer = new SspAssetCollectionTransfer(); |
||
1107 | |||
1108 | $sspAssetQuery = $this->getFactory()->createSspAssetQuery(); |
||
1109 | |||
1110 | $sspAssetQuery = $this->applyAssetConditions($sspAssetQuery, $sspAssetCriteriaTransfer); |
||
1111 | $sspAssetQuery = $this->applyAssetSorting($sspAssetQuery, $sspAssetCriteriaTransfer); |
||
1112 | |||
1113 | if ($sspAssetCriteriaTransfer->getInclude()?->getWithOwnerCompanyBusinessUnit()) { |
||
1114 | $sspAssetQuery->joinWithSpyCompanyBusinessUnit(Criteria::LEFT_JOIN); |
||
1115 | } |
||
1116 | |||
1117 | $sspAssetEntities = $this->getAssetPaginatedCollection($sspAssetQuery, $sspAssetCriteriaTransfer->getPagination()); |
||
1118 | $sspAssetIds = []; |
||
1119 | foreach ($sspAssetEntities as $sspAssetEntity) { |
||
1120 | $sspAssetTransfer = $this->getFactory() |
||
1121 | ->createAssetMapper() |
||
1122 | ->mapSpySspAssetEntityToSspAssetTransfer($sspAssetEntity, new SspAssetTransfer()); |
||
1123 | |||
1124 | if ($sspAssetCriteriaTransfer->getInclude()) { |
||
1125 | $sspAssetTransfer = $this->getFactory() |
||
1126 | ->createAssetMapper() |
||
1127 | ->mapSpySspAssetEntityToSspAssetTransferIncludes( |
||
1128 | $sspAssetEntity, |
||
1129 | $sspAssetTransfer, |
||
1130 | $sspAssetCriteriaTransfer->getIncludeOrFail(), |
||
1131 | ); |
||
1132 | } |
||
1133 | |||
1134 | $sspAssetCollectionTransfer->addSspAsset($sspAssetTransfer); |
||
1135 | $sspAssetIds[] = $sspAssetTransfer->getIdSspAsset(); |
||
1136 | } |
||
1137 | |||
1138 | $sspAssetCollectionTransfer->setPagination($sspAssetCriteriaTransfer->getPagination()); |
||
1139 | |||
1140 | if (!$sspAssetCriteriaTransfer->getInclude()?->getWithAssignedBusinessUnits()) { |
||
1141 | return $sspAssetCollectionTransfer; |
||
1142 | } |
||
1143 | |||
1144 | /** @var \Orm\Zed\SelfServicePortal\Persistence\SpySspAssetToCompanyBusinessUnitQuery $sspAssetToCompanyBusinessUnitQuery */ |
||
1145 | $sspAssetToCompanyBusinessUnitQuery = $this->getFactory()->createSspAssetToCompanyBusinessUnitQuery() |
||
1146 | ->filterByFkSspAsset_In($sspAssetIds) |
||
1147 | ->joinWithSpyCompanyBusinessUnit() |
||
1148 | ->useSpyCompanyBusinessUnitQuery() |
||
1149 | ->joinWithCompany() |
||
1150 | ->endUse(); |
||
1151 | |||
1152 | if ($sspAssetCriteriaTransfer->getSspAssetConditions()) { |
||
1153 | if ($sspAssetCriteriaTransfer->getSspAssetConditionsOrFail()->getAssignedBusinessUnitId()) { |
||
1154 | $sspAssetToCompanyBusinessUnitQuery->filterByFkCompanyBusinessUnit( |
||
1155 | $sspAssetCriteriaTransfer->getSspAssetConditionsOrFail()->getAssignedBusinessUnitId(), |
||
1156 | ); |
||
1157 | } |
||
1158 | |||
1159 | if ($sspAssetCriteriaTransfer->getSspAssetConditionsOrFail()->getAssignedBusinessUnitCompanyId()) { |
||
1160 | $sspAssetToCompanyBusinessUnitQuery |
||
1161 | ->useSpyCompanyBusinessUnitQuery() |
||
1162 | ->filterByFkCompany($sspAssetCriteriaTransfer->getSspAssetConditionsOrFail()->getAssignedBusinessUnitCompanyId()) |
||
1163 | ->endUse(); |
||
1164 | } |
||
1165 | } |
||
1166 | |||
1167 | $sspAssetToCompanyBusinessUnitEntities = $sspAssetToCompanyBusinessUnitQuery->find(); |
||
1168 | |||
1169 | foreach ($sspAssetCollectionTransfer->getSspAssets() as $sspAssetTransfer) { |
||
1170 | foreach ($sspAssetToCompanyBusinessUnitEntities as $sspAssetToCompanyBusinessUnit) { |
||
1171 | if ($sspAssetToCompanyBusinessUnit->getFkSspAsset() === $sspAssetTransfer->getIdSspAsset()) { |
||
1172 | $sspAssetTransfer->addBusinessUnitAssignment( |
||
1173 | (new SspAssetBusinessUnitAssignmentTransfer()) |
||
1174 | ->setCompanyBusinessUnit( |
||
1175 | (new CompanyBusinessUnitTransfer()) |
||
1176 | ->setIdCompanyBusinessUnit($sspAssetToCompanyBusinessUnit->getFkCompanyBusinessUnit()) |
||
1177 | ->setName($sspAssetToCompanyBusinessUnit->getSpyCompanyBusinessUnit()->getName()) |
||
1178 | ->setCompany( |
||
1179 | (new CompanyTransfer()) |
||
1180 | ->setIdCompany($sspAssetToCompanyBusinessUnit->getSpyCompanyBusinessUnit()->getFkCompany()) |
||
1181 | ->setName($sspAssetToCompanyBusinessUnit->getSpyCompanyBusinessUnit()->getCompany()->getName()), |
||
1182 | ), |
||
1183 | ) |
||
1184 | ->setAssignedAt($sspAssetToCompanyBusinessUnit->getCreatedAt()->format('Y-m-d H:i:s')), |
||
1185 | ); |
||
1186 | } |
||
1187 | } |
||
1188 | } |
||
1189 | |||
1190 | return $sspAssetCollectionTransfer; |
||
1191 | } |
||
1192 | |||
1193 | /** |
||
1194 | * @param \Orm\Zed\SelfServicePortal\Persistence\SpySspAssetQuery $sspAssetQuery |
||
1195 | * @param \Generated\Shared\Transfer\SspAssetCriteriaTransfer $sspAssetCriteriaTransfer |
||
1196 | * |
||
1197 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpySspAssetQuery |
||
1198 | */ |
||
1199 | protected function applyAssetConditions( |
||
1200 | SpySspAssetQuery $sspAssetQuery, |
||
1201 | SspAssetCriteriaTransfer $sspAssetCriteriaTransfer |
||
1202 | ): SpySspAssetQuery { |
||
1203 | $sspAssetConditionsTransfer = $sspAssetCriteriaTransfer->getSspAssetConditions(); |
||
1204 | |||
1205 | if (!$sspAssetConditionsTransfer) { |
||
1206 | return $sspAssetQuery; |
||
1207 | } |
||
1208 | |||
1209 | if ($sspAssetConditionsTransfer->getSspAssetIds()) { |
||
1210 | $sspAssetQuery->filterByIdSspAsset_In($sspAssetConditionsTransfer->getSspAssetIds()); |
||
1211 | } |
||
1212 | |||
1213 | if ($sspAssetConditionsTransfer->getReferences()) { |
||
1214 | $sspAssetQuery->filterByReference_In($sspAssetConditionsTransfer->getReferences()); |
||
1215 | } |
||
1216 | |||
1217 | if ($sspAssetConditionsTransfer->getStatus()) { |
||
1218 | $sspAssetQuery->filterByStatus($sspAssetConditionsTransfer->getStatus()); |
||
1219 | } |
||
1220 | |||
1221 | if ($sspAssetConditionsTransfer->getAssignedBusinessUnitId()) { |
||
1222 | $sspAssetQuery |
||
1223 | ->useSpySspAssetToCompanyBusinessUnitExistsQuery() |
||
1224 | ->filterByFkCompanyBusinessUnit($sspAssetConditionsTransfer->getAssignedBusinessUnitId()) |
||
1225 | ->endUse(); |
||
1226 | } |
||
1227 | |||
1228 | if ($sspAssetConditionsTransfer->getAssignedBusinessUnitCompanyId()) { |
||
1229 | $sspAssetQuery |
||
1230 | ->useSpySspAssetToCompanyBusinessUnitExistsQuery() |
||
1231 | ->useSpyCompanyBusinessUnitQuery() |
||
1232 | ->filterByFkCompany($sspAssetConditionsTransfer->getAssignedBusinessUnitCompanyId()) |
||
1233 | ->endUse() |
||
1234 | ->endUse(); |
||
1235 | } |
||
1236 | |||
1237 | if ($sspAssetConditionsTransfer->getStatuses() !== []) { |
||
1238 | $sspAssetQuery->filterByStatus_In($sspAssetConditionsTransfer->getStatuses()); |
||
1239 | } |
||
1240 | |||
1241 | if ($sspAssetConditionsTransfer->getSearchText()) { |
||
1242 | $searchText = '%' . $sspAssetConditionsTransfer->getSearchTextOrFail() . '%'; |
||
1243 | $sspAssetQuery->filterByName_Like($searchText) |
||
1244 | ->_or() |
||
1245 | ->filterByReference_Like($searchText) |
||
1246 | ->_or() |
||
1247 | ->filterBySerialNumber_Like($searchText); |
||
1248 | } |
||
1249 | |||
1250 | if ($sspAssetConditionsTransfer->getImageFileIds() !== []) { |
||
1251 | $sspAssetQuery->filterByFkImageFile_In($sspAssetConditionsTransfer->getImageFileIds()); |
||
1252 | } |
||
1253 | |||
1254 | return $sspAssetQuery; |
||
1255 | } |
||
1256 | |||
1257 | /** |
||
1258 | * @param \Orm\Zed\SelfServicePortal\Persistence\SpySspAssetQuery $sspAssetQuery |
||
1259 | * @param \Generated\Shared\Transfer\SspAssetCriteriaTransfer $sspAssetCriteriaTransfer |
||
1260 | * |
||
1261 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpySspAssetQuery |
||
1262 | */ |
||
1263 | protected function applyAssetSorting( |
||
1264 | SpySspAssetQuery $sspAssetQuery, |
||
1265 | SspAssetCriteriaTransfer $sspAssetCriteriaTransfer |
||
1266 | ): SpySspAssetQuery { |
||
1267 | $sortCollection = $sspAssetCriteriaTransfer->getSortCollection(); |
||
1268 | |||
1269 | if (!$sortCollection->count()) { |
||
1270 | return $sspAssetQuery; |
||
1271 | } |
||
1272 | |||
1273 | foreach ($sortCollection as $sort) { |
||
1274 | $field = $sort->getFieldOrFail(); |
||
1275 | if ($field === SspAssetTransfer::CREATED_DATE) { |
||
1276 | $field = SpySspAssetTableMap::COL_CREATED_AT; |
||
1277 | } |
||
1278 | $direction = $sort->getIsAscending() ? Criteria::ASC : Criteria::DESC; |
||
1279 | $sspAssetQuery->orderBy($field, $direction); |
||
1280 | } |
||
1281 | |||
1282 | return $sspAssetQuery; |
||
1283 | } |
||
1284 | |||
1285 | /** |
||
1286 | * @param \Propel\Runtime\ActiveQuery\ModelCriteria $query |
||
1287 | * @param \Generated\Shared\Transfer\PaginationTransfer|null $paginationTransfer |
||
1288 | * |
||
1289 | * @return \Propel\Runtime\Collection\Collection |
||
1290 | */ |
||
1291 | protected function getAssetPaginatedCollection(ModelCriteria $query, ?PaginationTransfer $paginationTransfer = null): Collection |
||
1292 | { |
||
1293 | if ($paginationTransfer === null) { |
||
1294 | return $query->find(); |
||
1295 | } |
||
1296 | |||
1297 | $page = $paginationTransfer |
||
1298 | ->requirePage() |
||
1299 | ->getPageOrFail(); |
||
1300 | |||
1301 | $maxPerPage = $paginationTransfer |
||
1302 | ->requireMaxPerPage() |
||
1303 | ->getMaxPerPageOrFail(); |
||
1304 | |||
1305 | $paginationModel = $query->paginate($page, $maxPerPage); |
||
1306 | |||
1307 | $paginationTransfer->setNbResults($paginationModel->getNbResults()); |
||
1308 | $paginationTransfer->setFirstIndex($paginationModel->getFirstIndex()); |
||
1309 | $paginationTransfer->setLastIndex($paginationModel->getLastIndex()); |
||
1310 | $paginationTransfer->setFirstPage($paginationModel->getFirstPage()); |
||
1311 | $paginationTransfer->setLastPage($paginationModel->getLastPage()); |
||
1312 | $paginationTransfer->setNextPage($paginationModel->getNextPage()); |
||
1313 | $paginationTransfer->setPreviousPage($paginationModel->getPreviousPage()); |
||
1314 | |||
1315 | return $paginationModel->getResults(); |
||
1316 | } |
||
1317 | |||
1318 | /** |
||
1319 | * @param array<int> $salesOrderItemIds |
||
1320 | * |
||
1321 | * @return array<int, \Generated\Shared\Transfer\SspAssetTransfer> |
||
1322 | */ |
||
1323 | public function getSspAssetsIndexedByIdSalesOrderItem(array $salesOrderItemIds): array |
||
1324 | { |
||
1325 | if (!$salesOrderItemIds) { |
||
1326 | return []; |
||
1327 | } |
||
1328 | |||
1329 | $salesOrderItemSspAssetQuery = $this->getFactory() |
||
1330 | ->getSalesOrderItemSspAssetQuery() |
||
1331 | ->filterByFkSalesOrderItem_In($salesOrderItemIds); |
||
1332 | |||
1333 | $salesOrderItemSspAssetEntities = $salesOrderItemSspAssetQuery->find(); |
||
1334 | $sspAssetsIndexedByIdSalesOrderItem = []; |
||
1335 | |||
1336 | foreach ($salesOrderItemSspAssetEntities as $salesOrderItemSspAssetEntity) { |
||
1337 | $sspAssetTransfer = new SspAssetTransfer(); |
||
1338 | $sspAssetTransfer->fromArray($salesOrderItemSspAssetEntity->toArray(), true); |
||
1339 | |||
1340 | $sspAssetsIndexedByIdSalesOrderItem[(int)$salesOrderItemSspAssetEntity->getFkSalesOrderItem()] = $sspAssetTransfer; |
||
1341 | } |
||
1342 | |||
1343 | return $sspAssetsIndexedByIdSalesOrderItem; |
||
1344 | } |
||
1345 | |||
1346 | /** |
||
1347 | * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery $query |
||
1348 | * @param \Generated\Shared\Transfer\SspServiceCriteriaTransfer $sspServiceCriteriaTransfer |
||
1349 | * |
||
1350 | * @return \Propel\Runtime\Collection\Collection<\Orm\Zed\Sales\Persistence\SpySalesOrderItem> |
||
1351 | */ |
||
1352 | protected function getServicePaginatedCollection( |
||
1380 | } |
||
1381 | } |
||
1382 |