The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

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