Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add mechanism to load links by AJAX based on DOI. - Implement data provider using BrowZine API.
- Loading branch information
1 parent
affa44a
commit a595b80
Showing
23 changed files
with
797 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* AJAX handler to look up DOI data. | ||
* | ||
* PHP version 7 | ||
* | ||
* Copyright (C) Villanova University 2018. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
namespace VuFind\AjaxHandler; | ||
|
||
use VuFind\DoiLinker\PluginManager; | ||
use Zend\Mvc\Controller\Plugin\Params; | ||
|
||
/** | ||
* AJAX handler to look up DOI data. | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
class DoiLookup extends AbstractBase | ||
{ | ||
/** | ||
* DOI Linker Plugin Manager | ||
* | ||
* @var PluginManager | ||
*/ | ||
protected $pluginManager; | ||
|
||
/** | ||
* DOI resolver configuration value | ||
* | ||
* @var string | ||
*/ | ||
protected $resolver; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param PluginManager $pluginManager DOI Linker Plugin Manager | ||
* @param string $resolver DOI resolver configuration value | ||
*/ | ||
public function __construct(PluginManager $pluginManager, $resolver) | ||
{ | ||
$this->pluginManager = $pluginManager; | ||
$this->resolver = $resolver; | ||
} | ||
|
||
/** | ||
* Handle a request. | ||
* | ||
* @param Params $params Parameter helper from controller | ||
* | ||
* @return array [response data, HTTP status code] | ||
*/ | ||
public function handleRequest(Params $params) | ||
{ | ||
$response = []; | ||
if ($this->pluginManager->has($this->resolver)) { | ||
$dois = (array)$params->fromQuery('doi', []); | ||
$response = $this->pluginManager->get($this->resolver)->getLinks($dois); | ||
} | ||
return $this->formatResponse($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Factory for DoiLookup AJAX handler. | ||
* | ||
* PHP version 7 | ||
* | ||
* Copyright (C) Villanova University 2018. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
namespace VuFind\AjaxHandler; | ||
|
||
use Interop\Container\ContainerInterface; | ||
|
||
/** | ||
* Factory for DoiLookup AJAX handler. | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
class DoiLookupFactory implements \Zend\ServiceManager\Factory\FactoryInterface | ||
{ | ||
/** | ||
* Create an object | ||
* | ||
* @param ContainerInterface $container Service manager | ||
* @param string $requestedName Service being created | ||
* @param null|array $options Extra options (optional) | ||
* | ||
* @return object | ||
* | ||
* @throws ServiceNotFoundException if unable to resolve the service. | ||
* @throws ServiceNotCreatedException if an exception is raised when | ||
* creating a service. | ||
* @throws ContainerException if any other error occurs | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, | ||
array $options = null | ||
) { | ||
if (!empty($options)) { | ||
throw new \Exception('Unexpected options passed to factory.'); | ||
} | ||
$config = $container->get('VuFind\Config\PluginManager')->get('config'); | ||
$pluginManager = $container->get('VuFind\DoiLinker\PluginManager'); | ||
return new $requestedName($pluginManager, $config->DOI->resolver ?? null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* BrowZine DOI linker | ||
* | ||
* PHP version 7 | ||
* | ||
* Copyright (C) Villanova University 2018. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package DOI | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
*/ | ||
namespace VuFind\DoiLinker; | ||
|
||
use VuFind\I18n\Translator\TranslatorAwareInterface; | ||
use VuFindSearch\Backend\BrowZine\Connector; | ||
|
||
/** | ||
* BrowZine DOI linker | ||
* | ||
* @category VuFind | ||
* @package DOI | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
*/ | ||
class BrowZine implements DoiLinkerInterface, TranslatorAwareInterface | ||
{ | ||
use \VuFind\I18n\Translator\TranslatorAwareTrait; | ||
|
||
/** | ||
* BrowZine connector | ||
* | ||
* @var Connector | ||
*/ | ||
protected $connector; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Connector $connector Connector | ||
*/ | ||
public function __construct(Connector $connector) | ||
{ | ||
$this->connector = $connector; | ||
} | ||
|
||
/** | ||
* Given an array of DOIs, perform a lookup and return an associative array | ||
* of arrays, keyed by DOI. Each array contains one or more associative arrays | ||
* with 'link' and 'label' keys. | ||
* | ||
* @param array $doiArray DOIs to look up | ||
* | ||
* @return array | ||
*/ | ||
public function getLinks(array $doiArray) | ||
{ | ||
$response = []; | ||
foreach ($doiArray as $doi) { | ||
$data = $this->connector->lookupDoi($doi)['data'] ?? null; | ||
if (!empty($data['browzineWebLink'])) { | ||
$response[$doi][] = [ | ||
'link' => $data['browzineWebLink'], | ||
'label' => $this->translate('View Complete Issue'), | ||
'data' => $data, | ||
]; | ||
} | ||
if (!empty($data['fullTextFile'])) { | ||
$response[$doi][] = [ | ||
'link' => $data['fullTextFile'], | ||
'label' => $this->translate('PDF Full Text'), | ||
'data' => $data, | ||
]; | ||
} | ||
} | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* BrowZine DOI linker factory | ||
* | ||
* PHP version 7 | ||
* | ||
* Copyright (C) Villanova University 2018. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package DOI | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
*/ | ||
namespace VuFind\DoiLinker; | ||
|
||
use Interop\Container\ContainerInterface; | ||
|
||
/** | ||
* BrowZine DOI linker factory | ||
* | ||
* @category VuFind | ||
* @package DOI | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
*/ | ||
class BrowZineFactory implements \Zend\ServiceManager\Factory\FactoryInterface | ||
{ | ||
/** | ||
* Create an object | ||
* | ||
* @param ContainerInterface $container Service manager | ||
* @param string $requestedName Service being created | ||
* @param null|array $options Extra options (optional) | ||
* | ||
* @return object | ||
* | ||
* @throws ServiceNotFoundException if unable to resolve the service. | ||
* @throws ServiceNotCreatedException if an exception is raised when | ||
* creating a service. | ||
* @throws ContainerException if any other error occurs | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, | ||
array $options = null | ||
) { | ||
if (!empty($options)) { | ||
throw new \Exception('Unexpected options passed to factory.'); | ||
} | ||
$backend = $container->get('VuFind\Search\BackendManager')->get('BrowZine'); | ||
return new $requestedName($backend->getConnector()); | ||
} | ||
} |
Oops, something went wrong.