diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index 0f1a5135b42299a3f8febf07a828def83dfb059d..a913c73d2a5398d7af0e04231b67d67abeb82c00 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -112,8 +112,9 @@ class Bootstrap $manager->setServiceLocator($serviceManager); $serviceManager->setService('SearchManager', $manager); - // TODO: factor out static connection manager. + // TODO: factor out static connection manager and record loader. \VuFind\Connection\Manager::setServiceLocator($serviceManager); + \VuFind\Record\Loader::getInstance()->setServiceLocator($serviceManager); } /** diff --git a/module/VuFind/src/VuFind/Cart.php b/module/VuFind/src/VuFind/Cart.php index 99d78b6f42612dbcb1747f0faf7e631f05aa380d..3e0a3c25487c730cef777b77abcd0e2479a04f63 100644 --- a/module/VuFind/src/VuFind/Cart.php +++ b/module/VuFind/src/VuFind/Cart.php @@ -267,6 +267,6 @@ class Cart */ public function getRecordDetails() { - return RecordLoader::loadBatch($this->items); + return RecordLoader::getInstance()->loadBatch($this->items); } } diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 4ddbcb322b9acb000ab539e7d21bc53552886cf5..b1c4216361425847f884accb77560753a2b18298 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -609,7 +609,7 @@ class AjaxController extends AbstractBase } // empty tag try { - $driver = RecordLoader::load( + $driver = RecordLoader::getInstance()->load( $this->params()->fromPost('id'), $this->params()->fromPost('source', 'VuFind') ); @@ -832,7 +832,7 @@ class AjaxController extends AbstractBase ); } - $driver = RecordLoader::load( + $driver = RecordLoader::getInstance()->load( $this->params()->fromPost('id'), $this->params()->fromPost('source', 'VuFind') ); @@ -939,7 +939,7 @@ class AjaxController extends AbstractBase { // Attempt to send the email: try { - $record = RecordLoader::load( + $record = RecordLoader::getInstance()->load( $this->params()->fromPost('id'), $this->params()->fromPost('source', 'VuFind') ); @@ -968,7 +968,7 @@ class AjaxController extends AbstractBase { // Attempt to send the email: try { - $record = RecordLoader::load( + $record = RecordLoader::getInstance()->load( $this->params()->fromPost('id'), $this->params()->fromPost('source', 'VuFind') ); @@ -1128,7 +1128,7 @@ class AjaxController extends AbstractBase */ public function getRecordCommentsAsHTML() { - $driver = RecordLoader::load( + $driver = RecordLoader::getInstance()->load( $this->params()->fromQuery('id'), $this->params()->fromQuery('source', 'VuFind') ); diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php index d8bd06bfc75b0c885ac06e96c65a69164745fb32..889c34157a3aa1ff40f085552caeb951cfdf29e8 100644 --- a/module/VuFind/src/VuFind/Controller/CartController.php +++ b/module/VuFind/src/VuFind/Controller/CartController.php @@ -174,7 +174,7 @@ class CartController extends AbstractBase return $this->redirectToSource('error', 'bulk_noitems_advice'); } $view = $this->createViewModel(); - $view->records = RecordLoader::loadBatch($ids); + $view->records = RecordLoader::getInstance()->loadBatch($ids); // Process form submission: if ($this->params()->fromPost('submit')) { @@ -258,7 +258,7 @@ class CartController extends AbstractBase // Load the records: $view = $this->createViewModel(); - $view->records = RecordLoader::loadBatch($ids); + $view->records = RecordLoader::getInstance()->loadBatch($ids); // Assign the list of legal export options. We'll filter them down based // on what the selected records actually support. @@ -305,7 +305,7 @@ class CartController extends AbstractBase // Actually export the records - $records = RecordLoader::loadBatch($ids); + $records = RecordLoader::getInstance()->loadBatch($ids); $recordHelper = $this->getViewRenderer()->plugin('record'); $parts = array(); foreach ($records as $record) { @@ -356,7 +356,7 @@ class CartController extends AbstractBase // Pass record and list information to view: return $this->createViewModel( array( - 'records' => RecordLoader::loadBatch($ids), + 'records' => RecordLoader::getInstance()->loadBatch($ids), 'lists' => $user->getLists() ) ); diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 2f40ed866bbe233961fca32ccba5783527330c6b..004e39ed3b88a5fd40ab7522a63e0a9cded3d1cc 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -320,7 +320,7 @@ class MyResearchController extends AbstractBase 'list' => empty($listID) ? false : UserListTable::getExisting($listID), 'deleteIDS' => $ids, - 'records' => RecordLoader::loadBatch($ids) + 'records' => RecordLoader::getInstance()->loadBatch($ids) ) ); } @@ -422,7 +422,7 @@ class MyResearchController extends AbstractBase $source = $this->params()->fromPost( 'source', $this->params()->fromQuery('source', 'VuFind') ); - $driver = RecordLoader::load($id, $source); + $driver = RecordLoader::getInstance()->load($id, $source); $listID = $this->params()->fromPost( 'list_id', $this->params()->fromQuery('list_id', null) ); diff --git a/module/VuFind/src/VuFind/Controller/UpgradeController.php b/module/VuFind/src/VuFind/Controller/UpgradeController.php index a829f35e20c1837565aaa272048cb66dd8016590..1ac9c73be30c76f50685225799c5190e68c34352 100644 --- a/module/VuFind/src/VuFind/Controller/UpgradeController.php +++ b/module/VuFind/src/VuFind/Controller/UpgradeController.php @@ -413,8 +413,8 @@ class UpgradeController extends AbstractBase if (strlen($this->params()->fromPost('submit', '')) > 0) { foreach ($problems as $problem) { try { - $driver - = RecordLoader::load($problem->record_id, $problem->source); + $driver = RecordLoader::getInstance() + ->load($problem->record_id, $problem->source); $problem->assignMetadata($driver)->save(); } catch (RecordMissingException $e) { $this->session->warnings->append( diff --git a/module/VuFind/src/VuFind/Db/Table/Resource.php b/module/VuFind/src/VuFind/Db/Table/Resource.php index 7181c08b3d04028b39cde6ff6e8c6e9985218b61..47b27877b0183721b566dcd757c2d44ff1cc2ce9 100644 --- a/module/VuFind/src/VuFind/Db/Table/Resource.php +++ b/module/VuFind/src/VuFind/Db/Table/Resource.php @@ -79,7 +79,7 @@ class Resource extends Gateway // Load record if it was not provided: if (is_null($driver)) { - $driver = RecordLoader::load($id, $source); + $driver = RecordLoader::getInstance()->load($id, $source); } // Load metadata into the database for sorting/failback purposes: diff --git a/module/VuFind/src/VuFind/Record/Loader.php b/module/VuFind/src/VuFind/Record/Loader.php index 1c44cb02dca91fabdbaa597dc39a8c0f0a24c349..bdf6468dcbf4cbe2026405a17bb02533a8d516f7 100644 --- a/module/VuFind/src/VuFind/Record/Loader.php +++ b/module/VuFind/src/VuFind/Record/Loader.php @@ -26,6 +26,8 @@ * @link http://vufind.org Main Site */ namespace VuFind\Record; +use Zend\ServiceManager\ServiceLocatorAwareInterface, + Zend\ServiceManager\ServiceLocatorInterface; /** * Record loader @@ -36,8 +38,23 @@ namespace VuFind\Record; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org Main Site */ -class Loader +class Loader implements ServiceLocatorAwareInterface { + /** + * Temporary method to get instance of object -- TODO: eliminate in place of + * service manager after further refactoring. + * + * @return Loader + */ + public function getInstance() + { + static $instance = false; + if (!$instance) { + $instance = new Loader(); + } + return $instance; + } + /** * Given a record source, return the search class that can load that type of * record. @@ -47,7 +64,7 @@ class Loader * @throws \Exception * @return string */ - protected static function getClassForSource($source) + protected function getClassForSource($source) { // Special case -- the VuFind record source actually maps to Solr classes; // this is a legacy issue related to values inserted into the database by @@ -76,10 +93,10 @@ class Loader * @throws \Exception * @return \VuFind\RecordDriver\AbstractBase */ - public static function load($id, $source = 'VuFind') + public function load($id, $source = 'VuFind') { // Load the record: - $class = self::getClassForSource($source); + $class = $this->getClassForSource($source); return call_user_func(array($class, 'getRecord'), $id); } @@ -97,7 +114,7 @@ class Loader * @throws \Exception * @return array Array of record drivers */ - public static function loadBatch($ids) + public function loadBatch($ids) { // Sort the IDs by source -- we'll create an associative array indexed by // source and record ID which points to the desired position of the indexed @@ -117,7 +134,7 @@ class Loader // Retrieve the records and put them back in order: $retVal = array(); foreach ($idBySource as $source => $details) { - $class = self::getClassForSource($source); + $class = $this->getClassForSource($source); $records = call_user_func(array($class, 'getRecords'), array_keys($details)); foreach ($records as $current) { @@ -142,4 +159,27 @@ class Loader ksort($retVal); return $retVal; } + + /** + * Set the service locator. + * + * @param ServiceLocatorInterface $serviceLocator Locator to register + * + * @return Manager + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + return $this; + } + + /** + * Get the service locator. + * + * @return \Zend\ServiceManager\ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } } diff --git a/module/VuFind/src/VuFind/Search/Favorites/Results.php b/module/VuFind/src/VuFind/Search/Favorites/Results.php index 354196d4098447a1d7ff56bff84bfbdbdf4195a9..2d6271eb950264530bc9cdadb4c5a43e63d00a49 100644 --- a/module/VuFind/src/VuFind/Search/Favorites/Results.php +++ b/module/VuFind/src/VuFind/Search/Favorites/Results.php @@ -172,7 +172,7 @@ class Results extends BaseResults ) ); } - $this->results = RecordLoader::loadBatch($recordsToRequest); + $this->results = RecordLoader::getInstance()->loadBatch($recordsToRequest); } /** diff --git a/module/VuFind/src/VuFind/Search/MixedList/Results.php b/module/VuFind/src/VuFind/Search/MixedList/Results.php index a29658b8ff30304e916cbb7a4c214a7cbd066ae5..2cc6001a249a722924adcf2cbf1515291ee5161d 100644 --- a/module/VuFind/src/VuFind/Search/MixedList/Results.php +++ b/module/VuFind/src/VuFind/Search/MixedList/Results.php @@ -62,7 +62,7 @@ class Results extends BaseResults protected function performSearch() { $recordsToRequest = $this->getParams()->getRecordsToRequest(); - $this->results = RecordLoader::loadBatch($recordsToRequest); + $this->results = RecordLoader::getInstance()->loadBatch($recordsToRequest); $this->resultTotal = count($this->results); } diff --git a/module/VuFind/src/VuFind/Search/Tags/Results.php b/module/VuFind/src/VuFind/Search/Tags/Results.php index 7a783934a6f6488161c5563716c319589e218c66..09873c0146fee406f9a7d349e3d558054c6b3bc0 100644 --- a/module/VuFind/src/VuFind/Search/Tags/Results.php +++ b/module/VuFind/src/VuFind/Search/Tags/Results.php @@ -74,7 +74,7 @@ class Results extends BaseResults $recordsToRequest[] = array('id' => $row->record_id, 'source' => $row->source); } - $this->results = RecordLoader::loadBatch($recordsToRequest); + $this->results = RecordLoader::getInstance()->loadBatch($recordsToRequest); } /**