Skip to content
Snippets Groups Projects
Commit e92a20b2 authored by Dorian Merz's avatar Dorian Merz Committed by Robert Lange
Browse files

refs #19529 [finc] refactoring of "misspelled resources" mapping

* now uses YAML
* enables use of special characters
parent 00d93e4b
Branches
Tags
No related merge requests found
...@@ -78,6 +78,13 @@ class AmslResourceController extends AbstractBase ...@@ -78,6 +78,13 @@ class AmslResourceController extends AbstractBase
*/ */
protected $baseUrl; protected $baseUrl;
/**
* mapping of resource labels to be re-written for the query string
*
* @var array | null
*/
protected $resourceMapping;
/** /**
* Constructor * Constructor
* *
...@@ -91,13 +98,15 @@ class AmslResourceController extends AbstractBase ...@@ -91,13 +98,15 @@ class AmslResourceController extends AbstractBase
ServiceLocatorInterface $sm, ServiceLocatorInterface $sm,
\Zend\Config\Config $config, \Zend\Config\Config $config,
\VuFindHttp\HttpService $httpClient, \VuFindHttp\HttpService $httpClient,
\VuFind\Cache\Manager $cacheManager = null \VuFind\Cache\Manager $cacheManager = null,
array $resourceMapping = null
) { ) {
parent::__construct($sm); parent::__construct($sm);
$this->config = $config; $this->config = $config;
$this->apiConfig = $config->API; $this->apiConfig = $config->API;
$this->httpClient = $httpClient; $this->httpClient = $httpClient;
$this->cacheManager = $cacheManager; $this->cacheManager = $cacheManager;
$this->resourceMapping = $resourceMapping;
} }
/** /**
...@@ -265,16 +274,10 @@ class AmslResourceController extends AbstractBase ...@@ -265,16 +274,10 @@ class AmslResourceController extends AbstractBase
} }
if(!empty($mapping->show_link) && !empty($source[$mapping->sub_key])) { if(!empty($mapping->show_link) && !empty($source[$mapping->sub_key])) {
$misspelled = $this->config->get('MisspelledResources');
$searchTerm = $source[$mapping->sub_key]; $searchTerm = $source[$mapping->sub_key];
if (!empty($misspelled)) { // map the source label to the correct SOLR search term
foreach ($misspelled as $wrongLabel => $rightLabel) { $searchTerm = $this->resourceMapping[$searchTerm] ?? $searchTerm;
if (strpos($searchTerm, $wrongLabel) !== false) {
$searchTerm = $rightLabel;
break;
}
}
}
if (!$this->baseUrl) { if (!$this->baseUrl) {
$urlHelper = $this->getViewRenderer()->plugin('url'); $urlHelper = $this->getViewRenderer()->plugin('url');
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace finc\Controller; namespace finc\Controller;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use VuFind\Config\YamlReader;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
class AmslResourceControllerFactory class AmslResourceControllerFactory
...@@ -13,11 +14,13 @@ class AmslResourceControllerFactory ...@@ -13,11 +14,13 @@ class AmslResourceControllerFactory
*/ */
public function __invoke(ContainerInterface $container) public function __invoke(ContainerInterface $container)
{ {
$reader = $container->get('VuFind\YamlReader');
return new AmslResourceController( return new AmslResourceController(
$container, $container,
$container->get('VuFind\Config\PluginManager')->get('Amsl'), $container->get('VuFind\Config\PluginManager')->get('Amsl'),
$container->get('VuFindHttp\HttpService'), $container->get('VuFindHttp\HttpService'),
$container->get('VuFind\Cache\Manager') $container->get('VuFind\Cache\Manager'),
$reader->get('AmslResourceMapping.yaml')
); );
} }
} }
\ No newline at end of file
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