From a2007b939c7fdc346bc7e982d8eeda9ae0a76ec6 Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Tue, 31 May 2022 10:15:44 -0400 Subject: [PATCH] discoverygarden#82: prefix container list with level --- includes/jstreebuilder.inc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/includes/jstreebuilder.inc b/includes/jstreebuilder.inc index 9743078..e9fc76b 100644 --- a/includes/jstreebuilder.inc +++ b/includes/jstreebuilder.inc @@ -84,6 +84,7 @@ class JSTreeBuilder { * Never actually got used? */ protected function getComponentTree(DOMElement $element) { + $level = $this->translateLevelCode($this->xpath->evaluate('string(./@level)', $element)); $unitid = $this->stringifyNode('ead:did/ead:unitid', $element); $title = $this->stringifyNode('ead:did/ead:unittitle', $element); $date = $this->stringifyNode('ead:did/ead:unitdate', $element); @@ -96,6 +97,9 @@ class JSTreeBuilder { if ($unitid) { $text = $unitid.' '.$text; } + if ($level) { + $text = $level.' '.$text; + } $info = array( 'id' => $element->getAttribute('id'), 'text' => $text, @@ -109,6 +113,28 @@ class JSTreeBuilder { return $info; } + /** + * Given the string of a component's level + * return a human-readable representation + * @param string $level the code from an EAD component's level attribute + * @return string A human-readable representation + */ + protected function translateLevelCode($level) { + $value = ''; + switch ($level) { + case 'recordgrp': + $value = t('Record Group'); + break; + case 'subgrp': + $value = t('Subgroup'); + break; + default: + $value = t(ucfirst($level)); + } + return $value; + } + + /** * Given the xpath to a single node in a DOMElement, * return the text content of the node and its children