Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion includes/blocks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function islandora_manuscript_container_list($object) {
);
module_load_include('inc', 'islandora_manuscript', 'includes/jstreebuilder');
$builder = new \Islandora\Manuscript\ContainerListJSTreeBuilder($object);
$structure = $builder->getTreeStructure();
if (empty($structure)) {
return;
}
$form['tree']['#attached']['js'][] = array(
'type' => 'setting',
'data' => array(
Expand All @@ -58,7 +62,7 @@ function islandora_manuscript_container_list($object) {
$id => array(
'core' => array(
'multiple' => FALSE,
'data' => $builder->getTreeStructure(),
'data' => $structure,
),
'plugins' => array('types'),
'types' => array(
Expand Down
53 changes: 49 additions & 4 deletions includes/jstreebuilder.inc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class JSTreeBuilder {
$list = $this->xpath->query($query, $node);
$roots = array();
foreach ($list as $component) {
$roots[] = $this->getComponentTree($component);
$root = $this->getComponentTree($component);
if ($root) {
$roots[] = $root;
}
}
return $roots;
}
Expand All @@ -84,27 +87,69 @@ class JSTreeBuilder {
* Never actually got used?
*/
protected function getComponentTree(DOMElement $element) {
$title = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unittitle/text()))', $element);
$date = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unitdate/text()))', $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);
$text = empty($date) ?
$title :
format_string('@title (@date)', array(
'@title' => $title,
'@date' => $date,
));
if ($unitid) {
$text = $unitid.' '.$text;
}
if ($level) {
$text = $level.' '.$text;
}
$info = array(
'id' => $element->getAttribute('id'),
'text' => $text,
'type' => $element->getAttribute('level'),
'children' => array_merge(
$this->getLevel('ead:c01 | ead:c02 | ead:c03 | ead:c04 | ead:c05 | ead:c', $element),
$this->getLevel('ead:c01 | ead:c02 | ead:c03 | ead:c04 | ead:c05 | ead:c06 | ead:c07 | ead:c08 | ead:c09 | ead:c', $element),
$this->getContainers($element)
),
'path' => $element->getNodePath(),
);
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
* @param string $xpath Path to a single node
* @param DOMElement $element Element which may contain the xpath
* @return string The textContent of the node, or an empty string if no node is found
*/
protected function stringifyNode($xpath, DOMElement $element) {
$node = $this->xpath->query($xpath, $element)->item(0);
return $node ? $node->textContent : '';
}

/**
* Get all containers of this component.
*/
Expand Down