From 052c4032c009e9cbb1481c65e067923e8b1602cf Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 5 Dec 2012 10:41:02 -0500 Subject: [PATCH] Moved author deduplication logic from templates into record driver. --- .../src/VuFind/RecordDriver/SolrDefault.php | 30 +++++++++++++++++++ .../RecordDriver/SolrDefault/core.phtml | 30 +++++-------------- .../RecordDriver/SolrDefault/core.phtml | 30 +++++-------------- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php index 61e91f3e1f5..ff98733ecc0 100644 --- a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php +++ b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php @@ -321,6 +321,36 @@ class SolrDefault extends AbstractBase $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. * diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml index 0b68ff60916..d21bde46cd6 100644 --- a/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml +++ b/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml @@ -44,42 +44,26 @@ </tr> <? endif; ?> - <? - // The secondary author array may contain a corporate or primary author; - // 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)): ?> + <? $authors = $this->driver->getDeduplicatedAuthors(); ?> + <? if (isset($authors['main']) && !empty($authors['main'])): ?> <tr valign="top"> <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> <? endif; ?> - <? if (!empty($corpAuthor)): ?> + <? if (isset($authors['corporate']) && !empty($authors['corporate'])): ?> <tr valign="top"> <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> <? endif; ?> - <? if (!empty($secondaryAuthors)): ?> + <? if (isset($authors['secondary']) && !empty($authors['secondary'])): ?> <tr valign="top"> <th><?=$this->transEsc('Other Authors')?>: </th> <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> </tr> <? endif; ?> diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml index 22bcae161d0..cd0d0a8bee9 100644 --- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml +++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml @@ -41,26 +41,10 @@ </dd> <? endif; ?> - <? - // The secondary author array may contain a corporate or primary author; - // 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)): ?> + <? $authors = $this->driver->getDeduplicatedAuthors(); ?> + <? if (isset($authors['main']) && !empty($authors['main'])): ?> <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; ?> <? $formats = $this->driver->getFormats(); if (!empty($formats)): ?> @@ -105,15 +89,15 @@ </tr> <? endif; ?> - <? if (!empty($corpAuthor)): ?> + <? if (isset($authors['corporate']) && !empty($authors['corporate'])): ?> <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; ?> - <? if (!empty($secondaryAuthors)): ?> + <? if (isset($authors['secondary']) && !empty($authors['secondary'])): ?> <dt><?=$this->transEsc('Other Authors')?>: </dt> <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> <? endif; ?> -- GitLab