1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Domain\Repository; |
14
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Doc; |
16
|
|
|
use Kitodo\Dlf\Common\Helper; |
17
|
|
|
use Kitodo\Dlf\Common\Solr; |
18
|
|
|
use Kitodo\Dlf\Common\SolrSearch; |
19
|
|
|
use Kitodo\Dlf\Domain\Model\Document; |
20
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
21
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
23
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
24
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
25
|
|
|
|
26
|
|
|
class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* The controller settings passed to the repository for some special actions. |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
* @access protected |
33
|
|
|
*/ |
34
|
|
|
protected $settings; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Find one document by given parameters |
38
|
|
|
* |
39
|
|
|
* GET parameters may be: |
40
|
|
|
* |
41
|
|
|
* - 'id': the uid of the document |
42
|
|
|
* - 'location': the URL of the location of the XML file |
43
|
|
|
* - 'recordId': the record_id of the document |
44
|
|
|
* |
45
|
|
|
* Currently used by EXT:slub_digitalcollections |
46
|
|
|
* |
47
|
|
|
* @param array $parameters |
48
|
|
|
* |
49
|
|
|
* @return \Kitodo\Dlf\Domain\Model\Document|null |
50
|
|
|
*/ |
51
|
|
|
public function findOneByParameters($parameters) |
52
|
|
|
{ |
53
|
|
|
$doc = null; |
54
|
|
|
$document = null; |
55
|
|
|
|
56
|
|
|
if (isset($parameters['id']) && MathUtility::canBeInterpretedAsInteger($parameters['id'])) { |
57
|
|
|
|
58
|
|
|
$document = $this->findOneByIdAndSettings($parameters['id']); |
59
|
|
|
|
60
|
|
|
} else if (isset($parameters['recordId'])) { |
61
|
|
|
|
62
|
|
|
$document = $this->findOneByRecordId($parameters['recordId']); |
|
|
|
|
63
|
|
|
|
64
|
|
|
} else if (isset($parameters['location']) && GeneralUtility::isValidUrl($parameters['location'])) { |
65
|
|
|
|
66
|
|
|
$doc = Doc::getInstance($parameters['location'], [], true); |
67
|
|
|
|
68
|
|
|
if ($doc->recordId) { |
69
|
|
|
$document = $this->findOneByRecordId($doc->recordId); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ($document === null) { |
73
|
|
|
// create new (dummy) Document object |
74
|
|
|
$document = GeneralUtility::makeInstance(Document::class); |
75
|
|
|
$document->setLocation($parameters['location']); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($document !== null && $doc === null) { |
81
|
|
|
$doc = Doc::getInstance($document->getLocation(), [], true); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($doc !== null) { |
85
|
|
|
$document->setDoc($doc); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $document; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Find the oldest document |
93
|
|
|
* |
94
|
|
|
* @return \Kitodo\Dlf\Domain\Model\Document|null |
95
|
|
|
*/ |
96
|
|
|
public function findOldestDocument() |
97
|
|
|
{ |
98
|
|
|
$query = $this->createQuery(); |
99
|
|
|
|
100
|
|
|
$query->setOrderings(['tstamp' => QueryInterface::ORDER_ASCENDING]); |
101
|
|
|
$query->setLimit(1); |
102
|
|
|
|
103
|
|
|
return $query->execute()->getFirst(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param int $partOf |
108
|
|
|
* @param \Kitodo\Dlf\Domain\Model\Structure $structure |
109
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
110
|
|
|
*/ |
111
|
|
|
public function getChildrenOfYearAnchor($partOf, $structure) |
112
|
|
|
{ |
113
|
|
|
$query = $this->createQuery(); |
114
|
|
|
|
115
|
|
|
$query->matching($query->equals('structure', $structure)); |
116
|
|
|
$query->matching($query->equals('partof', $partOf)); |
117
|
|
|
|
118
|
|
|
$query->setOrderings([ |
119
|
|
|
'mets_orderlabel' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING |
120
|
|
|
]); |
121
|
|
|
|
122
|
|
|
return $query->execute(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Finds all documents for the given settings |
127
|
|
|
* |
128
|
|
|
* @param int $uid |
129
|
|
|
* @param array $settings |
130
|
|
|
* |
131
|
|
|
* @return \Kitodo\Dlf\Domain\Model\Document|null |
132
|
|
|
*/ |
133
|
|
|
public function findOneByIdAndSettings($uid, $settings = []) |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
$settings = ['documentSets' => $uid]; |
136
|
|
|
|
137
|
|
|
return $this->findDocumentsBySettings($settings)->getFirst(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Finds all documents for the given settings |
142
|
|
|
* |
143
|
|
|
* @param array $settings |
144
|
|
|
* |
145
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
146
|
|
|
*/ |
147
|
|
|
public function findDocumentsBySettings($settings = []) |
148
|
|
|
{ |
149
|
|
|
$query = $this->createQuery(); |
150
|
|
|
|
151
|
|
|
$constraints = []; |
152
|
|
|
|
153
|
|
|
if ($settings['documentSets']) { |
154
|
|
|
$constraints[] = $query->in('uid', GeneralUtility::intExplode(',', $settings['documentSets'])); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if (isset($settings['excludeOther']) && (int) $settings['excludeOther'] === 0) { |
158
|
|
|
$query->getQuerySettings()->setRespectStoragePage(false); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if (count($constraints)) { |
162
|
|
|
$query->matching( |
163
|
|
|
$query->logicalAnd($constraints) |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return $query->execute(); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Finds all documents for the given collections |
172
|
|
|
* |
173
|
|
|
* @param array $collections |
174
|
|
|
* @param int $limit |
175
|
|
|
* |
176
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
177
|
|
|
*/ |
178
|
|
|
public function findAllByCollectionsLimited($collections, $limit = 50) |
179
|
|
|
{ |
180
|
|
|
$query = $this->createQuery(); |
181
|
|
|
|
182
|
|
|
// order by start_date -> start_time... |
183
|
|
|
$query->setOrderings( |
184
|
|
|
['tstamp' => QueryInterface::ORDER_DESCENDING] |
185
|
|
|
); |
186
|
|
|
|
187
|
|
|
$constraints = []; |
188
|
|
|
if ($collections) { |
|
|
|
|
189
|
|
|
$constraints[] = $query->in('collections.uid', $collections); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if (count($constraints)) { |
193
|
|
|
$query->matching( |
194
|
|
|
$query->logicalAnd($constraints) |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
if ($limit > 0) { |
199
|
|
|
$query->setLimit((int) $limit); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
return $query->execute(); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Count the titles and volumes for statistics |
207
|
|
|
* |
208
|
|
|
* Volumes are documents that are both |
209
|
|
|
* a) "leaf" elements i.e. partof != 0 |
210
|
|
|
* b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) |
211
|
|
|
|
212
|
|
|
* @param array $settings |
213
|
|
|
* |
214
|
|
|
* @return array |
215
|
|
|
*/ |
216
|
|
|
public function getStatisticsForSelectedCollection($settings) |
217
|
|
|
{ |
218
|
|
|
if ($settings['collections']) { |
219
|
|
|
// Include only selected collections. |
220
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
221
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
222
|
|
|
|
223
|
|
|
$countTitles = $queryBuilder |
224
|
|
|
->count('tx_dlf_documents.uid') |
225
|
|
|
->from('tx_dlf_documents') |
226
|
|
|
->innerJoin( |
227
|
|
|
'tx_dlf_documents', |
228
|
|
|
'tx_dlf_relations', |
229
|
|
|
'tx_dlf_relations_joins', |
230
|
|
|
$queryBuilder->expr()->eq( |
231
|
|
|
'tx_dlf_relations_joins.uid_local', |
232
|
|
|
'tx_dlf_documents.uid' |
233
|
|
|
) |
234
|
|
|
) |
235
|
|
|
->innerJoin( |
236
|
|
|
'tx_dlf_relations_joins', |
237
|
|
|
'tx_dlf_collections', |
238
|
|
|
'tx_dlf_collections_join', |
239
|
|
|
$queryBuilder->expr()->eq( |
240
|
|
|
'tx_dlf_relations_joins.uid_foreign', |
241
|
|
|
'tx_dlf_collections_join.uid' |
242
|
|
|
) |
243
|
|
|
) |
244
|
|
|
->where( |
245
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['storagePid'])), |
246
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections_join.pid', intval($settings['storagePid'])), |
247
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.partof', 0), |
248
|
|
|
$queryBuilder->expr()->in('tx_dlf_collections_join.uid', $queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', $settings['collections']), Connection::PARAM_INT_ARRAY)), |
249
|
|
|
$queryBuilder->expr()->eq('tx_dlf_relations_joins.ident', $queryBuilder->createNamedParameter('docs_colls')) |
250
|
|
|
) |
251
|
|
|
->execute() |
252
|
|
|
->fetchColumn(0); |
253
|
|
|
|
254
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
255
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
256
|
|
|
$subQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
257
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
258
|
|
|
|
259
|
|
|
$subQuery = $subQueryBuilder |
260
|
|
|
->select('tx_dlf_documents.partof') |
261
|
|
|
->from('tx_dlf_documents') |
262
|
|
|
->where( |
263
|
|
|
$subQueryBuilder->expr()->neq('tx_dlf_documents.partof', 0) |
264
|
|
|
) |
265
|
|
|
->groupBy('tx_dlf_documents.partof') |
266
|
|
|
->getSQL(); |
267
|
|
|
|
268
|
|
|
$countVolumes = $queryBuilder |
269
|
|
|
->count('tx_dlf_documents.uid') |
270
|
|
|
->from('tx_dlf_documents') |
271
|
|
|
->innerJoin( |
272
|
|
|
'tx_dlf_documents', |
273
|
|
|
'tx_dlf_relations', |
274
|
|
|
'tx_dlf_relations_joins', |
275
|
|
|
$queryBuilder->expr()->eq( |
276
|
|
|
'tx_dlf_relations_joins.uid_local', |
277
|
|
|
'tx_dlf_documents.uid' |
278
|
|
|
) |
279
|
|
|
) |
280
|
|
|
->innerJoin( |
281
|
|
|
'tx_dlf_relations_joins', |
282
|
|
|
'tx_dlf_collections', |
283
|
|
|
'tx_dlf_collections_join', |
284
|
|
|
$queryBuilder->expr()->eq( |
285
|
|
|
'tx_dlf_relations_joins.uid_foreign', |
286
|
|
|
'tx_dlf_collections_join.uid' |
287
|
|
|
) |
288
|
|
|
) |
289
|
|
|
->where( |
290
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['storagePid'])), |
291
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections_join.pid', intval($settings['storagePid'])), |
292
|
|
|
$queryBuilder->expr()->notIn('tx_dlf_documents.uid', $subQuery), |
293
|
|
|
$queryBuilder->expr()->in('tx_dlf_collections_join.uid', $queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', $settings['collections']), Connection::PARAM_INT_ARRAY)), |
294
|
|
|
$queryBuilder->expr()->eq('tx_dlf_relations_joins.ident', $queryBuilder->createNamedParameter('docs_colls')) |
295
|
|
|
) |
296
|
|
|
->execute() |
297
|
|
|
->fetchColumn(0); |
298
|
|
|
} else { |
299
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
300
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
301
|
|
|
|
302
|
|
|
// Include all collections. |
303
|
|
|
$countTitles = $queryBuilder |
304
|
|
|
->count('tx_dlf_documents.uid') |
305
|
|
|
->from('tx_dlf_documents') |
306
|
|
|
->where( |
307
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['storagePid'])), |
308
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.partof', 0), |
309
|
|
|
Helper::whereExpression('tx_dlf_documents') |
310
|
|
|
) |
311
|
|
|
->execute() |
312
|
|
|
->fetchColumn(0); |
313
|
|
|
|
314
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
315
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
316
|
|
|
$subQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
317
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
318
|
|
|
|
319
|
|
|
$subQuery = $subQueryBuilder |
320
|
|
|
->select('tx_dlf_documents.partof') |
321
|
|
|
->from('tx_dlf_documents') |
322
|
|
|
->where( |
323
|
|
|
$subQueryBuilder->expr()->neq('tx_dlf_documents.partof', 0) |
324
|
|
|
) |
325
|
|
|
->groupBy('tx_dlf_documents.partof') |
326
|
|
|
->getSQL(); |
327
|
|
|
|
328
|
|
|
$countVolumes = $queryBuilder |
329
|
|
|
->count('tx_dlf_documents.uid') |
330
|
|
|
->from('tx_dlf_documents') |
331
|
|
|
->where( |
332
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['storagePid'])), |
333
|
|
|
$queryBuilder->expr()->notIn('tx_dlf_documents.uid', $subQuery) |
334
|
|
|
) |
335
|
|
|
->execute() |
336
|
|
|
->fetchColumn(0); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
return ['titles' => $countTitles, 'volumes' => $countVolumes]; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Build table of contents |
344
|
|
|
* |
345
|
|
|
* @param int $uid |
346
|
|
|
* @param int $pid |
347
|
|
|
* @param array $settings |
348
|
|
|
* |
349
|
|
|
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
350
|
|
|
*/ |
351
|
|
|
public function getTableOfContentsFromDb($uid, $pid, $settings) |
352
|
|
|
{ |
353
|
|
|
// Build table of contents from database. |
354
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
355
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
356
|
|
|
|
357
|
|
|
$excludeOtherWhere = ''; |
358
|
|
|
if ($settings['excludeOther']) { |
359
|
|
|
$excludeOtherWhere = 'tx_dlf_documents.pid=' . intval($settings['storagePid']); |
360
|
|
|
} |
361
|
|
|
// Check if there are any metadata to suggest. |
362
|
|
|
$result = $queryBuilder |
363
|
|
|
->select( |
364
|
|
|
'tx_dlf_documents.uid AS uid', |
365
|
|
|
'tx_dlf_documents.title AS title', |
366
|
|
|
'tx_dlf_documents.volume AS volume', |
367
|
|
|
'tx_dlf_documents.mets_label AS mets_label', |
368
|
|
|
'tx_dlf_documents.mets_orderlabel AS mets_orderlabel', |
369
|
|
|
'tx_dlf_structures_join.index_name AS type' |
370
|
|
|
) |
371
|
|
|
->innerJoin( |
372
|
|
|
'tx_dlf_documents', |
373
|
|
|
'tx_dlf_structures', |
374
|
|
|
'tx_dlf_structures_join', |
375
|
|
|
$queryBuilder->expr()->eq( |
376
|
|
|
'tx_dlf_structures_join.uid', |
377
|
|
|
'tx_dlf_documents.structure' |
378
|
|
|
) |
379
|
|
|
) |
380
|
|
|
->from('tx_dlf_documents') |
381
|
|
|
->where( |
382
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($uid)), |
383
|
|
|
$queryBuilder->expr()->eq('tx_dlf_structures_join.pid', intval($pid)), |
384
|
|
|
$excludeOtherWhere |
385
|
|
|
) |
386
|
|
|
->addOrderBy('tx_dlf_documents.volume_sorting') |
387
|
|
|
->addOrderBy('tx_dlf_documents.mets_orderlabel') |
388
|
|
|
->execute(); |
389
|
|
|
return $result; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Find one document by given settings and identifier |
394
|
|
|
* |
395
|
|
|
* @param array $settings |
396
|
|
|
* @param array $parameters |
397
|
|
|
* |
398
|
|
|
* @return array The found document object |
399
|
|
|
*/ |
400
|
|
|
public function getOaiRecord($settings, $parameters) |
401
|
|
|
{ |
402
|
|
|
$where = ''; |
403
|
|
|
|
404
|
|
|
if (!$settings['show_userdefined']) { |
405
|
|
|
$where .= 'AND tx_dlf_collections.fe_cruser_id=0 '; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
409
|
|
|
->getConnectionForTable('tx_dlf_documents'); |
410
|
|
|
|
411
|
|
|
$sql = 'SELECT `tx_dlf_documents`.*, GROUP_CONCAT(DISTINCT `tx_dlf_collections`.`oai_name` ORDER BY `tx_dlf_collections`.`oai_name` SEPARATOR " ") AS `collections` ' . |
412
|
|
|
'FROM `tx_dlf_documents` ' . |
413
|
|
|
'INNER JOIN `tx_dlf_relations` ON `tx_dlf_relations`.`uid_local` = `tx_dlf_documents`.`uid` ' . |
414
|
|
|
'INNER JOIN `tx_dlf_collections` ON `tx_dlf_collections`.`uid` = `tx_dlf_relations`.`uid_foreign` ' . |
415
|
|
|
'WHERE `tx_dlf_documents`.`record_id` = ? ' . |
416
|
|
|
'AND `tx_dlf_relations`.`ident`="docs_colls" ' . |
417
|
|
|
$where; |
418
|
|
|
|
419
|
|
|
$values = [ |
420
|
|
|
$parameters['identifier'] |
421
|
|
|
]; |
422
|
|
|
|
423
|
|
|
$types = [ |
424
|
|
|
Connection::PARAM_STR |
425
|
|
|
]; |
426
|
|
|
|
427
|
|
|
// Create a prepared statement for the passed SQL query, bind the given params with their binding types and execute the query |
428
|
|
|
$statement = $connection->executeQuery($sql, $values, $types); |
429
|
|
|
|
430
|
|
|
return $statement->fetch(); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Finds all documents for the given settings |
435
|
|
|
* |
436
|
|
|
* @param array $settings |
437
|
|
|
* @param array $documentsToProcess |
438
|
|
|
* |
439
|
|
|
* @return array The found document objects |
440
|
|
|
*/ |
441
|
|
|
public function getOaiDocumentList($settings, $documentsToProcess) |
|
|
|
|
442
|
|
|
{ |
443
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
444
|
|
|
->getConnectionForTable('tx_dlf_documents'); |
445
|
|
|
|
446
|
|
|
$sql = 'SELECT `tx_dlf_documents`.*, GROUP_CONCAT(DISTINCT `tx_dlf_collections`.`oai_name` ORDER BY `tx_dlf_collections`.`oai_name` SEPARATOR " ") AS `collections` ' . |
447
|
|
|
'FROM `tx_dlf_documents` ' . |
448
|
|
|
'INNER JOIN `tx_dlf_relations` ON `tx_dlf_relations`.`uid_local` = `tx_dlf_documents`.`uid` ' . |
449
|
|
|
'INNER JOIN `tx_dlf_collections` ON `tx_dlf_collections`.`uid` = `tx_dlf_relations`.`uid_foreign` ' . |
450
|
|
|
'WHERE `tx_dlf_documents`.`uid` IN ( ? ) ' . |
451
|
|
|
'AND `tx_dlf_relations`.`ident`="docs_colls" ' . |
452
|
|
|
'AND ' . Helper::whereExpression('tx_dlf_collections') . ' ' . |
453
|
|
|
'GROUP BY `tx_dlf_documents`.`uid` '; |
454
|
|
|
|
455
|
|
|
$values = [ |
456
|
|
|
$documentsToProcess, |
457
|
|
|
]; |
458
|
|
|
|
459
|
|
|
$types = [ |
460
|
|
|
Connection::PARAM_INT_ARRAY, |
461
|
|
|
]; |
462
|
|
|
|
463
|
|
|
// Create a prepared statement for the passed SQL query, bind the given params with their binding types and execute the query |
464
|
|
|
$documents = $connection->executeQuery($sql, $values, $types); |
465
|
|
|
|
466
|
|
|
return $documents; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Finds all documents with given uids |
471
|
|
|
* |
472
|
|
|
* @param array $uids |
473
|
|
|
* @param array $checkPartof Whether or not to also match $uids against partof. |
474
|
|
|
* |
475
|
|
|
* @return array |
476
|
|
|
*/ |
477
|
|
|
public function findAllByUids($uids, $checkPartof = false) |
478
|
|
|
{ |
479
|
|
|
// get all documents from db we are talking about |
480
|
|
|
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
481
|
|
|
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_documents'); |
482
|
|
|
// Fetch document info for UIDs in $documentSet from DB |
483
|
|
|
$exprDocumentMatchesUid = $queryBuilder->expr()->in('tx_dlf_documents.uid', $uids); |
484
|
|
|
if ($checkPartof) { |
485
|
|
|
$exprDocumentMatchesUid = $queryBuilder->expr()->orX( |
486
|
|
|
$exprDocumentMatchesUid, |
487
|
|
|
$queryBuilder->expr()->in('tx_dlf_documents.partof', $uids) |
488
|
|
|
); |
489
|
|
|
} |
490
|
|
|
$kitodoDocuments = $queryBuilder |
491
|
|
|
->select( |
492
|
|
|
'tx_dlf_documents.uid AS uid', |
493
|
|
|
'tx_dlf_documents.title AS title', |
494
|
|
|
'tx_dlf_documents.structure AS structure', |
495
|
|
|
'tx_dlf_documents.thumbnail AS thumbnail', |
496
|
|
|
'tx_dlf_documents.volume_sorting AS volumeSorting', |
497
|
|
|
'tx_dlf_documents.mets_orderlabel AS metsOrderlabel', |
498
|
|
|
'tx_dlf_documents.partof AS partOf' |
499
|
|
|
) |
500
|
|
|
->from('tx_dlf_documents') |
501
|
|
|
->where( |
502
|
|
|
$queryBuilder->expr()->in('tx_dlf_documents.pid', $this->settings['storagePid']), |
503
|
|
|
$exprDocumentMatchesUid |
504
|
|
|
) |
505
|
|
|
->addOrderBy('tx_dlf_documents.volume_sorting', 'asc') |
506
|
|
|
->addOrderBy('tx_dlf_documents.mets_orderlabel', 'asc') |
507
|
|
|
->execute(); |
508
|
|
|
|
509
|
|
|
$allDocuments = []; |
510
|
|
|
$documentStructures = Helper::getDocumentStructures($this->settings['storagePid']); |
511
|
|
|
// Process documents in a usable array structure |
512
|
|
|
while ($resArray = $kitodoDocuments->fetch()) { |
513
|
|
|
$resArray['structure'] = $documentStructures[$resArray['structure']]; |
514
|
|
|
$allDocuments[$resArray['uid']] = $resArray; |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
return $allDocuments; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* |
522
|
|
|
* |
523
|
|
|
* @param array $uids |
524
|
|
|
* |
525
|
|
|
* @return array |
526
|
|
|
*/ |
527
|
|
|
public function findChildrenOfEach(array $uids) |
528
|
|
|
{ |
529
|
|
|
$allDocuments = $this->findAllByUids($uids, true); |
|
|
|
|
530
|
|
|
|
531
|
|
|
$result = []; |
532
|
|
|
foreach ($allDocuments as $doc) { |
533
|
|
|
if ($doc['partOf']) { |
534
|
|
|
$result[$doc['partOf']][] = $doc; |
535
|
|
|
} |
536
|
|
|
} |
537
|
|
|
return $result; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* Find all documents with given collection from Solr |
542
|
|
|
* |
543
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult|\Kitodo\Dlf\Domain\Model\Collection $collection |
544
|
|
|
* @param array $settings |
545
|
|
|
* @param array $searchParams |
546
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $listedMetadata |
547
|
|
|
* @return array |
548
|
|
|
*/ |
549
|
|
|
public function findSolrByCollection($collection, $settings, $searchParams, $listedMetadata = null) |
550
|
|
|
{ |
551
|
|
|
// set settings global inside this repository |
552
|
|
|
// (may be necessary when SolrSearch calls back) |
553
|
|
|
$this->settings = $settings; |
554
|
|
|
|
555
|
|
|
$search = new SolrSearch($this, $collection, $settings, $searchParams, $listedMetadata); |
556
|
|
|
$search->prepare(); |
557
|
|
|
return $search; |
|
|
|
|
558
|
|
|
} |
559
|
|
|
} |
560
|
|
|
|