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\Communication\CompanyFile\Table; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\FileAttachmentViewDetailTableCriteriaTransfer; |
11
|
|
|
use Orm\Zed\CompanyBusinessUnit\Persistence\Map\SpyCompanyBusinessUnitTableMap; |
12
|
|
|
use Orm\Zed\Customer\Persistence\Map\SpyCustomerTableMap; |
13
|
|
|
use Orm\Zed\FileManager\Persistence\Map\SpyFileTableMap; |
14
|
|
|
use Orm\Zed\FileManager\Persistence\SpyFileQuery; |
15
|
|
|
use Orm\Zed\SelfServicePortal\Persistence\Map\SpyCompanyBusinessUnitFileTableMap; |
16
|
|
|
use Orm\Zed\SelfServicePortal\Persistence\Map\SpyCompanyUserFileTableMap; |
17
|
|
|
use Orm\Zed\SelfServicePortal\Persistence\Map\SpySspAssetFileTableMap; |
18
|
|
|
use Orm\Zed\SelfServicePortal\Persistence\Map\SpySspAssetTableMap; |
19
|
|
|
use PDO; |
20
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
21
|
|
|
use Propel\Runtime\Adapter\Pdo\PdoAdapter; |
22
|
|
|
use Propel\Runtime\Connection\ConnectionInterface; |
23
|
|
|
use Propel\Runtime\Connection\StatementWrapper; |
24
|
|
|
use Propel\Runtime\Map\DatabaseMap; |
25
|
|
|
use Propel\Runtime\Propel; |
26
|
|
|
use Spryker\Service\UtilDateTime\UtilDateTimeServiceInterface; |
27
|
|
|
use Spryker\Service\UtilText\Model\Url\Url; |
28
|
|
|
use Spryker\Zed\Gui\Communication\Table\AbstractTable; |
29
|
|
|
use Spryker\Zed\Gui\Communication\Table\TableConfiguration; |
30
|
|
|
use SprykerFeature\Shared\SelfServicePortal\SelfServicePortalConfig as SharedSelfServicePortalConfig; |
31
|
|
|
use SprykerFeature\Zed\SelfServicePortal\Communication\CompanyFile\Form\UnlinkFileForm; |
32
|
|
|
use SprykerFeature\Zed\SelfServicePortal\Communication\CompanyFile\Formatter\TimeZoneFormatterInterface; |
33
|
|
|
use SprykerFeature\Zed\SelfServicePortal\Communication\Controller\FileAbstractController; |
34
|
|
|
|
35
|
|
|
class ViewFileDetailTable extends AbstractTable |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected const HEADER_BUSINESS_ENTITY_NAME = 'Business entity name'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected const HEADER_BUSINESS_ENTITY_TYPE = 'Business entity type'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected const HEADER_DATE_ATTACHED = 'Date Attached'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected const COL_ATTACHED_AT = 'attached_at'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected const COL_ENTITY_NAME = 'entity_name'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected const COL_ENTITY_TYPE = 'entity_type'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
protected const COL_ID_FILE = 'id_file'; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
protected const COL_ENTITY_ID = 'entity_id'; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var string |
79
|
|
|
*/ |
80
|
|
|
protected const COL_ACTIONS = 'Actions'; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
protected const COL_ENTITY_TYPE_COMPANY = '\'company\''; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
protected const COL_ENTITY_TYPE_COMPANY_BUSINESS_UNIT = '\'company_business_unit\''; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var string |
94
|
|
|
*/ |
95
|
|
|
protected const COL_ENTITY_TYPE_COMPANY_USER = '\'company_user\''; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var string |
99
|
|
|
*/ |
100
|
|
|
protected const COL_ENTITY_TYPE_ASSET = '\'ssp_asset\''; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var string |
104
|
|
|
*/ |
105
|
|
|
protected const SORTABLE_COLUMN = 'column'; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var string |
109
|
|
|
*/ |
110
|
|
|
protected const SORTABLE_DIRECTION = 'dir'; |
111
|
|
|
|
112
|
|
|
public function __construct( |
113
|
|
|
protected SpyFileQuery $fileQuery, |
114
|
|
|
protected int $idFile, |
115
|
|
|
protected UtilDateTimeServiceInterface $utilDateTimeService, |
116
|
|
|
protected TimeZoneFormatterInterface $timeZoneFormatter, |
117
|
|
|
protected FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer |
118
|
|
|
) { |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
protected function configure(TableConfiguration $config): TableConfiguration |
122
|
|
|
{ |
123
|
|
|
$config->setUrl(Url::generate( |
124
|
|
|
'/table', |
125
|
|
|
$this->getRequest()->query->all(), |
126
|
|
|
)); |
127
|
|
|
|
128
|
|
|
$config->setHeader([ |
129
|
|
|
static::COL_ENTITY_NAME => static::HEADER_BUSINESS_ENTITY_NAME, |
130
|
|
|
static::COL_ENTITY_TYPE => static::HEADER_BUSINESS_ENTITY_TYPE, |
131
|
|
|
static::COL_ATTACHED_AT => static::HEADER_DATE_ATTACHED, |
132
|
|
|
static::COL_ACTIONS => static::COL_ACTIONS, |
133
|
|
|
]); |
134
|
|
|
|
135
|
|
|
$config->setSortable([ |
136
|
|
|
static::COL_ENTITY_NAME, |
137
|
|
|
static::COL_ENTITY_TYPE, |
138
|
|
|
static::COL_ATTACHED_AT, |
139
|
|
|
]); |
140
|
|
|
|
141
|
|
|
$config->addRawColumn(static::COL_ACTIONS); |
142
|
|
|
|
143
|
|
|
return $config; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config |
148
|
|
|
* |
149
|
|
|
* @return array<int, array<string, mixed>> |
150
|
|
|
*/ |
151
|
|
|
protected function prepareData(TableConfiguration $config): array |
152
|
|
|
{ |
153
|
|
|
$countQuery = $this->prepareRowCountQuery($this->fileAttachmentViewDetailTableCriteriaTransfer); |
154
|
|
|
$countQuery->execute(); |
155
|
|
|
$totalRows = $countQuery->fetchColumn(); |
156
|
|
|
|
157
|
|
|
$query = $this->prepareRawQuery($config, $this->fileAttachmentViewDetailTableCriteriaTransfer); |
158
|
|
|
$query->execute(); |
159
|
|
|
$queryResults = $query->fetchAll(PDO::FETCH_ASSOC); |
160
|
|
|
|
161
|
|
|
$this->setTotal((int)$totalRows); |
162
|
|
|
$this->setFiltered(count($queryResults)); |
163
|
|
|
|
164
|
|
|
$results = []; |
165
|
|
|
foreach ($queryResults as $item) { |
166
|
|
|
$results[] = $this->prepareTableRow($item); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $results; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param array<mixed> $item |
174
|
|
|
* |
175
|
|
|
* @return array<mixed> |
176
|
|
|
*/ |
177
|
|
|
protected function prepareTableRow(array $item): array |
178
|
|
|
{ |
179
|
|
|
return [ |
180
|
|
|
static::COL_ENTITY_NAME => $item[static::COL_ENTITY_NAME], |
181
|
|
|
static::COL_ENTITY_TYPE => $this->getEntityType($item), |
182
|
|
|
static::COL_ATTACHED_AT => $this->utilDateTimeService->formatDateTime($item[static::COL_ATTACHED_AT]), |
183
|
|
|
static::COL_ACTIONS => $this->buildLinks($item), |
184
|
|
|
]; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param array<mixed> $item |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
protected function getEntityType(array $item): string |
193
|
|
|
{ |
194
|
|
|
$translator = $this->getTranslator(); |
195
|
|
|
if (!$translator) { |
196
|
|
|
return ''; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return sprintf('%s', $translator->trans($item[static::COL_ENTITY_TYPE])); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param array<mixed> $item |
204
|
|
|
* |
205
|
|
|
* @return string |
206
|
|
|
*/ |
207
|
|
|
protected function buildLinks(array $item): string |
208
|
|
|
{ |
209
|
|
|
$buttons = []; |
210
|
|
|
$buttons[] = $this->generateFormButton( |
211
|
|
|
Url::generate(FileAbstractController::URL_PATH_UNLINK_FILE, [ |
212
|
|
|
FileAbstractController::REQUEST_PARAM_ID_FILE => $item[static::COL_ID_FILE], |
213
|
|
|
FileAbstractController::REQUEST_PARAM_ENTITY_TYPE => $item[static::COL_ENTITY_TYPE], |
214
|
|
|
FileAbstractController::REQUEST_PARAM_ENTITY_ID => $item[static::COL_ENTITY_ID], |
215
|
|
|
]), |
216
|
|
|
'Unlink', |
217
|
|
|
UnlinkFileForm::class, |
218
|
|
|
[ |
219
|
|
|
'class' => 'btn btn-sm btn-outline safe-submit btn-remove', |
220
|
|
|
'icon' => 'fa fa-unlink', |
221
|
|
|
'data-qa' => 'unlink-button', |
222
|
|
|
], |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
return implode(' ', $buttons); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
protected function prepareCompanyBusinessUnitFileQuery( |
229
|
|
|
FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer |
230
|
|
|
): SpyFileQuery { |
231
|
|
|
$companyBusinessUnitFileQuery = $this->fileQuery::create() |
232
|
|
|
->filterByIdFile($this->idFile) |
233
|
|
|
->withColumn(SpyFileTableMap::COL_ID_FILE, static::COL_ID_FILE) |
234
|
|
|
->useSpyCompanyBusinessUnitFileQuery(null, Criteria::LEFT_JOIN) |
235
|
|
|
->withColumn(SpyCompanyBusinessUnitFileTableMap::COL_CREATED_AT, static::COL_ATTACHED_AT) |
236
|
|
|
->withColumn(SpyCompanyBusinessUnitFileTableMap::COL_FK_COMPANY_BUSINESS_UNIT, static::COL_ENTITY_ID) |
237
|
|
|
->useCompanyBusinessUnitQuery() |
238
|
|
|
->withColumn(SpyCompanyBusinessUnitTableMap::COL_NAME, static::COL_ENTITY_NAME) |
239
|
|
|
->withColumn(static::COL_ENTITY_TYPE_COMPANY_BUSINESS_UNIT, static::COL_ENTITY_TYPE) |
240
|
|
|
->filterByName_Like($this->getSearchString()) |
241
|
|
|
->endUse() |
242
|
|
|
->endUse() |
243
|
|
|
->select([ |
244
|
|
|
static::COL_ID_FILE, |
245
|
|
|
static::COL_ATTACHED_AT, |
246
|
|
|
static::COL_ENTITY_ID, |
247
|
|
|
static::COL_ENTITY_NAME, |
248
|
|
|
static::COL_ENTITY_TYPE, |
249
|
|
|
]); |
250
|
|
|
|
251
|
|
|
if ($fileAttachmentViewDetailTableCriteriaTransfer->getDateFrom()) { |
252
|
|
|
// @phpstan-ignore-next-line |
253
|
|
|
$companyBusinessUnitFileQuery |
254
|
|
|
->useSpyCompanyBusinessUnitFileQuery() |
255
|
|
|
->filterByCreatedAt($this->timeZoneFormatter->formatToUTCFromLocalTimeZone($fileAttachmentViewDetailTableCriteriaTransfer->getDateFrom()), Criteria::GREATER_EQUAL) |
256
|
|
|
->endUse(); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
if ($fileAttachmentViewDetailTableCriteriaTransfer->getDateTo()) { |
260
|
|
|
// @phpstan-ignore-next-line |
261
|
|
|
$companyBusinessUnitFileQuery |
262
|
|
|
->useSpyCompanyBusinessUnitFileQuery() |
263
|
|
|
->filterByCreatedAt($this->timeZoneFormatter->formatToUTCFromLocalTimeZone($fileAttachmentViewDetailTableCriteriaTransfer->getDateTo()), Criteria::LESS_THAN) |
264
|
|
|
->endUse(); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
// @phpstan-ignore-next-line |
268
|
|
|
return $companyBusinessUnitFileQuery; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
protected function prepareCompanyUserFileQuery( |
272
|
|
|
FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer |
273
|
|
|
): SpyFileQuery { |
274
|
|
|
$companyUserFileQuery = $this->fileQuery::create() |
275
|
|
|
->filterByIdFile($this->idFile) |
276
|
|
|
->withColumn(SpyFileTableMap::COL_ID_FILE, static::COL_ID_FILE) |
277
|
|
|
->useSpyCompanyUserFileQuery(null, Criteria::LEFT_JOIN) |
278
|
|
|
->withColumn(SpyCompanyUserFileTableMap::COL_CREATED_AT, static::COL_ATTACHED_AT) |
279
|
|
|
->withColumn(SpyCompanyUserFileTableMap::COL_FK_COMPANY_USER, static::COL_ENTITY_ID) |
280
|
|
|
->useCompanyUserQuery() |
281
|
|
|
->useCustomerQuery() |
282
|
|
|
->withColumn(sprintf("CONCAT(%s, ' ', %s)", SpyCustomerTableMap::COL_FIRST_NAME, SpyCustomerTableMap::COL_LAST_NAME), static::COL_ENTITY_NAME) |
283
|
|
|
->withColumn(static::COL_ENTITY_TYPE_COMPANY_USER, static::COL_ENTITY_TYPE) |
284
|
|
|
->condition( |
285
|
|
|
'firstAndLastNameCondition', |
286
|
|
|
sprintf("CONCAT(%s, ' ', %s) LIKE ?", SpyCustomerTableMap::COL_FIRST_NAME, SpyCustomerTableMap::COL_LAST_NAME), |
287
|
|
|
$this->getSearchString(), |
288
|
|
|
) |
289
|
|
|
->combine(['firstAndLastNameCondition']) |
290
|
|
|
->endUse() |
291
|
|
|
->endUse() |
292
|
|
|
->endUse() |
293
|
|
|
->select([ |
294
|
|
|
static::COL_ID_FILE, |
295
|
|
|
static::COL_ATTACHED_AT, |
296
|
|
|
static::COL_ENTITY_ID, |
297
|
|
|
static::COL_ENTITY_NAME, |
298
|
|
|
static::COL_ENTITY_TYPE, |
299
|
|
|
]); |
300
|
|
|
|
301
|
|
|
if ($fileAttachmentViewDetailTableCriteriaTransfer->getDateFrom()) { |
302
|
|
|
// @phpstan-ignore-next-line |
303
|
|
|
$companyUserFileQuery |
304
|
|
|
->useSpyCompanyUserFileQuery() |
305
|
|
|
->filterByCreatedAt($this->timeZoneFormatter->formatToUTCFromLocalTimeZone($fileAttachmentViewDetailTableCriteriaTransfer->getDateFrom()), Criteria::GREATER_EQUAL) |
306
|
|
|
->endUse(); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
if ($fileAttachmentViewDetailTableCriteriaTransfer->getDateTo()) { |
310
|
|
|
// @phpstan-ignore-next-line |
311
|
|
|
$companyUserFileQuery |
312
|
|
|
->useSpyCompanyUserFileQuery() |
313
|
|
|
->filterByCreatedAt($this->timeZoneFormatter->formatToUTCFromLocalTimeZone($fileAttachmentViewDetailTableCriteriaTransfer->getDateTo()), Criteria::LESS_THAN) |
314
|
|
|
->endUse(); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
// @phpstan-ignore-next-line |
318
|
|
|
return $companyUserFileQuery; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
protected function prepareAssetFileQuery( |
322
|
|
|
FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer |
323
|
|
|
): SpyFileQuery { |
324
|
|
|
$fileQuery = $this->fileQuery::create(); |
325
|
|
|
|
326
|
|
|
$fileQuery |
327
|
|
|
->useSpySspAssetFileQuery() |
328
|
|
|
->filterByFkFile($this->idFile) |
329
|
|
|
->withColumn(SpyFileTableMap::COL_ID_FILE, static::COL_ID_FILE) |
330
|
|
|
->useSspAssetQuery() |
331
|
|
|
->withColumn(SpySspAssetFileTableMap::COL_CREATED_AT, static::COL_ATTACHED_AT) |
332
|
|
|
->withColumn(SpySspAssetTableMap::COL_ID_SSP_ASSET, static::COL_ENTITY_ID) |
333
|
|
|
->withColumn(SpySspAssetTableMap::COL_NAME, static::COL_ENTITY_NAME) |
334
|
|
|
->withColumn(static::COL_ENTITY_TYPE_ASSET, static::COL_ENTITY_TYPE) |
335
|
|
|
->endUse() |
336
|
|
|
->endUse() |
337
|
|
|
->select([ |
338
|
|
|
static::COL_ID_FILE, |
339
|
|
|
static::COL_ATTACHED_AT, |
340
|
|
|
static::COL_ENTITY_ID, |
341
|
|
|
static::COL_ENTITY_NAME, |
342
|
|
|
static::COL_ENTITY_TYPE, |
343
|
|
|
]); |
344
|
|
|
|
345
|
|
|
return $fileQuery; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @param \Generated\Shared\Transfer\FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer |
350
|
|
|
* |
351
|
|
|
* @return array<int, array<int, mixed>|string> |
352
|
|
|
*/ |
353
|
|
|
protected function getFileUnionQuerySql(FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer): array |
354
|
|
|
{ |
355
|
|
|
$companyFileParams = []; |
356
|
|
|
$companyBusinessUnitFileParams = []; |
357
|
|
|
$companyUserFileParams = []; |
358
|
|
|
$assetFileParams = []; |
359
|
|
|
$unionParts = []; |
360
|
|
|
|
361
|
|
|
if (!$fileAttachmentViewDetailTableCriteriaTransfer->getEntityType() || $fileAttachmentViewDetailTableCriteriaTransfer->getEntityType() === SharedSelfServicePortalConfig::ENTITY_TYPE_COMPANY_BUSINESS_UNIT) { |
362
|
|
|
$companyBusinessUnitFileQuery = $this->prepareCompanyBusinessUnitFileQuery($fileAttachmentViewDetailTableCriteriaTransfer); |
363
|
|
|
$unionParts[] = $companyBusinessUnitFileQuery->createSelectSql($companyBusinessUnitFileParams); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
if (!$fileAttachmentViewDetailTableCriteriaTransfer->getEntityType() || $fileAttachmentViewDetailTableCriteriaTransfer->getEntityType() === SharedSelfServicePortalConfig::ENTITY_TYPE_COMPANY_USER) { |
367
|
|
|
$companyUserFileQuery = $this->prepareCompanyUserFileQuery($fileAttachmentViewDetailTableCriteriaTransfer); |
368
|
|
|
$unionParts[] = $companyUserFileQuery->createSelectSql($companyUserFileParams); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
if (!$fileAttachmentViewDetailTableCriteriaTransfer->getEntityType() || $fileAttachmentViewDetailTableCriteriaTransfer->getEntityType() === SharedSelfServicePortalConfig::ENTITY_TYPE_SSP_ASSET) { |
372
|
|
|
$assetFileQuery = $this->prepareAssetFileQuery($fileAttachmentViewDetailTableCriteriaTransfer); |
373
|
|
|
$unionParts[] = $assetFileQuery->createSelectSql($assetFileParams); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
$unionSql = implode(' UNION ALL ', array_map(fn ($sql) => "($sql)", $unionParts)); |
377
|
|
|
|
378
|
|
|
return [ |
379
|
|
|
$unionSql, [$companyFileParams, $companyBusinessUnitFileParams, $companyUserFileParams, $assetFileParams], |
380
|
|
|
]; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
protected function prepareRawQuery( |
384
|
|
|
TableConfiguration $config, |
385
|
|
|
FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer |
386
|
|
|
): StatementWrapper { |
387
|
|
|
$orderBy = $this->getOrderBy($config); |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* @var array<int, mixed> $params |
391
|
|
|
* @var string $unionSql |
392
|
|
|
*/ |
393
|
|
|
[$unionSql, $params] = $this->getFileUnionQuerySql($fileAttachmentViewDetailTableCriteriaTransfer); |
394
|
|
|
|
395
|
|
|
$sql = <<<SQL |
396
|
|
|
SELECT * |
397
|
|
|
FROM ( |
398
|
|
|
$unionSql |
399
|
|
|
) AS unioned |
400
|
|
|
ORDER BY $orderBy |
401
|
|
|
LIMIT :limit OFFSET :offset |
402
|
|
|
SQL; |
403
|
|
|
|
404
|
|
|
$readConnection = $this->getReadConnection(); |
405
|
|
|
|
406
|
|
|
/** @var \Propel\Runtime\Connection\StatementWrapper $preparedStatement */ |
407
|
|
|
$preparedStatement = $readConnection->prepare($sql); |
408
|
|
|
|
409
|
|
|
$adapter = $this->getPropelAdapter(); |
410
|
|
|
$dbMap = $this->getPropelDatabaseMap(); |
411
|
|
|
|
412
|
|
|
foreach ($params as $param) { |
413
|
|
|
$adapter->bindValues($preparedStatement, $param, $dbMap); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
$preparedStatement->bindValue(':limit', $this->getLimit(), PDO::PARAM_INT); |
417
|
|
|
$preparedStatement->bindValue(':offset', $this->getOffset(), PDO::PARAM_INT); |
418
|
|
|
|
419
|
|
|
return $preparedStatement; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
protected function prepareRowCountQuery( |
423
|
|
|
FileAttachmentViewDetailTableCriteriaTransfer $fileAttachmentViewDetailTableCriteriaTransfer |
424
|
|
|
): StatementWrapper { |
425
|
|
|
/** |
426
|
|
|
* @var array<int, mixed> $params |
427
|
|
|
* @var string $unionSql |
428
|
|
|
*/ |
429
|
|
|
[$unionSql, $params] = $this->getFileUnionQuerySql($fileAttachmentViewDetailTableCriteriaTransfer); |
430
|
|
|
|
431
|
|
|
$sql = <<<SQL |
432
|
|
|
SELECT COUNT(*) AS total |
433
|
|
|
FROM ( |
434
|
|
|
$unionSql |
435
|
|
|
) AS unioned |
436
|
|
|
SQL; |
437
|
|
|
|
438
|
|
|
$connection = $this->getReadConnection(); |
439
|
|
|
|
440
|
|
|
/** @var \Propel\Runtime\Connection\StatementWrapper $preparedStatement */ |
441
|
|
|
$preparedStatement = $connection->prepare($sql); |
442
|
|
|
|
443
|
|
|
$adapter = $this->getPropelAdapter(); |
444
|
|
|
$dbMap = $this->getPropelDatabaseMap(); |
445
|
|
|
|
446
|
|
|
foreach ($params as $param) { |
447
|
|
|
$adapter->bindValues($preparedStatement, $param, $dbMap); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
return $preparedStatement; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
protected function getSearchString(): string |
454
|
|
|
{ |
455
|
|
|
$searchTerm = !$this->getSearchTerm() ?: $this->getSearchTerm()['value']; |
456
|
|
|
|
457
|
|
|
return sprintf('%s%%', mb_strtolower($searchTerm)); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
protected function getOrderBy(TableConfiguration $config): string |
461
|
|
|
{ |
462
|
|
|
$sortOrderCollection = $this->getOrders($config); |
463
|
|
|
$sortableColumns = $config->getSortable(); |
464
|
|
|
|
465
|
|
|
if (!$sortOrderCollection || !$sortableColumns) { |
466
|
|
|
return ''; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
$orderClauses = []; |
470
|
|
|
foreach ($sortOrderCollection as $sortOrderItem) { |
471
|
|
|
$columnKey = $sortOrderItem[static::SORTABLE_COLUMN] ?? null; |
472
|
|
|
$direction = mb_strtoupper($sortOrderItem[static::SORTABLE_DIRECTION] ?? Criteria::ASC); |
473
|
|
|
|
474
|
|
|
if (!isset($sortableColumns[$columnKey])) { |
475
|
|
|
continue; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
if (!in_array($direction, [Criteria::ASC, Criteria::DESC], true)) { |
479
|
|
|
$direction = Criteria::ASC; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
$orderClauses[] = sprintf( |
483
|
|
|
'unioned.%s %s', |
484
|
|
|
$sortableColumns[$columnKey], |
485
|
|
|
$direction, |
486
|
|
|
); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
return $orderClauses ? implode(', ', $orderClauses) : ''; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
protected function getPropelAdapter(): PdoAdapter |
493
|
|
|
{ |
494
|
|
|
/** @var \Propel\Runtime\Adapter\Pdo\PdoAdapter $adapter */ |
495
|
|
|
$adapter = Propel::getServiceContainer()->getAdapter(SpyFileTableMap::DATABASE_NAME); |
496
|
|
|
|
497
|
|
|
return $adapter; |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
protected function getPropelDatabaseMap(): DatabaseMap |
501
|
|
|
{ |
502
|
|
|
return Propel::getServiceContainer()->getDatabaseMap(SpyFileTableMap::DATABASE_NAME); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
protected function getReadConnection(): ConnectionInterface |
506
|
|
|
{ |
507
|
|
|
return Propel::getReadConnection(SpyFileTableMap::DATABASE_NAME); |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
|