From 84dbfee6fa10461abce62cc376f71db845c6bf1e Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 20 Sep 2012 10:56:22 -0400 Subject: [PATCH] Smarter missing record support: missing titles now display more consistently, and missing records can be deleted from favorites (resolving VUFIND-645). --- .../Controller/MyResearchController.php | 1 + module/VuFind/src/VuFind/Record/Loader.php | 1 + .../src/VuFind/RecordDriver/Missing.php | 54 +++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 497ddda21b9..5bc0556e7b9 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -740,6 +740,7 @@ class MyResearchController extends AbstractBase $record->setRawData( array('id' => isset($current['id']) ? $current['id'] : null) ); + $record->setResourceSource('VuFind'); } $record->setExtraDetail('ils_details', $current); return $record; diff --git a/module/VuFind/src/VuFind/Record/Loader.php b/module/VuFind/src/VuFind/Record/Loader.php index 15ad4762023..853eb850161 100644 --- a/module/VuFind/src/VuFind/Record/Loader.php +++ b/module/VuFind/src/VuFind/Record/Loader.php @@ -136,6 +136,7 @@ class Loader implements ServiceLocatorAwareInterface ->get('RecordDriverPluginManager'); $retVal[$i] = clone($factory->get('Missing')); $retVal[$i]->setRawData($fields); + $retVal[$i]->setResourceSource($details['source']); } } diff --git a/module/VuFind/src/VuFind/RecordDriver/Missing.php b/module/VuFind/src/VuFind/RecordDriver/Missing.php index 405e59241cc..f0d2ed40ef8 100644 --- a/module/VuFind/src/VuFind/RecordDriver/Missing.php +++ b/module/VuFind/src/VuFind/RecordDriver/Missing.php @@ -48,4 +48,58 @@ class Missing extends SolrDefault $this->resourceSource = 'missing'; parent::__construct(); } + + /** + * Set the resource source of the missing record. This is a special function + * of the missing record driver and normally should NOT be attempted. + * + * @param string $source Resource source + * + * @return void + */ + public function setResourceSource($source) + { + $this->resourceSource = $source; + } + + /** + * Format the missing title. + * + * @return string + */ + public function determineMissingTitle() + { + // If available, load title from database: + $table = $this->getDbTable('Resource'); + $resource = $table + ->findResource($this->getUniqueId(), $this->getResourceSource(), false); + if (!empty($resource) && !empty($resource->title)) { + return $resource->title; + } + + // Default -- message about missing title: + return $this->translate('Title not available'); + } + + /** + * Get the short title of the record. + * + * @return string + */ + public function getShortTitle() + { + $title = parent::getShortTitle(); + return empty($title) ? $this->determineMissingTitle() : $title; + } + + /** + * Get the full title of the record. + * + * @return string + */ + public function getTitle() + { + $title = parent::getShortTitle(); + return empty($title) ? $this->determineMissingTitle() : $title; + } } -- GitLab