|
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\Helper; |
|
16
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
|
19
|
|
|
|
|
20
|
|
|
class CollectionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Set the default ordering. This is applied to findAll(), too. |
|
24
|
|
|
* |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $defaultOrderings = [ |
|
28
|
|
|
'label' => QueryInterface::ORDER_ASCENDING, |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Finds all collections |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $uids separated by comma |
|
35
|
|
|
* |
|
36
|
|
|
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
public function findAllByUids($uids) |
|
39
|
|
|
{ |
|
40
|
|
|
$query = $this->createQuery(); |
|
41
|
|
|
|
|
42
|
|
|
$constraints = []; |
|
43
|
|
|
$constraints[] = $query->in('uid', $uids); |
|
44
|
|
|
|
|
45
|
|
|
if (count($constraints)) { |
|
46
|
|
|
$query->matching($query->logicalAnd($constraints)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $query->execute(); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getCollectionForMetadata($pages) |
|
53
|
|
|
{ |
|
54
|
|
|
// Get list of collections to show. |
|
55
|
|
|
$query = $this->createQuery(); |
|
56
|
|
|
|
|
57
|
|
|
$query->matching($query->equals('pid', $pages)); |
|
58
|
|
|
|
|
59
|
|
|
return $query->execute(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Finds all collection for the given settings |
|
64
|
|
|
* |
|
65
|
|
|
* @param array $settings |
|
66
|
|
|
* |
|
67
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
|
68
|
|
|
*/ |
|
69
|
|
|
public function findCollectionsBySettings($settings = []) |
|
70
|
|
|
{ |
|
71
|
|
|
$query = $this->createQuery(); |
|
72
|
|
|
|
|
73
|
|
|
$constraints = []; |
|
74
|
|
|
|
|
75
|
|
|
if ($settings['collections']) { |
|
76
|
|
|
$constraints[] = $query->in('uid', GeneralUtility::intExplode(',', $settings['collections'])); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if ($settings['index_name']) { |
|
80
|
|
|
$constraints[] = $query->in('index_name', $settings['index_name']); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// do not find user created collections (used by oai-pmh plugin) |
|
84
|
|
|
if (!$settings['show_userdefined']) { |
|
85
|
|
|
$constraints[] = $query->equals('fe_cruser_id', 0); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// do not find collections without oai_name set (used by oai-pmh plugin) |
|
89
|
|
|
if ($settings['hideEmptyOaiNames']) { |
|
90
|
|
|
$constraints[] = $query->logicalNot($query->equals('oai_name', '')); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (count($constraints)) { |
|
94
|
|
|
$query->matching( |
|
95
|
|
|
$query->logicalAnd($constraints) |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
// order by oai_name |
|
100
|
|
|
$query->setOrderings( |
|
101
|
|
|
array('oai_name' => QueryInterface::ORDER_ASCENDING) |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
return $query->execute(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getIndexNameForSolr($settings, $set) |
|
108
|
|
|
{ |
|
109
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
110
|
|
|
->getQueryBuilderForTable('tx_dlf_collections'); |
|
111
|
|
|
|
|
112
|
|
|
$where = ''; |
|
113
|
|
|
if (!$settings['show_userdefined']) { |
|
114
|
|
|
$where = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0); |
|
115
|
|
|
} |
|
116
|
|
|
// For SOLR we need the index_name of the collection, |
|
117
|
|
|
// For DB Query we need the UID of the collection |
|
118
|
|
|
$result = $queryBuilder |
|
119
|
|
|
->select( |
|
120
|
|
|
'tx_dlf_collections.index_name AS index_name', |
|
121
|
|
|
'tx_dlf_collections.uid AS uid', |
|
122
|
|
|
'tx_dlf_collections.index_search as index_query' |
|
123
|
|
|
) |
|
124
|
|
|
->from('tx_dlf_collections') |
|
125
|
|
|
->where( |
|
126
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])), |
|
127
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections.oai_name', |
|
128
|
|
|
$queryBuilder->expr()->literal($set)), |
|
129
|
|
|
$where, |
|
130
|
|
|
Helper::whereExpression('tx_dlf_collections') |
|
131
|
|
|
) |
|
132
|
|
|
->setMaxResults(1) |
|
133
|
|
|
->execute(); |
|
134
|
|
|
|
|
135
|
|
|
return $result; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|