Skip to content

Commit

Permalink
Merge branch 'kitodo:master' into Pres_01-2023_Solr-Verbesserungen_up…
Browse files Browse the repository at this point in the history
…grade_to_solr9
  • Loading branch information
frank-ulrich-weber authored Jan 9, 2024
2 parents 34dc86d + 770df5a commit 450c23c
Show file tree
Hide file tree
Showing 25 changed files with 668 additions and 223 deletions.
4 changes: 2 additions & 2 deletions Classes/Common/IiifManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ protected function getLogicalStructureInfo(IiifResourceInterface $resource, bool
$details = [];
$details['id'] = $resource->getId();
$details['dmdId'] = '';
$details['label'] = $resource->getLabelForDisplay() !== null ? $resource->getLabelForDisplay() : '';
$details['orderlabel'] = $resource->getLabelForDisplay() !== null ? $resource->getLabelForDisplay() : '';
$details['label'] = $resource->getLabelForDisplay() ?? '';
$details['orderlabel'] = $resource->getLabelForDisplay() ?? '';
$details['contentIds'] = '';
$details['volume'] = '';
$details['pagination'] = '';
Expand Down
1 change: 1 addition & 0 deletions Classes/Common/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ protected static function processPhysical(Document $document, int $page, array $
$solrDoc->setField('toplevel', false);
$solrDoc->setField('type', $physicalUnit['type'], self::$fields['fieldboost']['type']);
$solrDoc->setField('collection', $doc->metadataArray[$doc->toplevelId]['collection']);
$solrDoc->setField('location', $document->getLocation());

$solrDoc->setField('fulltext', $fullText);
if (is_array($doc->metadataArray[$doc->toplevelId])) {
Expand Down
4 changes: 2 additions & 2 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ class_exists($class)
)
->execute();
// Merge both result sets.
$allResults = array_merge($resultWithFormat->fetchAll(), $resultWithoutFormat->fetchAll());
$allResults = array_merge($resultWithFormat->fetchAllAssociative(), $resultWithoutFormat->fetchAllAssociative());
// We need a \DOMDocument here, because SimpleXML doesn't support XPath functions properly.
$domNode = dom_import_simplexml($this->mdSec[$dmdId]['xml']);
$domXPath = new \DOMXPath($domNode->ownerDocument);
Expand Down Expand Up @@ -1097,7 +1097,7 @@ protected function magicGetThumbnail(bool $forceReload = false): string
->setMaxResults(1)
->execute();

$allResults = $result->fetchAll();
$allResults = $result->fetchAllAssociative();

if (count($allResults) == 1) {
$resArray = $allResults[0];
Expand Down
43 changes: 26 additions & 17 deletions Classes/Common/Solr/SolrSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,24 +585,33 @@ public function submit($start, $rows, $processResults = true)
if ($this->searchParams['fulltext'] != '1') {
$documents[$doc['uid']]['page'] = 1;
$children = $childrenOf[$doc['uid']] ?? [];
$childrenRows = !empty($this->settings['childrenRows']) ? intval($this->settings['childrenRows']) : 100;

if (!empty($children)) {
$metadataOf = $this->fetchToplevelMetadataFromSolr([
'query' => 'partof:' . $doc['uid'],
'start' => 0,
'rows' => $childrenRows,
]);
foreach ($children as $docChild) {
// We need only a few fields from the children, but we need them as array.
$childDocument = [
'thumbnail' => $docChild['thumbnail'],
'title' => $docChild['title'],
'structure' => $docChild['structure'],
'metsOrderlabel' => $docChild['metsOrderlabel'],
'uid' => $docChild['uid'],
'metadata' => $metadataOf[$docChild['uid']],
];
$documents[$doc['uid']]['children'][$docChild['uid']] = $childDocument;
$batchSize = 100;
$totalChildren = count($children);

for ($start = 0; $start < $totalChildren; $start += $batchSize) {
$batch = array_slice($children, $start, $batchSize, true);

// Fetch metadata for the current batch
$metadataOf = $this->fetchToplevelMetadataFromSolr([
'query' => 'partof:' . $doc['uid'],
'start' => $start,
'rows' => min($batchSize, $totalChildren - $start),
]);

foreach ($batch as $docChild) {
// We need only a few fields from the children, but we need them as an array.
$childDocument = [
'thumbnail' => $docChild['thumbnail'],
'title' => $docChild['title'],
'structure' => $docChild['structure'],
'metsOrderlabel' => $docChild['metsOrderlabel'],
'uid' => $docChild['uid'],
'metadata' => $metadataOf[$docChild['uid']],
];
$documents[$doc['uid']]['children'][$docChild['uid']] = $childDocument;
}
}
}
}
Expand Down
70 changes: 66 additions & 4 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,78 @@ protected function buildSimplePagination(PaginationInterface $pagination, Pagina
{
$firstPage = $pagination->getFirstPageNumber();
$lastPage = $pagination->getLastPageNumber();
$currentPageNumber = $paginator->getCurrentPageNumber();

$pages = [];

$lastStartRecordNumberGrid = 0; // due to validity outside the loop
foreach (range($firstPage, $lastPage) as $i) {
// detect which pagination is active: ListView or GridView
if (get_class($pagination) == 'TYPO3\CMS\Core\Pagination\SimplePagination') { // ListView
$lastStartRecordNumberGrid = $i; // save last $startRecordNumber for LastPage button

$pages[$i] = [
'label' => $i,
'startRecordNumber' => $i
];
} else { // GridView
// to calculate the values for generation the links for the pagination pages
/** @var \Kitodo\Dlf\Pagination\PageGridPaginator $paginator */
$itemsPerPage = $paginator->getPublicItemsPerPage();

$startRecordNumber = $itemsPerPage * $i;
$startRecordNumber = $startRecordNumber + 1;
$startRecordNumber = $startRecordNumber - $itemsPerPage;

$lastStartRecordNumberGrid = $startRecordNumber; // save last $startRecordNumber for LastPage button

// array with label as screen/pagination page number
// and startRecordNumer for correct structure of the link
//<f:link.action action="{action}"
// addQueryString="true"
// argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[page]'}"
// additionalParams="{'tx_dlf[page]': page.startRecordNumber}"
// arguments="{searchParameter: lastSearch}">{page.label}</f:link.action>
$pages[$i] = [
'label' => $i,
'startRecordNumber' => $startRecordNumber
];
}
}

$nextPageNumber = $pages[$currentPageNumber + 1]['startRecordNumber'];
$previousPageNumber = $pages[$currentPageNumber - 1]['startRecordNumber'];

// 'startRecordNumber' is not required in GridView, only the variant for each loop is required
// 'endRecordNumber' is not required in both views
// 'startRecordNumber' is not required in GridView, only the variant for each loop is required
// 'endRecordNumber' is not required in both views
//
// lastPageNumber => last screen page
// lastPageNumber => Document page to build the last screen page. This is the first document
// of the last block of 10 (or less) documents on the last screen page
// firstPageNumber => always 1
// nextPageNumber => Document page to build the next screen page
// nextPageNumberG => Number of the screen page for the next screen page
// previousPageNumber => Document page to build up the previous screen page
// previousPageNumberG => Number of the screen page for the previous screen page
// currentPageNumber => Number of the current screen page
// pagesG => Array with two keys
// label => Number of the screen page
// startRecordNumber => First document of this block of 10 documents on the same screen page
return [
'lastPageNumber' => $lastPage,
'lastPageNumberG' => $lastStartRecordNumberGrid,
'firstPageNumber' => $firstPage,
'nextPageNumber' => ($pagination->getNextPageNumber()),
'previousPageNumber' => $pagination->getPreviousPageNumber(),
'nextPageNumber' => $nextPageNumber,
'nextPageNumberG' => $currentPageNumber + 1,
'previousPageNumber' => $previousPageNumber,
'previousPageNumberG' => $currentPageNumber - 1,
'startRecordNumber' => $pagination->getStartRecordNumber(),
'endRecordNumber' => $pagination->getEndRecordNumber(),
'currentPageNumber' => $paginator->getCurrentPageNumber(),
'pages' => range($firstPage, $lastPage)
'currentPageNumber' => $currentPageNumber,
'pages' => range($firstPage, $lastPage),
'pagesG' => $pages
];
}
}
14 changes: 14 additions & 0 deletions Classes/Controller/Backend/NewTenantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
use Kitodo\Dlf\Domain\Repository\StructureRepository;
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
Expand Down Expand Up @@ -436,6 +437,19 @@ public function indexAction(): void
$this->view->assign('recordInfos', $recordInfos);
}

/**
* Error function - there is nothing to do at the moment.
*
* @access public
*
* @return void
*/
// @phpstan-ignore-next-line
public function errorAction(): void
{
// TODO: Call parent::errorAction() when dropping support for TYPO3 v10.
}

/**
* Get language label for given key and language.
*
Expand Down
42 changes: 15 additions & 27 deletions Classes/Controller/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

namespace Kitodo\Dlf\Controller;

use Generator;
use Kitodo\Dlf\Domain\Model\Document;
use Kitodo\Dlf\Domain\Repository\StructureRepository;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;

/**
* Controller class for the plugin 'Calendar'.
Expand Down Expand Up @@ -218,7 +220,7 @@ public function yearsAction(): void
}

$this->view->assign('documentId', $this->document->getUid());
$this->view->assign('allYearDocTitle', $this->document->getCurrentDocument()->getTitle($this->document->getUid()));
$this->view->assign('allYearDocTitle', $this->document->getCurrentDocument()->getTitle((int) $this->document->getUid()) ?: $this->document->getCurrentDocument()->tableOfContents[0]['label']);
}

/**
Expand Down Expand Up @@ -397,12 +399,10 @@ private function buildCalendar(): array
*/
private function getIssuesByYear(): array
{
$issues = $this->getIssues();

// We need an array of issues with year => month => day number as key.
$issuesByYear = [];

foreach ($issues as $issue) {
foreach ($this->getIssues() as $issue) {
$dateTimestamp = strtotime($issue['year']);
if ($dateTimestamp !== false) {
$_year = date('Y', $dateTimestamp);
Expand All @@ -424,35 +424,29 @@ private function getIssuesByYear(): array
*
* @access private
*
* @return array
* @return Generator
*/
private function getIssues(): array
private function getIssues(): Generator
{
$documents = $this->documentRepository->getChildrenOfYearAnchor($this->document->getUid(), $this->structureRepository->findOneByIndexName('issue'));

$issues = [];

// Process results.
if ($documents->count() === 0) {
$issues = $this->getIssuesFromTableOfContents();
} else {
$issues = $this->getIssuesFromDocuments($documents);
return $this->getIssuesFromTableOfContents();
}

return $issues;
return $this->getIssuesFromDocuments($documents);
}

/**
* Gets issues from table of contents.
*
* @access private
*
* @return array
* @return Generator
*/
private function getIssuesFromTableOfContents(): array
private function getIssuesFromTableOfContents(): Generator
{
$issues = [];

$toc = $this->document->getCurrentDocument()->tableOfContents;

foreach ($toc[0]['children'] as $year) {
Expand All @@ -464,7 +458,7 @@ private function getIssuesFromTableOfContents(): array
$title = strftime('%x', strtotime($title));
}

$issues[] = [
yield [
'uid' => $issue['points'],
'title' => $title,
'year' => $day['orderlabel'],
Expand All @@ -473,23 +467,19 @@ private function getIssuesFromTableOfContents(): array
}
}
}

return $issues;
}

/**
* Gets issues from documents.
*
* @access private
*
* @param array $documents to create issues
* @param array|QueryResultInterface $documents to create issues
*
* @return array
* @return Generator
*/
private function getIssuesFromDocuments(array $documents): array
private function getIssuesFromDocuments($documents): Generator
{
$issues = [];

/** @var Document $document */
foreach ($documents as $document) {
// Set title for display in calendar view.
Expand All @@ -501,13 +491,11 @@ private function getIssuesFromDocuments(array $documents): array
$title = strftime('%x', strtotime($title));
}
}
$issues[] = [
yield [
'uid' => $document->getUid(),
'title' => $title,
'year' => $document->getYear()
];
}

return $issues;
}
}
Loading

0 comments on commit 450c23c

Please sign in to comment.