Skip to content

Commit 6bc0a7a

Browse files
Merge branch '5.0.x' into 5.0.x
2 parents cfbb58e + fab5661 commit 6bc0a7a

File tree

16 files changed

+312
-205
lines changed

16 files changed

+312
-205
lines changed

Classes/Command/BaseCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ protected function saveToDatabase(Document $document): bool
212212
$document->setPlace(implode('; ', $metadata['place']));
213213
$document->setYear(implode('; ', $metadata['year']));
214214

215-
// Remove appended "valueURI" from authors' names for storing in database.
215+
// Get only authors' names for storing in database.
216216
foreach ($metadata['author'] as $i => $author) {
217-
$splitName = explode(pack('C', 31), $author);
218-
$metadata['author'][$i] = $splitName[0];
217+
if (is_array($author)) {
218+
$metadata['author'][$i] = $author['name'];
219+
}
219220
}
220221
$document->setAuthor($this->getAuthors($metadata['author']));
221222
$document->setThumbnail($doc->thumbnail ? : '');

Classes/Common/SolrPaginator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function __construct(
4242
protected function updatePaginatedItems(int $itemsPerPage, int $offset): void
4343
{
4444
$this->solrSearch->submit($offset, $itemsPerPage);
45-
$this->paginatedItems = $this->solrSearch->toArray();
45+
foreach ($this->solrSearch as $item) {
46+
$this->paginatedItems[] = $item;
47+
}
4648
}
4749

4850
protected function getTotalAmountOfItems(): int

Classes/Controller/CollectionController.php

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
use Kitodo\Dlf\Common\SolrPaginator;
1515
use Kitodo\Dlf\Common\Solr\Solr;
1616
use Kitodo\Dlf\Domain\Model\Collection;
17+
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
18+
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
1719
use TYPO3\CMS\Core\Pagination\SimplePagination;
1820
use TYPO3\CMS\Core\Utility\GeneralUtility;
1921
use TYPO3\CMS\Core\Utility\MathUtility;
20-
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
21-
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
2222

2323
/**
2424
* Controller class for the plugin 'Collection'.
@@ -66,6 +66,12 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
6666
$this->metadataRepository = $metadataRepository;
6767
}
6868

69+
/**
70+
* @access protected
71+
* @var array The current search parameter
72+
*/
73+
protected $searchParams = [];
74+
6975
/**
7076
* Show a list of collections
7177
*
@@ -75,10 +81,9 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
7581
*/
7682
public function listAction(): void
7783
{
78-
$solr = Solr::getInstance($this->settings['solrcore']);
79-
80-
if (!$solr->ready) {
81-
$this->logger->error('Apache Solr not available');
84+
// Quit without doing anything if required variables are not set.
85+
if (empty($this->settings['solrcore'])) {
86+
$this->logger->warning('Incomplete plugin configuration for SOLR. Please check the plugin settings for UID of SOLR core.');
8287
return;
8388
}
8489

@@ -103,7 +108,7 @@ public function listAction(): void
103108
}
104109
}
105110

106-
$processedCollections = $this->processCollections($collections, $solr);
111+
$processedCollections = $this->processCollections($collections);
107112

108113
// Randomize sorting?
109114
if (!empty($this->settings['randomize'])) {
@@ -118,35 +123,50 @@ public function listAction(): void
118123
*
119124
* @access protected
120125
*
121-
* @param Collection $collection The collection object
126+
* @param ?Collection $collection The collection object
122127
*
123128
* @return void
124129
*/
125-
public function showAction(Collection $collection): void
130+
public function showAction(?Collection $collection = null): void
126131
{
127-
$searchParams = $this->getParametersSafely('searchParameter');
132+
// Quit without doing anything if required variables are not set.
133+
if (empty($this->settings['solrcore'])) {
134+
$this->logger->warning('Incomplete plugin configuration for SOLR. Please check the plugin settings for UID of SOLR core.');
135+
return;
136+
}
128137

129-
// Instantiate the Solr. Without Solr present, we can't do anything.
130-
$solr = Solr::getInstance($this->settings['solrcore']);
131-
if (!$solr->ready) {
132-
$this->logger->error('Apache Solr not available');
138+
$this->searchParams = $this->getParametersSafely('searchParameter');
139+
$searchRequestData = GeneralUtility::_GPmerged('tx_dlf_search');
140+
141+
if (isset($searchRequestData['searchParameter']) && is_array($searchRequestData['searchParameter'])) {
142+
$this->searchParams = array_merge($this->searchParams ?: [], $searchRequestData['searchParameter']);
143+
$this->request->getAttribute('frontend.user')->setKey('ses', 'search', $this->searchParams);
144+
}
145+
146+
if (!isset($this->searchParams['collection']) && !isset($collection)) {
147+
$this->logger->warning('Collection is not set.');
133148
return;
134149
}
135150

136-
// Pagination of Results: Pass the currentPage to the fluid template to calculate current index of search result.
137-
$currentPage = $this->getParametersSafely('page');
138-
if (empty($currentPage)) {
139-
$currentPage = 1;
151+
// Get current page from request data because the parameter is shared between plugins
152+
$currentPage = $this->requestData['page'] ?? 1;
153+
154+
if (!isset($collection)) {
155+
$collection = $this->collectionRepository->findByUid($this->searchParams['collection']);
156+
} else {
157+
$this->searchParams['collection'] = $collection->getUid();
140158
}
141159

142-
$searchParams['collection'] = $collection->getUid();
143-
// If a targetPid is given, the results will be shown by ListView on the target page.
160+
// If a targetPid is given, the results will be shown by Collection on the target page.
144161
if (!empty($this->settings['targetPid'])) {
145-
$this->redirect('main', 'ListView', null,
162+
$this->redirect(
163+
'show',
164+
'Collection',
165+
null,
146166
[
147-
'searchParameter' => $searchParams,
148-
'page' => $currentPage
149-
], $this->settings['targetPid']
167+
'collection' => $collection
168+
],
169+
$this->settings['targetPid']
150170
);
151171
}
152172

@@ -156,27 +176,22 @@ public function showAction(Collection $collection): void
156176
// get all sortable metadata records
157177
$sortableMetadata = $this->metadataRepository->findByIsSortable(true);
158178

159-
// get all documents of given collection
160-
$solrResults = null;
161-
if (is_array($searchParams) && !empty($searchParams)) {
162-
$solrResults = $this->documentRepository->findSolrByCollection($collection, $this->settings, $searchParams, $listedMetadata);
179+
$solrResults = $this->documentRepository->findSolrByCollection($collection, $this->settings, $this->searchParams, $listedMetadata);
163180

164-
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
165-
if (empty($itemsPerPage)) {
166-
$itemsPerPage = 25;
167-
}
168-
$solrPaginator = new SolrPaginator($solrResults, $currentPage, $itemsPerPage);
169-
$simplePagination = new SimplePagination($solrPaginator);
181+
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'] ?? 25;
170182

171-
$pagination = $this->buildSimplePagination($simplePagination, $solrPaginator);
172-
$this->view->assignMultiple([ 'pagination' => $pagination, 'paginator' => $solrPaginator ]);
173-
}
183+
$solrPaginator = new SolrPaginator($solrResults, $currentPage, $itemsPerPage);
184+
$simplePagination = new SimplePagination($solrPaginator);
185+
186+
$pagination = $this->buildSimplePagination($simplePagination, $solrPaginator);
187+
$this->view->assignMultiple([ 'pagination' => $pagination, 'paginator' => $solrPaginator ]);
174188

175189
$this->view->assign('viewData', $this->viewData);
176-
$this->view->assign('documents', $solrResults);
190+
$this->view->assign('countDocuments', $solrResults->count());
191+
$this->view->assign('countResults', $solrResults->getNumFound());
177192
$this->view->assign('collection', $collection);
178193
$this->view->assign('page', $currentPage);
179-
$this->view->assign('lastSearch', $searchParams);
194+
$this->view->assign('lastSearch', $this->searchParams);
180195
$this->view->assign('sortableMetadata', $sortableMetadata);
181196
$this->view->assign('listedMetadata', $listedMetadata);
182197
}
@@ -194,12 +209,12 @@ public function showSortedAction(): void
194209
$searchParams = $this->getParametersSafely('searchParameter');
195210

196211
$collection = null;
197-
if ($searchParams['collection']['__identity'] && MathUtility::canBeInterpretedAsInteger($searchParams['collection']['__identity'])) {
198-
$collection = $this->collectionRepository->findByUid($searchParams['collection']['__identity']);
212+
if ($searchParams['collection'] && MathUtility::canBeInterpretedAsInteger($searchParams['collection'])) {
213+
$collection = $this->collectionRepository->findByUid($searchParams['collection']);
199214
}
200215

201216
// output is done by show action
202-
$this->forward('show', null, null, ['searchParameter' => $searchParams, 'collection' => $collection]);
217+
$this->forward('show', null, null, ['collection' => $collection, 'searchParams' => $searchParams]);
203218

204219
}
205220

@@ -209,12 +224,13 @@ public function showSortedAction(): void
209224
* @access private
210225
*
211226
* @param QueryResultInterface|array|object $collections to be processed
212-
* @param Solr $solr for query
213227
*
214228
* @return array
215229
*/
216-
private function processCollections($collections, Solr $solr): array
230+
private function processCollections($collections): array
217231
{
232+
$solr = Solr::getInstance($this->settings['solrcore']);
233+
218234
$processedCollections = [];
219235

220236
// Process results.

Classes/Controller/ListViewController.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
namespace Kitodo\Dlf\Controller;
1313

1414
use Kitodo\Dlf\Common\SolrPaginator;
15-
use TYPO3\CMS\Core\Pagination\SimplePagination;
1615
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
1716
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
17+
use TYPO3\CMS\Core\Pagination\SimplePagination;
18+
use TYPO3\CMS\Core\Utility\GeneralUtility;
1819

1920
/**
2021
* Controller class for the plugin 'ListView'.
@@ -66,7 +67,7 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
6667
* @access protected
6768
* @var array The current search parameter
6869
*/
69-
protected $searchParams;
70+
protected $searchParams = [];
7071

7172
/**
7273
* The main method of the plugin
@@ -77,16 +78,18 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
7778
*/
7879
public function mainAction(): void
7980
{
81+
// Quit without doing anything if required variables are not set.
82+
if (empty($this->settings['solrcore'])) {
83+
$this->logger->warning('Incomplete plugin configuration for SOLR. Please check the plugin settings for UID of SOLR core.');
84+
return;
85+
}
86+
8087
$this->searchParams = $this->getParametersSafely('searchParameter');
88+
$searchRequestData = GeneralUtility::_GPmerged('tx_dlf_search');
8189

82-
// extract collection(s) from collection parameter
83-
$collections = [];
84-
if (is_array($this->searchParams) && array_key_exists('collection', $this->searchParams)) {
85-
foreach(explode(',', $this->searchParams['collection']) as $collectionEntry) {
86-
if (!empty($collectionEntry)) {
87-
$collections[] = $this->collectionRepository->findByUid((int) $collectionEntry);
88-
}
89-
}
90+
if (isset($searchRequestData['searchParameter']) && is_array($searchRequestData['searchParameter'])) {
91+
$this->searchParams = array_merge($this->searchParams ?: [], $searchRequestData['searchParameter']);
92+
$this->request->getAttribute('frontend.user')->setKey('ses', 'search', $this->searchParams);
9093
}
9194

9295
// Get current page from request data because the parameter is shared between plugins
@@ -98,16 +101,11 @@ public function mainAction(): void
98101
// get all metadata records to be shown in results
99102
$listedMetadata = $this->metadataRepository->findByIsListed(true);
100103

101-
$solrResults = null;
102-
$numResults = 0;
103-
if (is_array($this->searchParams) && !empty($this->searchParams)) {
104-
$solrResults = $this->documentRepository->findSolrByCollections($collections, $this->settings, $this->searchParams, $listedMetadata);
105-
$numResults = $solrResults->getNumFound();
104+
if (!empty($this->searchParams)) {
105+
$solrResults = $this->documentRepository->findSolrWithoutCollection($this->settings, $this->searchParams, $listedMetadata);
106+
107+
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'] ?? 25;
106108

107-
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
108-
if (empty($itemsPerPage)) {
109-
$itemsPerPage = 25;
110-
}
111109
$solrPaginator = new SolrPaginator($solrResults, $currentPage, $itemsPerPage);
112110
$simplePagination = new SimplePagination($solrPaginator);
113111

@@ -116,8 +114,8 @@ public function mainAction(): void
116114
}
117115

118116
$this->view->assign('viewData', $this->viewData);
119-
$this->view->assign('documents', $solrResults);
120-
$this->view->assign('numResults', $numResults);
117+
$this->view->assign('countDocuments', !empty($solrResults) ? $solrResults->count() : 0);
118+
$this->view->assign('countResults', !empty($solrResults) ? $solrResults->getNumFound() : 0);
121119
$this->view->assign('page', $currentPage);
122120
$this->view->assign('lastSearch', $this->searchParams);
123121
$this->view->assign('sortableMetadata', $sortableMetadata);

Classes/Controller/MetadataController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,14 @@ private function buildExternalUrlFromMetadata(array $metadata): array
323323

324324
foreach ($metadata as $i => $section) {
325325
foreach ($section as $name => $value) {
326-
if (($name == 'author' || $name == 'holder') && !empty($value) && !empty($value[0]['url'])) {
327-
$externalUrl[$i][$name]['externalUrl'] = $value[0];
326+
if (($name == 'author' || $name == 'holder') && !empty($value)) {
327+
foreach ($value as $entry) {
328+
if (!empty($entry['url'])) {
329+
$externalUrl[$i][$name][] = $entry;
330+
}
331+
}
328332
} elseif (($name == 'geonames' || $name == 'wikidata' || $name == 'wikipedia') && !empty($value)) {
329-
$externalUrl[$i][$name]['externalUrl'] = [
333+
$externalUrl[$i][$name][] = [
330334
'name' => $value[0],
331335
'url' => $value[0]
332336
];

0 commit comments

Comments
 (0)