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

Add dc:identifier to OAI response.

- Resolves VUFIND-959.
parent 1a4ae731
Branches
Tags
No related merge requests found
......@@ -101,6 +101,9 @@ class OaiController extends AbstractBase
$this->getServiceLocator()->get('VuFind\DbTablePluginManager'),
$config, $baseURL, $this->getRequest()->getQuery()->toArray()
);
$server->setRecordLinkHelper(
$this->getViewRenderer()->plugin('recordlink')
);
$xml = $server->getResponse();
} catch (\Exception $e) {
$response->setStatusCode(500);
......
......@@ -49,6 +49,13 @@ class Server
*/
protected $baseURL;
/**
* Base URL of host containing VuFind.
*
* @var string
*/
protected $baseHostURL;
/**
* Incoming request parameters
*
......@@ -147,6 +154,13 @@ class Server
*/
protected $tableManager;
/**
* Record link helper (optional)
*
* @var \VuFind\View\Helper\Root\RecordLink
*/
protected $recordLinkHelper = null;
/**
* Constructor
*
......@@ -168,11 +182,29 @@ class Server
$this->recordLoader = $loader;
$this->tableManager = $tables;
$this->baseURL = $baseURL;
$parts = parse_url($baseURL);
$this->baseHostURL = $parts['scheme'] . '://' . $parts['host'];
if (isset($parts['port'])) {
$this->baseHostURL .= $parts['port'];
}
$this->params = isset($params) && is_array($params) ? $params : array();
$this->initializeMetadataFormats(); // Load details on supported formats
$this->initializeSettings($config); // Load config.ini settings
}
/**
* Add a record link helper (optional -- allows enhancement of some metadata
* with VuFind-specific links).
*
* @param \VuFind\View\Helper\Root\RecordLink $helper Helper to set
*
* @return void
*/
public function setRecordLinkHelper($helper)
{
$this->recordLinkHelper = $helper;
}
/**
* Respond to the OAI-PMH request.
*
......@@ -266,7 +298,8 @@ class Server
if ($format === false) {
$xml = ''; // no metadata if in header-only mode!
} else {
$xml = $record->getXML($format);
$xml = $record
->getXML($format, $this->baseHostURL, $this->recordLinkHelper);
if ($xml === false) {
return false;
}
......@@ -959,4 +992,3 @@ class Server
throw new \Exception("Unexpected fatal error -- {$msg}.");
}
}
?>
\ No newline at end of file
......@@ -27,7 +27,7 @@
* @link http://vufind.org/wiki/vufind2:record_drivers Wiki
*/
namespace VuFind\RecordDriver;
use VuFind\Code\ISBN;
use VuFind\Code\ISBN, VuFind\View\Helper\Root\RecordLink;
/**
* Default model for Solr records -- used when a more specific model based on
......@@ -1397,12 +1397,16 @@ class SolrDefault extends AbstractBase
* Return an XML representation of the record using the specified format.
* Return false if the format is unsupported.
*
* @param string $format Name of format to use (corresponds with OAI-PMH
* @param string $format Name of format to use (corresponds with OAI-PMH
* metadataPrefix parameter).
* @param string $baseUrl Base URL of host containing VuFind (optional;
* may be used to inject record URLs into XML when appropriate).
* @param RecordLink $recordLink Record link helper (optional; may be used to
* inject record URLs into XML when appropriate).
*
* @return mixed XML, or false if format unsupported.
*/
public function getXML($format)
public function getXML($format, $baseUrl = null, $recordLink = null)
{
// For OAI-PMH Dublin Core, produce the necessary XML:
if ($format == 'oai_dc') {
......@@ -1441,6 +1445,10 @@ class SolrDefault extends AbstractBase
'subject', htmlspecialchars(implode(' -- ', $subj)), $dc
);
}
if (null !== $baseUrl && null !== $recordLink) {
$url = $baseUrl . $recordLink->getUrl($this);
$xml->addChild('identifier', $url, $dc);
}
return $xml->asXml();
}
......
......@@ -26,7 +26,9 @@
* @link http://vufind.org/wiki/vufind2:record_drivers Wiki
*/
namespace VuFind\RecordDriver;
use VuFind\Exception\ILS as ILSException, VuFind\XSLT\Processor as XSLTProcessor;
use VuFind\Exception\ILS as ILSException,
VuFind\View\Helper\Root\RecordLink,
VuFind\XSLT\Processor as XSLTProcessor;
/**
* Model for MARC records in Solr.
......@@ -935,12 +937,16 @@ class SolrMarc extends SolrDefault
* Return an XML representation of the record using the specified format.
* Return false if the format is unsupported.
*
* @param string $format Name of format to use (corresponds with OAI-PMH
* @param string $format Name of format to use (corresponds with OAI-PMH
* metadataPrefix parameter).
* @param string $baseUrl Base URL of host containing VuFind (optional;
* may be used to inject record URLs into XML when appropriate).
* @param RecordLink $recordLink Record link helper (optional; may be used to
* inject record URLs into XML when appropriate).
*
* @return mixed XML, or false if format unsupported.
*/
public function getXML($format)
public function getXML($format, $baseUrl = null, $recordLink = null)
{
// Special case for MARC:
if ($format == 'marc21') {
......@@ -966,7 +972,7 @@ class SolrMarc extends SolrDefault
}
// Try the parent method:
return parent::getXML($format);
return parent::getXML($format, $baseUrl, $recordLink);
}
/**
......
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