Skip to content

Commit

Permalink
Merge branch 'kitodo:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
csidirop authored Jan 9, 2024
2 parents 912664d + 770df5a commit 7f78d97
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 136 deletions.
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
];
}
}
7 changes: 4 additions & 3 deletions Classes/Controller/Backend/NewTenantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,12 @@ public function indexAction(): void
*
* @access public
*
* @return ResponseInterface
* @return void
*/
public function errorAction(): ResponseInterface
// @phpstan-ignore-next-line
public function errorAction(): void
{
return parent::errorAction();
// TODO: Call parent::errorAction() when dropping support for TYPO3 v10.
}

/**
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;
}
}
6 changes: 6 additions & 0 deletions Classes/ExpressionLanguage/DocumentTypeFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;

/**
* Provider class for additional "getDocumentType" function to the ExpressionLanguage.
Expand Down Expand Up @@ -91,6 +92,11 @@ public function injectDocumentRepository(DocumentRepository $documentRepository)
*/
protected function initializeRepositories(int $storagePid): void
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
// TODO: change it as it is deprecated since 10.4 and will be removed in 12.x
// TODO: necessary to test calendar view after updating this code
$configurationManager = $objectManager->get(ConfigurationManager::class);
$this->injectConfigurationManager($configurationManager);
$frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);

$frameworkConfiguration['persistence']['storagePid'] = MathUtility::forceIntegerInRange((int) $storagePid, 0);
Expand Down
16 changes: 0 additions & 16 deletions Documentation/Plugins/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,6 @@ The collection plugin shows one collection, all collections or selected collecti
:ref:`t3tsref:data-type-list`
:Default:

- :Property:
childrenRows
:Data Type:
:ref:`t3tsref:data-type-integer`
:Default:
:Description:
It defines for how many children documents metadata should be fetched

- :Property:
show_userdefined
:Data Type:
Expand Down Expand Up @@ -727,14 +719,6 @@ Search
:Default:
0

- :Property:
childrenRows
:Data Type:
:ref:`t3tsref:data-type-integer`
:Default:
:Description:
It defines for how many children documents metadata should be fetched

- :Property:
solrcore
:Data Type:
Expand Down
Loading

0 comments on commit 7f78d97

Please sign in to comment.