diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php index 61e91f3e1f5c1174eaf757801b9734ed10334bca..ff98733ecc07dc6754531212d93ae4ba0b0c4853 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 0b68ff60916f24c202ebb572dc44137d0f18df17..d21bde46cd679faaec9b72691bfd8ac9b972d26d 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 22bcae161d0f2050de6dcb31ca84437a31593838..cd0d0a8bee9e7191e9b712c1bb10baf9b372c4b7 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; ?>