From 7151db70f30a3ea42549f3af5436f74b6e4eafdd Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Tue, 16 May 2023 17:39:52 +0200 Subject: [PATCH 01/10] Take mets_label for issues from the day structure --- Classes/Common/MetsDocument.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index cc6c7a30e..18ca8a898 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -181,8 +181,10 @@ public function addMetadataFromMets(&$metadata, $id) $details = $this->getLogicalStructure($id); if (!empty($details)) { $metadata['mets_order'][0] = $details['order']; - $metadata['mets_label'][0] = $details['label']; - $metadata['mets_orderlabel'][0] = $details['orderlabel']; + if ($metadata['type'][0] != 'issue') { + $metadata['mets_label'][0] = $details['label']; + $metadata['mets_orderlabel'][0] = $details['orderlabel']; + } } } @@ -630,6 +632,14 @@ class_exists($class) if (empty($metadata['date'][0])) { $metadata['date'][0] = ''; } + // Set mets_label for issues + if ($metadata['type'][0] == 'issue' && empty($metadata['mets_label'][0])) { + $dayLabel = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@TYPE="day"]/@ORDERLABEL'); + if (!empty($dayLabel)) { + $metadata['mets_label'] = [(string) $dayLabel[0]]; + } + } + // Files are not expected to reference a dmdSec if (isset($this->fileInfos[$id]) || isset($hasMetadataSection['dmdSec'])) { return $metadata; From 06ad7b7c839f8c65211750e02079c911da8e8d42 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Tue, 16 May 2023 17:40:15 +0200 Subject: [PATCH 02/10] Set title for issues in ToC plugin --- .../Controller/TableOfContentsController.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index e0a70df47..5b59f911d 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -132,7 +132,7 @@ protected function getMenuEntry(array $entry, $recursive = false) $entryArray = []; // Set "title", "volume", "type" and "pagination" from $entry array. - $entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; + $entryArray['title'] = $this->setTitle($entry); $entryArray['volume'] = $entry['volume']; $entryArray['orderlabel'] = $entry['orderlabel']; $entryArray['type'] = $this->getTranslatedType($entry['type']); @@ -141,9 +141,6 @@ protected function getMenuEntry(array $entry, $recursive = false) $entryArray['doNotLinkIt'] = 1; $entryArray['ITEM_STATE'] = 'NO'; - if ($entry['type'] == 'volume') { - $entryArray['title'] = $this->getTranslatedType($entry['type']) . ' ' . $entry['volume']; - } // Build menu links based on the $entry['points'] array. if ( !empty($entry['points']) @@ -272,6 +269,23 @@ private function getTranslatedType($type) { private function isMultiElement($type) { return $type === 'multivolume_work' || $type === 'multipart_manuscript'; } + /** + * Set title from entry. + * + * @param array $entry + * @return string + */ + private function setTitle($entry) { + if ($entry['type'] == 'issue') { + return $this->getTranslatedType($entry['type']) . ' ' . $entry['label']; + } + + if ($entry['type'] == 'volume') { + return $this->getTranslatedType($entry['type']) . ' ' . $entry['volume']; + } + + return !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; + } /** * Sort menu by orderlabel - currently implemented for newspaper. @@ -288,7 +302,7 @@ private function sortMenu(&$menu) { /** * Sort menu years of the newspaper by orderlabel. - * + * * @param array &$menu * * @return void From 1bcd87710160061ccd16eba7ab6f4fc9b1ab3baa Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Wed, 17 May 2023 19:05:47 +0200 Subject: [PATCH 03/10] Sort issues in Table of Content plugin by ORDERLABEL --- Classes/Controller/TableOfContentsController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index 5b59f911d..3c9773946 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -288,7 +288,7 @@ private function setTitle($entry) { } /** - * Sort menu by orderlabel - currently implemented for newspaper. + * Sort menu by orderlabel. * * @param array &$menu * @@ -296,20 +296,23 @@ private function setTitle($entry) { */ private function sortMenu(&$menu) { if ($menu[0]['type'] == $this->getTranslatedType("newspaper")) { - $this->sortMenuForNewspapers($menu); + $this->sortSubMenu($menu); + } + if ($menu[0]['type'] == $this->getTranslatedType("year")) { + $this->sortSubMenu($menu); } } /** - * Sort menu years of the newspaper by orderlabel. + * Sort sub menu e.g years of the newspaper by orderlabel. * * @param array &$menu * * @return void */ - private function sortMenuForNewspapers(&$menu) { - usort($menu[0]['_SUB_MENU'], function ($firstYear, $secondYear) { - return $firstYear['orderlabel'] <=> $secondYear['orderlabel']; + private function sortSubMenu(&$menu) { + usort($menu[0]['_SUB_MENU'], function ($firstElement, $secondElement) { + return $firstElement['orderlabel'] <=> $secondElement['orderlabel']; }); } } From 58a60d1f89c3ecd65fe19b19806b8ffeab07714b Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Wed, 14 Jun 2023 17:59:43 +0200 Subject: [PATCH 04/10] Fix displaying of title for volumes Overwrite title with type and volume only when label is empty --- Classes/Controller/TableOfContentsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index 3c9773946..b0de17dc9 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -280,7 +280,7 @@ private function setTitle($entry) { return $this->getTranslatedType($entry['type']) . ' ' . $entry['label']; } - if ($entry['type'] == 'volume') { + if ($entry['type'] == 'volume' && empty($entry['label'])) { return $this->getTranslatedType($entry['type']) . ' ' . $entry['volume']; } From f7ec30a326e3c1f2442abc03ec0683691edf1d23 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Fri, 30 Jun 2023 12:49:48 +0200 Subject: [PATCH 05/10] Reverse changes to MetsDocument --- Classes/Common/MetsDocument.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 18ca8a898..13cbea901 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -181,10 +181,8 @@ public function addMetadataFromMets(&$metadata, $id) $details = $this->getLogicalStructure($id); if (!empty($details)) { $metadata['mets_order'][0] = $details['order']; - if ($metadata['type'][0] != 'issue') { - $metadata['mets_label'][0] = $details['label']; - $metadata['mets_orderlabel'][0] = $details['orderlabel']; - } + $metadata['mets_label'][0] = $details['label']; + $metadata['mets_orderlabel'][0] = $details['orderlabel']; } } @@ -632,13 +630,6 @@ class_exists($class) if (empty($metadata['date'][0])) { $metadata['date'][0] = ''; } - // Set mets_label for issues - if ($metadata['type'][0] == 'issue' && empty($metadata['mets_label'][0])) { - $dayLabel = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@TYPE="day"]/@ORDERLABEL'); - if (!empty($dayLabel)) { - $metadata['mets_label'] = [(string) $dayLabel[0]]; - } - } // Files are not expected to reference a dmdSec if (isset($this->fileInfos[$id]) || isset($hasMetadataSection['dmdSec'])) { From e66bcacedd8f303f020e671e711172d680a47882 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Fri, 30 Jun 2023 13:11:59 +0200 Subject: [PATCH 06/10] Set title for issues and volumes with empty label Use configured fields to determine how the title should be built --- Classes/Common/MetsDocument.php | 5 +- .../Controller/TableOfContentsController.php | 92 +++++++++++++------ .../Domain/Repository/DocumentRepository.php | 1 + Configuration/TypoScript/setup.typoscript | 15 +++ Documentation/Plugins/Index.rst | 20 ++++ 5 files changed, 104 insertions(+), 29 deletions(-) diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 13cbea901..3d96e8ea8 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -333,7 +333,7 @@ protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recurs $details['orderlabel'] = (isset($attributes['ORDERLABEL']) ? $attributes['ORDERLABEL'] : ''); $details['contentIds'] = (isset($attributes['CONTENTIDS']) ? $attributes['CONTENTIDS'] : ''); $details['volume'] = ''; - // Set volume information only if no label is set and this is the toplevel structure element. + // Set volume any year information only if no label is set and this is the toplevel structure element. if ( empty($details['label']) && $details['id'] == $this->_getToplevelId() @@ -342,6 +342,9 @@ protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recurs if (!empty($metadata['volume'][0])) { $details['volume'] = $metadata['volume'][0]; } + if (!empty($metadata['year'][0])) { + $details['year'] = $metadata['year'][0]; + } } $details['pagination'] = ''; $details['type'] = $attributes['TYPE']; diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index b0de17dc9..a58341951 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -36,6 +36,8 @@ class TableOfContentsController extends AbstractController /** * The main method of the plugin * + * @access public + * * @return void */ public function mainAction() @@ -55,10 +57,11 @@ public function mainAction() /** * This builds a menu array for HMENU * - * @access protected + * @access private + * * @return array HMENU array */ - protected function makeMenuArray() + private function makeMenuArray() { $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); $menuArray = []; @@ -67,21 +70,7 @@ protected function makeMenuArray() !empty($this->document->getDoc()->physicalStructure) || !MathUtility::canBeInterpretedAsInteger($this->requestData['id']) ) { - // Get all logical units the current page or track is a part of. - if ( - !empty($this->requestData['page']) - && !empty($this->document->getDoc()->physicalStructure) - ) { - $this->activeEntries = array_merge((array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[0]], - (array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]]); - if ( - !empty($this->requestData['double']) - && $this->requestData['page'] < $this->document->getDoc()->numPages - ) { - $this->activeEntries = array_merge($this->activeEntries, - (array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page'] + 1]]); - } - } + $this->getAllLogicalUnits(); // Go through table of contents and create all menu entries. foreach ($this->document->getDoc()->tableOfContents as $entry) { $menuArray[] = $this->getMenuEntry($entry, true); @@ -104,6 +93,7 @@ protected function makeMenuArray() 'label' => !empty($resArray['mets_label']) ? $resArray['mets_label'] : $resArray['title'], 'type' => $resArray['type'], 'volume' => $resArray['volume'], + 'year' => $resArray['year'], 'orderlabel' => $resArray['mets_orderlabel'], 'pagination' => '', 'targetUid' => $resArray['uid'] @@ -119,14 +109,14 @@ protected function makeMenuArray() /** * This builds an array for one menu entry * - * @access protected + * @access private * * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure * @param bool $recursive : Whether to include the child entries * * @return array HMENU array for menu entry */ - protected function getMenuEntry(array $entry, $recursive = false) + private function getMenuEntry(array $entry, $recursive = false) { $entry = $this->resolveMenuEntry($entry); @@ -134,6 +124,7 @@ protected function getMenuEntry(array $entry, $recursive = false) // Set "title", "volume", "type" and "pagination" from $entry array. $entryArray['title'] = $this->setTitle($entry); $entryArray['volume'] = $entry['volume']; + $entryArray['year'] = $entry['year']; $entryArray['orderlabel'] = $entry['orderlabel']; $entryArray['type'] = $this->getTranslatedType($entry['type']); $entryArray['pagination'] = htmlspecialchars($entry['pagination']); @@ -219,10 +210,12 @@ protected function getMenuEntry(array $entry, $recursive = false) * This is so that when linking from a child document back to its parent, * that link is via UID, so that subsequently the parent's TOC is built from database. * + * @access private + * * @param array $entry * @return array */ - protected function resolveMenuEntry($entry) + private function resolveMenuEntry($entry) { // If the menu entry points to the parent document, // resolve to the parent UID set on indexation. @@ -239,9 +232,35 @@ protected function resolveMenuEntry($entry) return $entry; } + /** + * Get all logical units the current page or track is a part of. + * + * @access private + * + * @return void + */ + private function getAllLogicalUnits() { + if ( + !empty($this->requestData['page']) + && !empty($this->document->getDoc()->physicalStructure) + ) { + $this->activeEntries = array_merge((array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[0]], + (array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]]); + if ( + !empty($this->requestData['double']) + && $this->requestData['page'] < $this->document->getDoc()->numPages + ) { + $this->activeEntries = array_merge($this->activeEntries, + (array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page'] + 1]]); + } + } + } + /** * Get translated type of entry. * + * @access private + * * @param string $type * * @return string @@ -272,24 +291,39 @@ private function isMultiElement($type) { /** * Set title from entry. * + * @access private + * * @param array $entry + * * @return string */ private function setTitle($entry) { - if ($entry['type'] == 'issue') { - return $this->getTranslatedType($entry['type']) . ' ' . $entry['label']; - } - - if ($entry['type'] == 'volume' && empty($entry['label'])) { - return $this->getTranslatedType($entry['type']) . ' ' . $entry['volume']; + if (empty($entry['label']) && empty($entry['orderlabel'])) { + foreach ($this->settings['titleReplacements'] as $titleReplacement) { + if ($entry['type'] == $titleReplacement['type']) { + $fields = explode(",", $titleReplacement['fields']); + $title = ''; + + foreach ($fields as $field) { + if ($field == 'type') { + $title .= $this->getTranslatedType($entry['type']) . ' '; + } else { + $title .= $entry[$field] . ' '; + } + } + + return trim($title); + } + } } - - return !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; + return $entry['label'] ?: $entry['orderlabel']; } /** * Sort menu by orderlabel. * + * @access private + * * @param array &$menu * * @return void @@ -306,6 +340,8 @@ private function sortMenu(&$menu) { /** * Sort sub menu e.g years of the newspaper by orderlabel. * + * @access private + * * @param array &$menu * * @return void diff --git a/Classes/Domain/Repository/DocumentRepository.php b/Classes/Domain/Repository/DocumentRepository.php index 0315504d6..181ddb4d6 100644 --- a/Classes/Domain/Repository/DocumentRepository.php +++ b/Classes/Domain/Repository/DocumentRepository.php @@ -365,6 +365,7 @@ public function getTableOfContentsFromDb($uid, $pid, $settings) 'tx_dlf_documents.uid AS uid', 'tx_dlf_documents.title AS title', 'tx_dlf_documents.volume AS volume', + 'tx_dlf_documents.year AS year', 'tx_dlf_documents.mets_label AS mets_label', 'tx_dlf_documents.mets_orderlabel AS mets_orderlabel', 'tx_dlf_structures_join.index_name AS type' diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index eb3167b1c..aec7c16eb 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -104,3 +104,18 @@ plugin.tx_dlf_search { } } } + +plugin.tx_dlf_tableofcontents { + settings { + titleReplacements { + 0 { + type = issue + fields = type,year + } + 1 { + type = volume + fields = type,volume + } + } + } +} diff --git a/Documentation/Plugins/Index.rst b/Documentation/Plugins/Index.rst index 90031af5d..068e6cfcb 100644 --- a/Documentation/Plugins/Index.rst +++ b/Documentation/Plugins/Index.rst @@ -867,6 +867,8 @@ Table Of Contents Data type :Default: Default + :Description: + Description - :Property: excludeOther_ @@ -894,6 +896,24 @@ Table Of Contents :ref:`t3tsref:data-type-page-id` :Default: + - :Property: + titleReplacement + :Data Type: + :ref:`t3tsref:data-type-list` + :Default: + :Description: + List containing types for which title should be replaced + when the label is empty. The defined fields are used for + replacement. Example data: + 0 { + type = issue + fields = type,year + } + 1 { + type = volume + fields = type,volume + } + Toolbox ------- From 3c21c0b6873968fd5fd28ce5889032504457e72a Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Mon, 3 Jul 2023 17:42:31 +0200 Subject: [PATCH 07/10] Update sorting to use year when orderlabel is empty --- Classes/Controller/TableOfContentsController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index a58341951..7a11ab0be 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -348,7 +348,10 @@ private function sortMenu(&$menu) { */ private function sortSubMenu(&$menu) { usort($menu[0]['_SUB_MENU'], function ($firstElement, $secondElement) { - return $firstElement['orderlabel'] <=> $secondElement['orderlabel']; + if (!empty($firstElement['orderlabel'])) { + return $firstElement['orderlabel'] <=> $secondElement['orderlabel']; + } + return $firstElement['year'] <=> $secondElement['year']; }); } } From 52ec21e0176e211b1be80f120381a0350da31e35 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Tue, 25 Jul 2023 16:08:34 +0200 Subject: [PATCH 08/10] Update Classes/Common/MetsDocument.php Co-authored-by: Sebastian Meyer --- Classes/Common/MetsDocument.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 3d96e8ea8..3aae30c78 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -336,7 +336,7 @@ protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recurs // Set volume any year information only if no label is set and this is the toplevel structure element. if ( empty($details['label']) - && $details['id'] == $this->_getToplevelId() + && empty($details['orderlabel']) ) { $metadata = $this->getMetadata($details['id']); if (!empty($metadata['volume'][0])) { From 0807e6480117c0f79a28907c8cf9b1a54bf10ed7 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Fri, 1 Sep 2023 10:00:23 +0200 Subject: [PATCH 09/10] Update Classes/Common/MetsDocument.php Co-authored-by: Sebastian Meyer --- Classes/Common/MetsDocument.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 3aae30c78..461dbda8f 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -333,7 +333,7 @@ protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recurs $details['orderlabel'] = (isset($attributes['ORDERLABEL']) ? $attributes['ORDERLABEL'] : ''); $details['contentIds'] = (isset($attributes['CONTENTIDS']) ? $attributes['CONTENTIDS'] : ''); $details['volume'] = ''; - // Set volume any year information only if no label is set and this is the toplevel structure element. + // Set volume and year information only if no label is set and this is the toplevel structure element. if ( empty($details['label']) && empty($details['orderlabel']) From 77eb1b9e75c9ff390cde715a12c678a0b7e947e9 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Fri, 1 Sep 2023 10:01:22 +0200 Subject: [PATCH 10/10] Update Classes/Controller/TableOfContentsController.php Co-authored-by: Sebastian Meyer --- Classes/Controller/TableOfContentsController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index 7a11ab0be..d90b5b8b2 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -303,7 +303,6 @@ private function setTitle($entry) { if ($entry['type'] == $titleReplacement['type']) { $fields = explode(",", $titleReplacement['fields']); $title = ''; - foreach ($fields as $field) { if ($field == 'type') { $title .= $this->getTranslatedType($entry['type']) . ' ';