Merge pull request #451 from albig/fix-metsdocument-query
Fix #450: Show all MODS metadata
This commit is contained in:
commit
85cc9d4659
|
@ -13,6 +13,7 @@
|
|||
namespace Kitodo\Dlf\Common;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use Ubl\Iiif\Tools\IiifHelper;
|
||||
use Ubl\Iiif\Services\AbstractImageService;
|
||||
|
@ -452,22 +453,78 @@ final class MetsDocument extends Document
|
|||
}
|
||||
}
|
||||
// Get the additional metadata from database.
|
||||
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
|
||||
'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadataformat.xpath AS xpath,tx_dlf_metadataformat.xpath_sorting AS xpath_sorting,tx_dlf_metadata.is_sortable AS is_sortable,tx_dlf_metadata.default_value AS default_value,tx_dlf_metadata.format AS format',
|
||||
'tx_dlf_metadata,tx_dlf_metadataformat,tx_dlf_formats',
|
||||
'tx_dlf_metadata.pid=' . $cPid
|
||||
. ' AND tx_dlf_metadataformat.pid=' . $cPid
|
||||
. ' AND ((tx_dlf_metadata.uid=tx_dlf_metadataformat.parent_id AND tx_dlf_metadataformat.encoded=tx_dlf_formats.uid AND tx_dlf_formats.type=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->dmdSec[$dmdId]['type'], 'tx_dlf_formats') . ') OR tx_dlf_metadata.format=0)'
|
||||
. Helper::whereClause('tx_dlf_metadata', true)
|
||||
. Helper::whereClause('tx_dlf_metadataformat')
|
||||
. Helper::whereClause('tx_dlf_formats')
|
||||
);
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_metadata');
|
||||
// Get hidden records, too.
|
||||
$queryBuilder
|
||||
->getRestrictions()
|
||||
->removeByType(HiddenRestriction::class);
|
||||
// Get all metadata with configured xpath and applicable format first.
|
||||
$resultWithFormat = $queryBuilder
|
||||
->select(
|
||||
'tx_dlf_metadata.index_name AS index_name',
|
||||
'tx_dlf_metadataformat_joins.xpath AS xpath',
|
||||
'tx_dlf_metadataformat_joins.xpath_sorting AS xpath_sorting',
|
||||
'tx_dlf_metadata.is_sortable AS is_sortable',
|
||||
'tx_dlf_metadata.default_value AS default_value',
|
||||
'tx_dlf_metadata.format AS format'
|
||||
)
|
||||
->from('tx_dlf_metadata')
|
||||
->innerJoin(
|
||||
'tx_dlf_metadata',
|
||||
'tx_dlf_metadataformat',
|
||||
'tx_dlf_metadataformat_joins',
|
||||
$queryBuilder->expr()->eq(
|
||||
'tx_dlf_metadataformat_joins.parent_id',
|
||||
'tx_dlf_metadata.uid'
|
||||
)
|
||||
)
|
||||
->innerJoin(
|
||||
'tx_dlf_metadataformat_joins',
|
||||
'tx_dlf_formats',
|
||||
'tx_dlf_formats_joins',
|
||||
$queryBuilder->expr()->eq(
|
||||
'tx_dlf_formats_joins.uid',
|
||||
'tx_dlf_metadataformat_joins.encoded'
|
||||
)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.pid', intval($cPid)),
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.l18n_parent', 0),
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadataformat_joins.pid', intval($cPid)),
|
||||
$queryBuilder->expr()->eq('tx_dlf_formats_joins.type', $queryBuilder->createNamedParameter($this->dmdSec[$dmdId]['type']))
|
||||
)
|
||||
->execute();
|
||||
// Get all metadata without a format, but with a default value next.
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_metadata');
|
||||
// Get hidden records, too.
|
||||
$queryBuilder
|
||||
->getRestrictions()
|
||||
->removeByType(HiddenRestriction::class);
|
||||
$resultWithoutFormat = $queryBuilder
|
||||
->select(
|
||||
'tx_dlf_metadata.index_name AS index_name',
|
||||
'tx_dlf_metadata.is_sortable AS is_sortable',
|
||||
'tx_dlf_metadata.default_value AS default_value',
|
||||
'tx_dlf_metadata.format AS format'
|
||||
)
|
||||
->from('tx_dlf_metadata')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.pid', intval($cPid)),
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.l18n_parent', 0),
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.format', 0),
|
||||
$queryBuilder->expr()->neq('tx_dlf_metadata.default_value', $queryBuilder->createNamedParameter(''))
|
||||
)
|
||||
->execute();
|
||||
// Merge both result sets.
|
||||
$allResults = array_merge($resultWithFormat->fetchAll(), $resultWithoutFormat->fetchAll());
|
||||
// We need a \DOMDocument here, because SimpleXML doesn't support XPath functions properly.
|
||||
$domNode = dom_import_simplexml($this->dmdSec[$dmdId]['xml']);
|
||||
$domXPath = new \DOMXPath($domNode->ownerDocument);
|
||||
$this->registerNamespaces($domXPath);
|
||||
// OK, now make the XPath queries.
|
||||
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
|
||||
foreach ($allResults as $resArray) {
|
||||
// Set metadata field's value(s).
|
||||
if (
|
||||
$resArray['format'] > 0
|
||||
|
|
|
@ -162,6 +162,8 @@ class Metadata extends \Kitodo\Dlf\Common\AbstractPlugin
|
|||
$this->getTemplate();
|
||||
$output = '';
|
||||
$subpart['block'] = $this->templateService->getSubpart($this->template, '###BLOCK###');
|
||||
// Save original data array.
|
||||
$cObjData = $this->cObj->data;
|
||||
// Get list of metadata to show.
|
||||
$metaList = [];
|
||||
if ($useOriginalIiifManifestMetadata) {
|
||||
|
@ -178,8 +180,6 @@ class Metadata extends \Kitodo\Dlf\Common\AbstractPlugin
|
|||
$iiifLink['value.']['setContentToCurrent'] = 1;
|
||||
$iiifLink['value.']['typolink.']['parameter.']['current'] = 1;
|
||||
$iiifLink['value.']['wrap'] = '<dd>|</dd>';
|
||||
// Save original data array.
|
||||
$cObjData = $this->cObj->data;
|
||||
foreach ($metadataArray as $metadata) {
|
||||
foreach ($metadata as $key => $group) {
|
||||
$markerArray['###METADATA###'] = '<span class="tx-dlf-metadata-group">' . $this->pi_getLL($key) . '</span>';
|
||||
|
@ -229,7 +229,6 @@ class Metadata extends \Kitodo\Dlf\Common\AbstractPlugin
|
|||
} else {
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_metadata');
|
||||
|
||||
$result = $queryBuilder
|
||||
->select(
|
||||
'tx_dlf_metadata.index_name AS index_name',
|
||||
|
@ -246,12 +245,10 @@ class Metadata extends \Kitodo\Dlf\Common\AbstractPlugin
|
|||
),
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.l18n_parent', 0)
|
||||
),
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.pid', intval($this->conf['pages'])),
|
||||
Helper::whereExpression('tx_dlf_metadata')
|
||||
$queryBuilder->expr()->eq('tx_dlf_metadata.pid', intval($this->conf['pages']))
|
||||
)
|
||||
->orderBy('tx_dlf_metadata.sorting')
|
||||
->execute();
|
||||
|
||||
while ($resArray = $result->fetch()) {
|
||||
if (is_array($resArray) && $resArray['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) {
|
||||
$resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_metadata', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
|
||||
|
@ -265,26 +262,20 @@ class Metadata extends \Kitodo\Dlf\Common\AbstractPlugin
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get list of collections to show.
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_collections');
|
||||
|
||||
// Get list of collections to show.
|
||||
$collList = [];
|
||||
$result = $queryBuilder
|
||||
->select('tx_dlf_collections.index_name AS index_name')
|
||||
->from('tx_dlf_collections')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($this->conf['pages'])),
|
||||
Helper::whereExpression('tx_dlf_collections')
|
||||
$queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($this->conf['pages']))
|
||||
)
|
||||
->execute();
|
||||
|
||||
while ($resArray = $result->fetch()) {
|
||||
$collList[] = $resArray['index_name'];
|
||||
}
|
||||
// Save original data array.
|
||||
$cObjData = $this->cObj->data;
|
||||
// Parse the metadata arrays.
|
||||
foreach ($metadataArray as $metadata) {
|
||||
$markerArray['###METADATA###'] = '';
|
||||
|
@ -300,67 +291,64 @@ class Metadata extends \Kitodo\Dlf\Common\AbstractPlugin
|
|||
}
|
||||
// Process each metadate.
|
||||
foreach ($metaList as $index_name => $metaConf) {
|
||||
if (!empty($metadata[$index_name])) {
|
||||
$parsedValue = '';
|
||||
$fieldwrap = $this->parseTS($metaConf['wrap']);
|
||||
do {
|
||||
$value = @array_shift($metadata[$index_name]);
|
||||
if ($index_name == 'title') {
|
||||
// Get title of parent document if needed.
|
||||
if (empty($value) && $this->conf['getTitle'] && $this->doc->parentId) {
|
||||
$superiorTitle = Document::getTitle($this->doc->parentId, true);
|
||||
if (!empty($superiorTitle)) {
|
||||
$value = '[' . $superiorTitle . ']';
|
||||
}
|
||||
$parsedValue = '';
|
||||
$fieldwrap = $this->parseTS($metaConf['wrap']);
|
||||
do {
|
||||
$value = @array_shift($metadata[$index_name]);
|
||||
if ($index_name == 'title') {
|
||||
// Get title of parent document if needed.
|
||||
if (empty($value) && $this->conf['getTitle'] && $this->doc->parentId) {
|
||||
$superiorTitle = Document::getTitle($this->doc->parentId, true);
|
||||
if (!empty($superiorTitle)) {
|
||||
$value = '[' . $superiorTitle . ']';
|
||||
}
|
||||
if (!empty($value)) {
|
||||
$value = htmlspecialchars($value);
|
||||
// Link title to pageview.
|
||||
if ($this->conf['linkTitle'] && $metadata['_id']) {
|
||||
$details = $this->doc->getLogicalStructure($metadata['_id']);
|
||||
$value = $this->pi_linkTP($value, [$this->prefixId => ['id' => $this->doc->uid, 'page' => (!empty($details['points']) ? intval($details['points']) : 1)]], true, $this->conf['targetPid']);
|
||||
}
|
||||
}
|
||||
} elseif ($index_name == 'owner' && !empty($value)) {
|
||||
// Translate name of holding library.
|
||||
$value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->conf['pages']));
|
||||
} elseif ($index_name == 'type' && !empty($value)) {
|
||||
// Translate document type.
|
||||
$value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->conf['pages']));
|
||||
} elseif ($index_name == 'collection' && !empty($value)) {
|
||||
// Check if collections isn't hidden.
|
||||
if (in_array($value, $collList)) {
|
||||
// Translate collection.
|
||||
$value = htmlspecialchars(Helper::translate($value, 'tx_dlf_collections', $this->conf['pages']));
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
} elseif ($index_name == 'language' && !empty($value)) {
|
||||
// Translate ISO 639 language code.
|
||||
$value = htmlspecialchars(Helper::getLanguageName($value));
|
||||
} elseif (!empty($value)) {
|
||||
// Sanitize value for output.
|
||||
$value = htmlspecialchars($value);
|
||||
}
|
||||
|
||||
if (!empty($value)) {
|
||||
// Hook for getting a customized value (requested by SBB).
|
||||
foreach ($this->hookObjects as $hookObj) {
|
||||
if (method_exists($hookObj, 'printMetadata_customizeMetadata')) {
|
||||
$hookObj->printMetadata_customizeMetadata($value);
|
||||
}
|
||||
$value = htmlspecialchars($value);
|
||||
// Link title to pageview.
|
||||
if ($this->conf['linkTitle'] && $metadata['_id']) {
|
||||
$details = $this->doc->getLogicalStructure($metadata['_id']);
|
||||
$value = $this->pi_linkTP($value, [$this->prefixId => ['id' => $this->doc->uid, 'page' => (!empty($details['points']) ? intval($details['points']) : 1)]], true, $this->conf['targetPid']);
|
||||
}
|
||||
$value = $this->cObj->stdWrap($value, $fieldwrap['value.']);
|
||||
|
||||
$parsedValue .= $value;
|
||||
}
|
||||
} while (count($metadata[$index_name]));
|
||||
|
||||
if (!empty($parsedValue)) {
|
||||
$field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']);
|
||||
$field .= $parsedValue;
|
||||
$markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']);
|
||||
} elseif ($index_name == 'owner' && !empty($value)) {
|
||||
// Translate name of holding library.
|
||||
$value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->conf['pages']));
|
||||
} elseif ($index_name == 'type' && !empty($value)) {
|
||||
// Translate document type.
|
||||
$value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->conf['pages']));
|
||||
} elseif ($index_name == 'collection' && !empty($value)) {
|
||||
// Check if collections isn't hidden.
|
||||
if (in_array($value, $collList)) {
|
||||
// Translate collection.
|
||||
$value = htmlspecialchars(Helper::translate($value, 'tx_dlf_collections', $this->conf['pages']));
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
} elseif ($index_name == 'language' && !empty($value)) {
|
||||
// Translate ISO 639 language code.
|
||||
$value = htmlspecialchars(Helper::getLanguageName($value));
|
||||
} elseif (!empty($value)) {
|
||||
// Sanitize value for output.
|
||||
$value = htmlspecialchars($value);
|
||||
}
|
||||
// Hook for getting a customized value (requested by SBB).
|
||||
foreach ($this->hookObjects as $hookObj) {
|
||||
if (method_exists($hookObj, 'printMetadata_customizeMetadata')) {
|
||||
$hookObj->printMetadata_customizeMetadata($value);
|
||||
}
|
||||
}
|
||||
// $value might be empty for aggregation metadata fields including other "hidden" fields.
|
||||
$value = $this->cObj->stdWrap($value, $fieldwrap['value.']);
|
||||
if (!empty($value)) {
|
||||
$parsedValue .= $value;
|
||||
}
|
||||
} while (is_array($metadata[$index_name]) && count($metadata[$index_name]) > 0);
|
||||
|
||||
if (!empty($parsedValue)) {
|
||||
$field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']);
|
||||
$field .= $parsedValue;
|
||||
$markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']);
|
||||
}
|
||||
}
|
||||
$output .= $this->templateService->substituteMarkerArray($subpart['block'], $markerArray);
|
||||
|
|
Loading…
Reference in New Issue