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

Refactored over-long method.

parent 161d158f
No related merge requests found
......@@ -669,107 +669,164 @@ class SolrDefault extends AbstractBase
}
/**
* Get the OpenURL parameters to represent this record (useful for the
* title attribute of a COinS span tag).
* Get default OpenURL parameters.
*
* @return string OpenURL parameters.
* @return array
*/
public function getOpenURL()
protected function getDefaultOpenURLParams()
{
// Get a representative publication date:
$pubDate = $this->getPublicationDates();
$pubDate = empty($pubDate) ? '' : $pubDate[0];
// Start an array of OpenURL parameters:
$params = array(
return array(
'ctx_ver' => 'Z39.88-2004',
'ctx_enc' => 'info:ofi/enc:UTF-8',
'rfr_id' => 'info:sid/' . $this->getCoinsID() . ':generator',
'rft.title' => $this->getTitle(),
'rft.date' => $pubDate
);
}
/**
* Get OpenURL parameters for a book.
*
* @return array
*/
protected function getBookOpenURLParams()
{
$params = $this->getDefaultOpenURLParams();
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:book';
$params['rft.genre'] = 'book';
$params['rft.btitle'] = $params['rft.title'];
$series = $this->getSeries();
if (count($series) > 0) {
// Handle both possible return formats of getSeries:
$params['rft.series'] = is_array($series[0]) ?
$series[0]['name'] : $series[0];
}
$params['rft.au'] = $this->getPrimaryAuthor();
$publishers = $this->getPublishers();
if (count($publishers) > 0) {
$params['rft.pub'] = $publishers[0];
}
$params['rft.edition'] = $this->getEdition();
$params['rft.isbn'] = (string)$this->getCleanISBN();
return $params;
}
/**
* Get OpenURL parameters for an article.
*
* @return array
*/
protected function getArticleOpenURLParams()
{
$params = $this->getDefaultOpenURLParams();
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:journal';
$params['rft.genre'] = 'article';
$params['rft.issn'] = (string)$this->getCleanISSN();
// an article may have also an ISBN:
$params['rft.isbn'] = (string)$this->getCleanISBN();
$params['rft.volume'] = $this->getContainerVolume();
$params['rft.issue'] = $this->getContainerIssue();
$params['rft.spage'] = $this->getContainerStartPage();
// unset default title -- we only want jtitle/atitle here:
unset($params['rft.title']);
$params['rft.jtitle'] = $this->getContainerTitle();
$params['rft.atitle'] = $this->getTitle();
$params['rft.au'] = $this->getPrimaryAuthor();
$params['rft.format'] = 'Article';
$langs = $this->getLanguages();
if (count($langs) > 0) {
$params['rft.language'] = $langs[0];
}
return $params;
}
/**
* Get OpenURL parameters for an unknown format.
*
* @param string $format Name of format
*
* @return array
*/
protected function getUnknownFormatOpenURLParams($format)
{
$params = $this->getDefaultOpenURLParams();
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:dc';
$params['rft.creator'] = $this->getPrimaryAuthor();
$publishers = $this->getPublishers();
if (count($publishers) > 0) {
$params['rft.pub'] = $publishers[0];
}
$params['rft.format'] = $format;
$langs = $this->getLanguages();
if (count($langs) > 0) {
$params['rft.language'] = $langs[0];
}
return $params;
}
/**
* Get OpenURL parameters for a journal.
*
* @return array
*/
protected function getJournalOpenURLParams()
{
$params = $this->getUnknownFormatOpenURLParams('Journal');
/* This is probably the most technically correct way to represent
* a journal run as an OpenURL; however, it doesn't work well with
* Zotero, so it is currently commented out -- instead, we just add
* some extra fields and to the "unknown format" case.
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:journal';
$params['rft.genre'] = 'journal';
$params['rft.jtitle'] = $params['rft.title'];
$params['rft.issn'] = $this->getCleanISSN();
$params['rft.au'] = $this->getPrimaryAuthor();
*/
$params['rft.issn'] = (string)$this->getCleanISSN();
// Including a date in a title-level Journal OpenURL may be too
// limiting -- in some link resolvers, it may cause the exclusion
// of databases if they do not cover the exact date provided!
unset($params['rft.date']);
// If we're working with the SFX resolver, we should add a
// special parameter to ensure that electronic holdings links
// are shown even though no specific date or issue is specified:
if (isset($this->mainConfig->OpenURL->resolver)
&& strtolower($this->mainConfig->OpenURL->resolver) == 'sfx'
) {
$params['sfx.ignore_date_threshold'] = 1;
}
return $params;
}
// Add additional parameters based on the format of the record:
$format = $this->getOpenURLFormat();
switch ($format) {
/**
* Get the OpenURL parameters to represent this record (useful for the
* title attribute of a COinS span tag).
*
* @return string OpenURL parameters.
*/
public function getOpenURL()
{
// Set up parameters based on the format of the record:
switch ($format = $this->getOpenURLFormat()) {
case 'Book':
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:book';
$params['rft.genre'] = 'book';
$params['rft.btitle'] = $params['rft.title'];
$series = $this->getSeries();
if (count($series) > 0) {
// Handle both possible return formats of getSeries:
$params['rft.series'] = is_array($series[0]) ?
$series[0]['name'] : $series[0];
}
$params['rft.au'] = $this->getPrimaryAuthor();
$publishers = $this->getPublishers();
if (count($publishers) > 0) {
$params['rft.pub'] = $publishers[0];
}
$params['rft.edition'] = $this->getEdition();
$params['rft.isbn'] = (string)$this->getCleanISBN();
$params = $this->getBookOpenURLParams();
break;
case 'Article':
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:journal';
$params['rft.genre'] = 'article';
$params['rft.issn'] = (string)$this->getCleanISSN();
// an article may have also an ISBN:
$params['rft.isbn'] = (string)$this->getCleanISBN();
$params['rft.volume'] = $this->getContainerVolume();
$params['rft.issue'] = $this->getContainerIssue();
$params['rft.spage'] = $this->getContainerStartPage();
// unset default title -- we only want jtitle/atitle here:
unset($params['rft.title']);
$params['rft.jtitle'] = $this->getContainerTitle();
$params['rft.atitle'] = $this->getTitle();
$params['rft.au'] = $this->getPrimaryAuthor();
$params['rft.format'] = $format;
$langs = $this->getLanguages();
if (count($langs) > 0) {
$params['rft.language'] = $langs[0];
}
$params = $this->getArticleOpenURLParams();
break;
case 'Journal':
/* This is probably the most technically correct way to represent
* a journal run as an OpenURL; however, it doesn't work well with
* Zotero, so it is currently commented out -- instead, we just add
* some extra fields and then drop through to the default case.
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:journal';
$params['rft.genre'] = 'journal';
$params['rft.jtitle'] = $params['rft.title'];
$params['rft.issn'] = $this->getCleanISSN();
$params['rft.au'] = $this->getPrimaryAuthor();
$params = $this->getJournalOpenURLParams();
break;
*/
$params['rft.issn'] = (string)$this->getCleanISSN();
// Including a date in a title-level Journal OpenURL may be too
// limiting -- in some link resolvers, it may cause the exclusion
// of databases if they do not cover the exact date provided!
unset($params['rft.date']);
// If we're working with the SFX resolver, we should add a
// special parameter to ensure that electronic holdings links
// are shown even though no specific date or issue is specified:
if (isset($this->mainConfig->OpenURL->resolver)
&& strtolower($this->mainConfig->OpenURL->resolver) == 'sfx'
) {
$params['sfx.ignore_date_threshold'] = 1;
}
default:
$params['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:dc';
$params['rft.creator'] = $this->getPrimaryAuthor();
$publishers = $this->getPublishers();
if (count($publishers) > 0) {
$params['rft.pub'] = $publishers[0];
}
$params['rft.format'] = $format;
$langs = $this->getLanguages();
if (count($langs) > 0) {
$params['rft.language'] = $langs[0];
}
$params = $this->getUnknownFormatOpenURLParams($format);
break;
}
......
......@@ -83,7 +83,7 @@ class SolrDefaultTest extends \VuFindTest\Unit\TestCase
'issn' => array('1234-5678'),
);
$driver = $this->getDriver($overrides);
$this->assertEquals('ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fvufind.svn.sourceforge.net%3Agenerator&rft.title=La+congiura+dei+Principi+Napoletani+1701+%3A+%28prima+e+seconda+stesura%29+%2F&rft.issn=1234-5678&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rft.creator=Vico%2C+Giambattista%2C+1668-1744.&rft.pub=Centro+di+Studi+Vichiani%2C&rft.format=Journal&rft.language=Italian', $driver->getOpenURL());
$this->assertEquals('ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fvufind.svn.sourceforge.net%3Agenerator&rft.title=La+congiura+dei+Principi+Napoletani+1701+%3A+%28prima+e+seconda+stesura%29+%2F&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rft.creator=Vico%2C+Giambattista%2C+1668-1744.&rft.pub=Centro+di+Studi+Vichiani%2C&rft.format=Journal&rft.language=Italian&rft.issn=1234-5678', $driver->getOpenURL());
}
/**
......
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