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 TYPO3\CMS\Core\Utility\GeneralUtility; |
16
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
17
|
|
|
use Kitodo\Dlf\Common\Helper; |
18
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
19
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
20
|
|
|
|
21
|
|
|
class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
public function findByUidAndPartOf($uid, $partOf) |
25
|
|
|
{ |
26
|
|
|
$query = $this->createQuery(); |
27
|
|
|
|
28
|
|
|
$query->matching($query->equals('uid', $uid)); |
29
|
|
|
$query->matching($query->equals('partof', $partOf)); |
30
|
|
|
|
31
|
|
|
return $query->execute(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function oaiDocumentByTstmp($pid) { |
35
|
|
|
$query = $this->createQuery(); |
36
|
|
|
|
37
|
|
|
$query->matching($query->equals('pid', $pid)); |
38
|
|
|
$query->setOrderings(['tstmp' => QueryInterface::ORDER_ASCENDING]); |
39
|
|
|
$query->setLimit(1); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param $structure |
44
|
|
|
* @param $partOf |
45
|
|
|
* @param $indexName (can be issue or year) |
|
|
|
|
46
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
47
|
|
|
*/ |
48
|
|
|
public function getChildrenOfYearAnchor($structure, $partOf, $indexName) |
49
|
|
|
{ |
50
|
|
|
$query = $this->createQuery(); |
51
|
|
|
|
52
|
|
|
$query->matching($query->equals('structure', Helper::getUidFromIndexName($indexName, 'tx_dlf_structures', $structure))); |
53
|
|
|
$query->matching($query->equals('partof', $partOf)); |
54
|
|
|
|
55
|
|
|
$query->setOrderings([ |
56
|
|
|
'mets_orderlabel' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
return $query->execute(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getDocumentsFromDocumentset($documentSet, $pages) { |
63
|
|
|
$query = $this->createQuery(); |
64
|
|
|
|
65
|
|
|
$query->matching($query->equals('pid', $pages)); |
66
|
|
|
$query->matching($query->in('uid', $documentSet)); |
67
|
|
|
|
68
|
|
|
return $query->execute(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getDocumentsForFeeds($settings, $collectionUid) { |
72
|
|
|
$additionalWhere = ''; |
73
|
|
|
// Check for pre-selected collections. |
74
|
|
|
if (!empty($collectionUid)) { |
75
|
|
|
$additionalWhere = 'tx_dlf_collections.uid=' . intval($collectionUid); |
76
|
|
|
} elseif (!empty($settings['collections'])) { |
77
|
|
|
$additionalWhere = 'tx_dlf_collections.uid IN (' . implode(',', GeneralUtility::intExplode(',', $settings['collections'])) . ')'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// get documents |
81
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
82
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
83
|
|
|
|
84
|
|
|
$result = $queryBuilder |
85
|
|
|
->select( |
86
|
|
|
'tx_dlf_documents.uid AS uid', |
87
|
|
|
'tx_dlf_documents.partof AS partof', |
88
|
|
|
'tx_dlf_documents.title AS title', |
89
|
|
|
'tx_dlf_documents.volume AS volume', |
90
|
|
|
'tx_dlf_documents.author AS author', |
91
|
|
|
'tx_dlf_documents.record_id AS record_id', |
92
|
|
|
'tx_dlf_documents.tstamp AS tstamp', |
93
|
|
|
'tx_dlf_documents.crdate AS crdate' |
94
|
|
|
) |
95
|
|
|
->from('tx_dlf_documents') |
96
|
|
|
->join( |
97
|
|
|
'tx_dlf_documents', |
98
|
|
|
'tx_dlf_relations', |
99
|
|
|
'tx_dlf_documents_collections_mm', |
100
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_local')) |
101
|
|
|
) |
102
|
|
|
->join( |
103
|
|
|
'tx_dlf_documents_collections_mm', |
104
|
|
|
'tx_dlf_collections', |
105
|
|
|
'tx_dlf_collections', |
106
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_foreign')) |
107
|
|
|
) |
108
|
|
|
->where( |
109
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', $queryBuilder->createNamedParameter((int) $settings['pages'])), |
110
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents_collections_mm.ident', $queryBuilder->createNamedParameter('docs_colls')), |
111
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections.pid', $queryBuilder->createNamedParameter((int) $settings['pages'])), |
112
|
|
|
$additionalWhere |
113
|
|
|
) |
114
|
|
|
->groupBy('tx_dlf_documents.uid') |
115
|
|
|
->orderBy('tx_dlf_documents.tstamp', 'DESC') |
116
|
|
|
->setMaxResults((int) $settings['limit']) |
117
|
|
|
->execute(); |
118
|
|
|
|
119
|
|
|
return $result; |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getStatisticsForCollection($settings) { |
124
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
125
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
126
|
|
|
|
127
|
|
|
// Include all collections. |
128
|
|
|
$countTitles = $queryBuilder |
129
|
|
|
->count('tx_dlf_documents.uid') |
130
|
|
|
->from('tx_dlf_documents') |
131
|
|
|
->where( |
132
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['pages'])), |
133
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.partof', 0), |
134
|
|
|
Helper::whereExpression('tx_dlf_documents') |
135
|
|
|
) |
136
|
|
|
->execute() |
137
|
|
|
->fetchColumn(0); |
138
|
|
|
|
139
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
140
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
141
|
|
|
$subQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
142
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
143
|
|
|
|
144
|
|
|
$subQuery = $subQueryBuilder |
145
|
|
|
->select('tx_dlf_documents.partof') |
146
|
|
|
->from('tx_dlf_documents') |
147
|
|
|
->where( |
148
|
|
|
$subQueryBuilder->expr()->neq('tx_dlf_documents.partof', 0) |
149
|
|
|
) |
150
|
|
|
->groupBy('tx_dlf_documents.partof') |
151
|
|
|
->getSQL(); |
152
|
|
|
|
153
|
|
|
$countVolumes = $queryBuilder |
154
|
|
|
->count('tx_dlf_documents.uid') |
155
|
|
|
->from('tx_dlf_documents') |
156
|
|
|
->where( |
157
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['pages'])), |
158
|
|
|
$queryBuilder->expr()->notIn('tx_dlf_documents.uid', $subQuery) |
159
|
|
|
) |
160
|
|
|
->execute() |
161
|
|
|
->fetchColumn(0); |
162
|
|
|
|
163
|
|
|
return ['titles' => $countTitles, 'volumes' => $countVolumes]; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getStatisticsForSelectedCollection($settings) { |
167
|
|
|
// Include only selected collections. |
168
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
169
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
170
|
|
|
|
171
|
|
|
$countTitles = $queryBuilder |
172
|
|
|
->count('tx_dlf_documents.uid') |
173
|
|
|
->from('tx_dlf_documents') |
174
|
|
|
->innerJoin( |
175
|
|
|
'tx_dlf_documents', |
176
|
|
|
'tx_dlf_relations', |
177
|
|
|
'tx_dlf_relations_joins', |
178
|
|
|
$queryBuilder->expr()->eq( |
179
|
|
|
'tx_dlf_relations_joins.uid_local', |
180
|
|
|
'tx_dlf_documents.uid' |
181
|
|
|
) |
182
|
|
|
) |
183
|
|
|
->innerJoin( |
184
|
|
|
'tx_dlf_relations_joins', |
185
|
|
|
'tx_dlf_collections', |
186
|
|
|
'tx_dlf_collections_join', |
187
|
|
|
$queryBuilder->expr()->eq( |
188
|
|
|
'tx_dlf_relations_joins.uid_foreign', |
189
|
|
|
'tx_dlf_collections_join.uid' |
190
|
|
|
) |
191
|
|
|
) |
192
|
|
|
->where( |
193
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['pages'])), |
194
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections_join.pid', intval($settings['pages'])), |
195
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.partof', 0), |
196
|
|
|
$queryBuilder->expr()->in('tx_dlf_collections_join.uid', |
197
|
|
|
$queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', |
198
|
|
|
$settings['collections']), Connection::PARAM_INT_ARRAY)), |
199
|
|
|
$queryBuilder->expr()->eq('tx_dlf_relations_joins.ident', |
200
|
|
|
$queryBuilder->createNamedParameter('docs_colls')) |
201
|
|
|
) |
202
|
|
|
->execute() |
203
|
|
|
->fetchColumn(0); |
204
|
|
|
|
205
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
206
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
207
|
|
|
$subQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
208
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
209
|
|
|
|
210
|
|
|
$subQuery = $subQueryBuilder |
211
|
|
|
->select('tx_dlf_documents.partof') |
212
|
|
|
->from('tx_dlf_documents') |
213
|
|
|
->where( |
214
|
|
|
$subQueryBuilder->expr()->neq('tx_dlf_documents.partof', 0) |
215
|
|
|
) |
216
|
|
|
->groupBy('tx_dlf_documents.partof') |
217
|
|
|
->getSQL(); |
218
|
|
|
|
219
|
|
|
$countVolumes = $queryBuilder |
220
|
|
|
->count('tx_dlf_documents.uid') |
221
|
|
|
->from('tx_dlf_documents') |
222
|
|
|
->innerJoin( |
223
|
|
|
'tx_dlf_documents', |
224
|
|
|
'tx_dlf_relations', |
225
|
|
|
'tx_dlf_relations_joins', |
226
|
|
|
$queryBuilder->expr()->eq( |
227
|
|
|
'tx_dlf_relations_joins.uid_local', |
228
|
|
|
'tx_dlf_documents.uid' |
229
|
|
|
) |
230
|
|
|
) |
231
|
|
|
->innerJoin( |
232
|
|
|
'tx_dlf_relations_joins', |
233
|
|
|
'tx_dlf_collections', |
234
|
|
|
'tx_dlf_collections_join', |
235
|
|
|
$queryBuilder->expr()->eq( |
236
|
|
|
'tx_dlf_relations_joins.uid_foreign', |
237
|
|
|
'tx_dlf_collections_join.uid' |
238
|
|
|
) |
239
|
|
|
) |
240
|
|
|
->where( |
241
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['pages'])), |
242
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections_join.pid', intval($settings['pages'])), |
243
|
|
|
$queryBuilder->expr()->notIn('tx_dlf_documents.uid', $subQuery), |
244
|
|
|
$queryBuilder->expr()->in('tx_dlf_collections_join.uid', |
245
|
|
|
$queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', |
246
|
|
|
$settings['collections']), Connection::PARAM_INT_ARRAY)), |
247
|
|
|
$queryBuilder->expr()->eq('tx_dlf_relations_joins.ident', |
248
|
|
|
$queryBuilder->createNamedParameter('docs_colls')) |
249
|
|
|
) |
250
|
|
|
->execute() |
251
|
|
|
->fetchColumn(0); |
252
|
|
|
|
253
|
|
|
return ['titles' => $countTitles, 'volumes' => $countVolumes]; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
public function getTableOfContentsFromDb($uid, $pid, $settings) { |
257
|
|
|
// Build table of contents from database. |
258
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
259
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
260
|
|
|
|
261
|
|
|
$excludeOtherWhere = ''; |
262
|
|
|
if ($settings['excludeOther']) { |
263
|
|
|
$excludeOtherWhere = 'tx_dlf_documents.pid=' . intval($settings['pages']); |
264
|
|
|
} |
265
|
|
|
// Check if there are any metadata to suggest. |
266
|
|
|
$result = $queryBuilder |
267
|
|
|
->select( |
268
|
|
|
'tx_dlf_documents.uid AS uid', |
269
|
|
|
'tx_dlf_documents.title AS title', |
270
|
|
|
'tx_dlf_documents.volume AS volume', |
271
|
|
|
'tx_dlf_documents.mets_label AS mets_label', |
272
|
|
|
'tx_dlf_documents.mets_orderlabel AS mets_orderlabel', |
273
|
|
|
'tx_dlf_structures_join.index_name AS type' |
274
|
|
|
) |
275
|
|
|
->innerJoin( |
276
|
|
|
'tx_dlf_documents', |
277
|
|
|
'tx_dlf_structures', |
278
|
|
|
'tx_dlf_structures_join', |
279
|
|
|
$queryBuilder->expr()->eq( |
280
|
|
|
'tx_dlf_structures_join.uid', |
281
|
|
|
'tx_dlf_documents.structure' |
282
|
|
|
) |
283
|
|
|
) |
284
|
|
|
->from('tx_dlf_documents') |
285
|
|
|
->where( |
286
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($uid)), |
287
|
|
|
$queryBuilder->expr()->eq('tx_dlf_structures_join.pid', intval($pid)), |
288
|
|
|
$excludeOtherWhere |
289
|
|
|
) |
290
|
|
|
->addOrderBy('tx_dlf_documents.volume_sorting') |
291
|
|
|
->addOrderBy('tx_dlf_documents.mets_orderlabel') |
292
|
|
|
->execute(); |
293
|
|
|
return $result; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
public function getOaiRecord($settings) { |
297
|
|
|
$where = ''; |
298
|
|
|
if (!$settings['show_userdefined']) { |
299
|
|
|
$where .= 'AND tx_dlf_collections.fe_cruser_id=0 '; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_dlf_documents'); |
303
|
|
|
|
304
|
|
|
$sql = 'SELECT `tx_dlf_documents`.*, GROUP_CONCAT(DISTINCT `tx_dlf_collections`.`oai_name` ORDER BY `tx_dlf_collections`.`oai_name` SEPARATOR " ") AS `collections` ' . |
305
|
|
|
'FROM `tx_dlf_documents` ' . |
306
|
|
|
'INNER JOIN `tx_dlf_relations` ON `tx_dlf_relations`.`uid_local` = `tx_dlf_documents`.`uid` ' . |
307
|
|
|
'INNER JOIN `tx_dlf_collections` ON `tx_dlf_collections`.`uid` = `tx_dlf_relations`.`uid_foreign` ' . |
308
|
|
|
'WHERE `tx_dlf_documents`.`record_id` = ? ' . |
309
|
|
|
'AND `tx_dlf_documents`.`pid` = ? ' . |
310
|
|
|
'AND `tx_dlf_collections`.`pid` = ? ' . |
311
|
|
|
'AND `tx_dlf_relations`.`ident`="docs_colls" ' . |
312
|
|
|
$where . |
313
|
|
|
'AND ' . Helper::whereExpression('tx_dlf_collections'); |
314
|
|
|
|
315
|
|
|
$values = [ |
316
|
|
|
$this->parameters['identifier'], |
|
|
|
|
317
|
|
|
$settings['pages'], |
318
|
|
|
$settings['pages'] |
319
|
|
|
]; |
320
|
|
|
$types = [ |
321
|
|
|
Connection::PARAM_STR, |
322
|
|
|
Connection::PARAM_INT, |
323
|
|
|
Connection::PARAM_INT |
324
|
|
|
]; |
325
|
|
|
// Create a prepared statement for the passed SQL query, bind the given params with their binding types and execute the query |
326
|
|
|
$statement = $connection->executeQuery($sql, $values, $types); |
327
|
|
|
|
328
|
|
|
$resArray = $statement->fetch(); |
329
|
|
|
|
330
|
|
|
return $resArray; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
public function getOaiMetadataFormats($pid, $id) { |
334
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
335
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
336
|
|
|
|
337
|
|
|
// Check given identifier. |
338
|
|
|
$result = $queryBuilder |
339
|
|
|
->select('tx_dlf_documents.*') |
340
|
|
|
->from('tx_dlf_documents') |
341
|
|
|
->where( |
342
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($pid)), |
343
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.record_id', |
344
|
|
|
$queryBuilder->expr()->literal($id)) |
345
|
|
|
) |
346
|
|
|
->orderBy('tx_dlf_documents.tstamp') |
347
|
|
|
->setMaxResults(1) |
348
|
|
|
->execute(); |
349
|
|
|
|
350
|
|
|
$resArray = $result->fetch(); |
351
|
|
|
return $resArray; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
public function getOaiDocumentList($settings, $documentsToProcess) { |
355
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
356
|
|
|
->getConnectionForTable('tx_dlf_documents'); |
357
|
|
|
|
358
|
|
|
$sql = 'SELECT `tx_dlf_documents`.*, GROUP_CONCAT(DISTINCT `tx_dlf_collections`.`oai_name` ORDER BY `tx_dlf_collections`.`oai_name` SEPARATOR " ") AS `collections` ' . |
359
|
|
|
'FROM `tx_dlf_documents` ' . |
360
|
|
|
'INNER JOIN `tx_dlf_relations` ON `tx_dlf_relations`.`uid_local` = `tx_dlf_documents`.`uid` ' . |
361
|
|
|
'INNER JOIN `tx_dlf_collections` ON `tx_dlf_collections`.`uid` = `tx_dlf_relations`.`uid_foreign` ' . |
362
|
|
|
'WHERE `tx_dlf_documents`.`uid` IN ( ? ) ' . |
363
|
|
|
'AND `tx_dlf_documents`.`pid` = ? ' . |
364
|
|
|
'AND `tx_dlf_collections`.`pid` = ? ' . |
365
|
|
|
'AND `tx_dlf_relations`.`ident`="docs_colls" ' . |
366
|
|
|
'AND ' . Helper::whereExpression('tx_dlf_collections') . ' ' . |
367
|
|
|
'GROUP BY `tx_dlf_documents`.`uid` ' . |
368
|
|
|
'LIMIT ?'; |
369
|
|
|
|
370
|
|
|
$values = [ |
371
|
|
|
$documentsToProcess, |
372
|
|
|
$settings['pages'], |
373
|
|
|
$settings['pages'], |
374
|
|
|
$settings['limit'] |
375
|
|
|
]; |
376
|
|
|
$types = [ |
377
|
|
|
Connection::PARAM_INT_ARRAY, |
378
|
|
|
Connection::PARAM_INT, |
379
|
|
|
Connection::PARAM_INT, |
380
|
|
|
Connection::PARAM_INT |
381
|
|
|
]; |
382
|
|
|
// Create a prepared statement for the passed SQL query, bind the given params with their binding types and execute the query |
383
|
|
|
$documents = $connection->executeQuery($sql, $values, $types); |
384
|
|
|
return $documents; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
} |