Skip to content
Snippets Groups Projects
Commit 052c4032 authored by Demian Katz's avatar Demian Katz
Browse files

Moved author deduplication logic from templates into record driver.

parent 5ea46231
Branches
Tags
No related merge requests found
...@@ -321,6 +321,36 @@ class SolrDefault extends AbstractBase ...@@ -321,6 +321,36 @@ class SolrDefault extends AbstractBase
$this->fields['dateSpan'] : array(); $this->fields['dateSpan'] : array();
} }
/**
* Deduplicate author information into associative array with main/corporate/
* secondary keys.
*
* @return array
*/
public function getDeduplicatedAuthors()
{
$authors = array(
'main' => $this->getPrimaryAuthor(),
'corporate' => $this->getCorporateAuthor(),
'secondary' => $this->getSecondaryAuthors()
);
// The secondary author array may contain a corporate or primary author;
// let's be sure we filter out duplicate values.
$duplicates = array();
if (!empty($authors['main'])) {
$duplicates[] = $authors['main'];
}
if (!empty($authors['corporate'])) {
$duplicates[] = $authors['corporate'];
}
if (!empty($duplicates)) {
$authors['secondary'] = array_diff($authors['secondary'], $duplicates);
}
return $authors;
}
/** /**
* Get the edition of the current record. * Get the edition of the current record.
* *
......
...@@ -44,42 +44,26 @@ ...@@ -44,42 +44,26 @@
</tr> </tr>
<? endif; ?> <? endif; ?>
<? <? $authors = $this->driver->getDeduplicatedAuthors(); ?>
// The secondary author array may contain a corporate or primary author; <? if (isset($authors['main']) && !empty($authors['main'])): ?>
// let's be sure we filter out duplicate values.
$mainAuthor = $this->driver->getPrimaryAuthor();
$corpAuthor = $this->driver->getCorporateAuthor();
$secondaryAuthors = $this->driver->getSecondaryAuthors();
$duplicates = array();
if (!empty($mainAuthor)) {
$duplicates[] = $mainAuthor;
}
if (!empty($corpAuthor)) {
$duplicates[] = $corpAuthor;
}
if (!empty($duplicates)) {
$secondaryAuthors = array_diff($secondaryAuthors, $duplicates);
}
?>
<? if (!empty($mainAuthor)): ?>
<tr valign="top"> <tr valign="top">
<th><?=$this->transEsc('Main Author')?>: </th> <th><?=$this->transEsc('Main Author')?>: </th>
<td><a href="<?=$this->record($this->driver)->getLink('author', $mainAuthor)?>"><?=$this->escapeHtml($mainAuthor)?></a></td> <td><a href="<?=$this->record($this->driver)->getLink('author', $authors['main'])?>"><?=$this->escapeHtml($authors['main'])?></a></td>
</tr> </tr>
<? endif; ?> <? endif; ?>
<? if (!empty($corpAuthor)): ?> <? if (isset($authors['corporate']) && !empty($authors['corporate'])): ?>
<tr valign="top"> <tr valign="top">
<th><?=$this->transEsc('Corporate Author')?>: </th> <th><?=$this->transEsc('Corporate Author')?>: </th>
<td><a href="<?=$this->record($this->driver)->getLink('author', $corpAuthor)?>"><?=$this->escapeHtml($corpAuthor)?></a></td> <td><a href="<?=$this->record($this->driver)->getLink('author', $authors['corporate'])?>"><?=$this->escapeHtml($authors['corporate'])?></a></td>
</tr> </tr>
<? endif; ?> <? endif; ?>
<? if (!empty($secondaryAuthors)): ?> <? if (isset($authors['secondary']) && !empty($authors['secondary'])): ?>
<tr valign="top"> <tr valign="top">
<th><?=$this->transEsc('Other Authors')?>: </th> <th><?=$this->transEsc('Other Authors')?>: </th>
<td> <td>
<? $i = 0; foreach ($secondaryAuthors as $field): ?><?=($i++ == 0)?'':', '?><a href="<?=$this->record($this->driver)->getLink('author', $field)?>"><?=$this->escapeHtml($field)?></a><? endforeach; ?> <? $i = 0; foreach ($authors['secondary'] as $field): ?><?=($i++ == 0)?'':', '?><a href="<?=$this->record($this->driver)->getLink('author', $field)?>"><?=$this->escapeHtml($field)?></a><? endforeach; ?>
</td> </td>
</tr> </tr>
<? endif; ?> <? endif; ?>
......
...@@ -41,26 +41,10 @@ ...@@ -41,26 +41,10 @@
</dd> </dd>
<? endif; ?> <? endif; ?>
<? <? $authors = $this->driver->getDeduplicatedAuthors(); ?>
// The secondary author array may contain a corporate or primary author; <? if (isset($authors['main']) && !empty($authors['main'])): ?>
// let's be sure we filter out duplicate values.
$mainAuthor = $this->driver->getPrimaryAuthor();
$corpAuthor = $this->driver->getCorporateAuthor();
$secondaryAuthors = $this->driver->getSecondaryAuthors();
$duplicates = array();
if (!empty($mainAuthor)) {
$duplicates[] = $mainAuthor;
}
if (!empty($corpAuthor)) {
$duplicates[] = $corpAuthor;
}
if (!empty($duplicates)) {
$secondaryAuthors = array_diff($secondaryAuthors, $duplicates);
}
?>
<? if (!empty($mainAuthor)): ?>
<dt><?=$this->transEsc('Main Author')?>: </dt> <dt><?=$this->transEsc('Main Author')?>: </dt>
<dd><a rel="external" href="<?=$this->record($this->driver)->getLink('author', $mainAuthor)?>"><?=$this->escapeHtml($mainAuthor)?></a></dd> <dd><a rel="external" href="<?=$this->record($this->driver)->getLink('author', $authors['main'])?>"><?=$this->escapeHtml($authors['main'])?></a></dd>
<? endif; ?> <? endif; ?>
<? $formats = $this->driver->getFormats(); if (!empty($formats)): ?> <? $formats = $this->driver->getFormats(); if (!empty($formats)): ?>
...@@ -105,15 +89,15 @@ ...@@ -105,15 +89,15 @@
</tr> </tr>
<? endif; ?> <? endif; ?>
<? if (!empty($corpAuthor)): ?> <? if (isset($authors['corporate']) && !empty($authors['corporate'])): ?>
<dt><?=$this->transEsc('Corporate Author')?>: </dt> <dt><?=$this->transEsc('Corporate Author')?>: </dt>
<dd><p><a rel="external" href="<?=$this->record($this->driver)->getLink('author', $corpAuthor)?>"><?=$this->escapeHtml($corpAuthor)?></a></p></dd> <dd><p><a rel="external" href="<?=$this->record($this->driver)->getLink('author', $authors['corporate'])?>"><?=$this->escapeHtml($authors['corporate'])?></a></p></dd>
<? endif; ?> <? endif; ?>
<? if (!empty($secondaryAuthors)): ?> <? if (isset($authors['secondary']) && !empty($authors['secondary'])): ?>
<dt><?=$this->transEsc('Other Authors')?>: </dt> <dt><?=$this->transEsc('Other Authors')?>: </dt>
<dd> <dd>
<p><? $i = 0; foreach ($secondaryAuthors as $field): ?><?=($i++ == 0)?'':', '?><a rel="external" href="<?=$this->record($this->driver)->getLink('author', $field)?>"><?=$this->escapeHtml($field)?></a><? endforeach; ?></p> <p><? $i = 0; foreach ($authors['secondary'] as $field): ?><?=($i++ == 0)?'':', '?><a rel="external" href="<?=$this->record($this->driver)->getLink('author', $field)?>"><?=$this->escapeHtml($field)?></a><? endforeach; ?></p>
</dd> </dd>
<? endif; ?> <? endif; ?>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment