diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index dc26b666f9b7475e38a47411bb3e7403582d5d02..50236a6b06376bf1ed6b3775c8009414b7aaa33e 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -608,6 +608,7 @@ $config = [ 'factories' => [ 'favorites' => 'VuFind\Search\Results\Factory::getFavorites', 'solr' => 'VuFind\Search\Results\Factory::getSolr', + 'tags' => 'VuFind\Search\Results\Factory::getTags', ], ], 'session' => [ diff --git a/module/VuFind/src/VuFind/Search/Base/Params.php b/module/VuFind/src/VuFind/Search/Base/Params.php index a14c0ef0af5be529888ba682d82bffa89b9c88b2..3c31272b23b2b515f60464cede207f2bcd9450f5 100644 --- a/module/VuFind/src/VuFind/Search/Base/Params.php +++ b/module/VuFind/src/VuFind/Search/Base/Params.php @@ -1684,19 +1684,6 @@ class Params implements ServiceLocatorAwareInterface return $this->setServiceLocatorThroughTrait($serviceLocator); } - /** - * Get a database table object. - * - * @param string $table Name of table to retrieve - * - * @return \VuFind\Db\Table\Gateway - */ - public function getTable($table) - { - return $this->getServiceLocator()->get('VuFind\DbTablePluginManager') - ->get($table); - } - /** * Translate a string (or string-castable object) * diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php index 4a94f9a9a022f0876ebfa45c99e60c9c47a52851..46f469c70f6934010ebe4e34249f4d522c8ae69e 100644 --- a/module/VuFind/src/VuFind/Search/Base/Results.php +++ b/module/VuFind/src/VuFind/Search/Base/Results.php @@ -610,19 +610,6 @@ abstract class Results implements ServiceLocatorAwareInterface return $this->searchService; } - /** - * Get a database table object. - * - * @param string $table Name of table to retrieve - * - * @return \VuFind\Db\Table\Gateway - */ - public function getTable($table) - { - return $this->getServiceLocator()->get('VuFind\DbTablePluginManager') - ->get($table); - } - /** * Translate a string if a translator is available (proxies method in Options). * diff --git a/module/VuFind/src/VuFind/Search/Favorites/Results.php b/module/VuFind/src/VuFind/Search/Favorites/Results.php index 24c942b4a8a4184d3a3bd80e4463267409b75ac3..8ea2c0b557616a55a1ff67333cce071ad5c0d2a0 100644 --- a/module/VuFind/src/VuFind/Search/Favorites/Results.php +++ b/module/VuFind/src/VuFind/Search/Favorites/Results.php @@ -26,11 +26,13 @@ * @link https://vufind.org Main Site */ namespace VuFind\Search\Favorites; -use VuFind\Exception\ListPermission as ListPermissionException, - VuFind\Search\Base\Results as BaseResults, - VuFind\Record\Cache, - ZfcRbac\Service\AuthorizationServiceAwareInterface, - ZfcRbac\Service\AuthorizationServiceAwareTrait; +use VuFind\Db\Table\Resource as ResourceTable; +use VuFind\Db\Table\UserList as ListTable; +use VuFind\Exception\ListPermission as ListPermissionException; +use VuFind\Search\Base\Results as BaseResults; +use VuFind\Record\Cache; +use ZfcRbac\Service\AuthorizationServiceAwareInterface; +use ZfcRbac\Service\AuthorizationServiceAwareTrait; /** * Search Favorites Results @@ -60,6 +62,36 @@ class Results extends BaseResults */ protected $list = false; + /** + * Resource table + * + * @var ResourceTable + */ + protected $resourceTable; + + /** + * UserList table + * + * @var ListTable + */ + protected $listTable; + + /** + * Constructor + * + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param ResourceTable $resourceTable Resource table + * @param ListTable $listTable UserList table + */ + public function __construct(\VuFind\Search\Base\Params $params, + ResourceTable $resourceTable, ListTable $listTable + ) { + parent::__construct($params); + $this->resourceTable = $resourceTable; + $this->listTable = $listTable; + } + /** * Returns the stored list of facets for the last search * @@ -146,10 +178,9 @@ class Results extends BaseResults } // How many results were there? - $resource = $this->getTable('Resource'); $userId = is_null($list) ? $this->user->id : $list->user_id; $listId = is_null($list) ? null : $list->id; - $rawResults = $resource->getFavorites( + $rawResults = $this->resourceTable->getFavorites( $userId, $listId, $this->getTagFilters(), $this->getParams()->getSort() ); $this->resultTotal = count($rawResults); @@ -157,7 +188,7 @@ class Results extends BaseResults // Apply offset and limit if necessary! $limit = $this->getParams()->getLimit(); if ($this->resultTotal > $limit) { - $rawResults = $resource->getFavorites( + $rawResults = $this->resourceTable->getFavorites( $userId, $listId, $this->getTagFilters(), $this->getParams()->getSort(), $this->getStartRecord() - 1, $limit ); @@ -204,12 +235,8 @@ class Results extends BaseResults // if one is found: $filters = $this->getParams()->getFilters(); $listId = isset($filters['lists'][0]) ? $filters['lists'][0] : null; - if (null === $listId) { - $this->list = null; - } else { - $table = $this->getTable('UserList'); - $this->list = $table->getExisting($listId); - } + $this->list = (null === $listId) + ? null : $this->listTable->getExisting($listId); } return $this->list; } diff --git a/module/VuFind/src/VuFind/Search/Results/Factory.php b/module/VuFind/src/VuFind/Search/Results/Factory.php index ff723c194597747cd4062dbd80c362b76fac1c17..03f4d1f300ca93787639e085ed91fd9eae352d45 100644 --- a/module/VuFind/src/VuFind/Search/Results/Factory.php +++ b/module/VuFind/src/VuFind/Search/Results/Factory.php @@ -46,12 +46,16 @@ class Factory * * @param ServiceManager $sm Service manager. * - * @return Favorites + * @return \VuFind\Search\Favorites\Results */ public static function getFavorites(ServiceManager $sm) { $factory = new PluginFactory(); - $obj = $factory->createServiceWithName($sm, 'favorites', 'Favorites'); + $tm = $sm->getServiceLocator()->get('VuFind\DbTablePluginManager'); + $obj = $factory->createServiceWithName( + $sm, 'favorites', 'Favorites', + [$tm->get('Resource'), $tm->get('UserList')] + ); $init = new \ZfcRbac\Initializer\AuthorizationServiceInitializer(); $init->initialize($obj, $sm); return $obj; @@ -62,7 +66,7 @@ class Factory * * @param ServiceManager $sm Service manager. * - * @return Solr + * @return \VuFind\Search\Solr\Results */ public static function getSolr(ServiceManager $sm) { @@ -77,4 +81,20 @@ class Factory ); return $solr; } + + /** + * Factory for Tags results object. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Search\Tags\Results + */ + public static function getTags(ServiceManager $sm) + { + $factory = new PluginFactory(); + $tm = $sm->getServiceLocator()->get('VuFind\DbTablePluginManager'); + return $factory->createServiceWithName( + $sm, 'tags', 'Tags', [$tm->get('Tags')] + ); + } } diff --git a/module/VuFind/src/VuFind/Search/Results/PluginFactory.php b/module/VuFind/src/VuFind/Search/Results/PluginFactory.php index 14f53b00a9f69ce8df27dfe909d401c5f305c1be..a5eab343f719e8f524259928eae0b51cf724297b 100644 --- a/module/VuFind/src/VuFind/Search/Results/PluginFactory.php +++ b/module/VuFind/src/VuFind/Search/Results/PluginFactory.php @@ -54,15 +54,18 @@ class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory * @param ServiceLocatorInterface $serviceLocator Service locator * @param string $name Name of service * @param string $requestedName Unfiltered name of service + * @param array $extraParams Extra constructor parameters + * (to follow the Params object) * * @return object */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, - $name, $requestedName + $name, $requestedName, array $extraParams = [] ) { $params = $serviceLocator->getServiceLocator() ->get('VuFind\SearchParamsPluginManager')->get($requestedName); $class = $this->getClassName($name, $requestedName); - return new $class($params); + array_unshift($extraParams, $params); + return new $class(...$extraParams); } } diff --git a/module/VuFind/src/VuFind/Search/Tags/Results.php b/module/VuFind/src/VuFind/Search/Tags/Results.php index 5cb79bf923174b1a5c8724f575c3a4be1c20f726..cda2bc4dcd0c98e00d69229db5f01068a29eb063 100644 --- a/module/VuFind/src/VuFind/Search/Tags/Results.php +++ b/module/VuFind/src/VuFind/Search/Tags/Results.php @@ -26,6 +26,7 @@ * @link https://vufind.org Main Site */ namespace VuFind\Search\Tags; +use VuFind\Db\Table\Tags as TagsTable; use VuFind\Search\Base\Results as BaseResults; /** @@ -39,6 +40,27 @@ use VuFind\Search\Base\Results as BaseResults; */ class Results extends BaseResults { + /** + * Tags table + * + * @var TagsTable + */ + protected $tagsTable; + + /** + * Constructor + * + * @param \VuFind\Search\Base\Params $params Object representing user search + * parameters. + * @param TagsTable $tagsTable Resource table + */ + public function __construct(\VuFind\Search\Base\Params $params, + TagsTable $tagsTable + ) { + parent::__construct($params); + $this->tagsTable = $tagsTable; + } + /** * Process a fuzzy tag query. * @@ -62,11 +84,10 @@ class Results extends BaseResults */ protected function performTagSearch($fuzzy) { - $table = $this->getTable('Tags'); $query = $fuzzy ? $this->formatFuzzyQuery($this->getParams()->getDisplayQuery()) : $this->getParams()->getDisplayQuery(); - $rawResults = $table->resourceSearch( + $rawResults = $this->tagsTable->resourceSearch( $query, null, $this->getParams()->getSort(), 0, null, $fuzzy ); @@ -76,7 +97,7 @@ class Results extends BaseResults // Apply offset and limit if necessary! $limit = $this->getParams()->getLimit(); if ($this->resultTotal > $limit) { - $rawResults = $table->resourceSearch( + $rawResults = $this->tagsTable->resourceSearch( $query, null, $this->getParams()->getSort(), $this->getStartRecord() - 1, $limit, $fuzzy );