Newer
Older
<?php
/**
* Copyright (C) Leipzig University Library 2019.
*
* 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
*
* @author Gregor Gawol <gawol@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
*/
use Zend\Mvc\Controller\Plugin\Params;
use Zend\View\Renderer\RendererInterface;
class GetBoss extends \VuFind\AjaxHandler\AbstractBase
{
/**
* Top-level configuration
*
* @var Config
*/
protected $config;
/**
* HTTP Service
*
protected $bossClient;
/**
* Request
*
* @var Request
*/
protected $request;
/**
* Record loader
*
* @var Loader
*/
protected $recordLoader;
/**
/**
* View renderer
*
* @var RendererInterface
*/
protected $renderer;
/**
* Constructor
*
* @param Loader $loader VuFind Record Loader
* @param Request $request Request
* @param Client $fidClient Resolver Library Mapper
* @param RendererInterface $renderer view
*/
public function __construct(
$this->recordLoader = $loader;
$this->request = $request;
$this->renderer = $renderer;
}
/**
* Handle a request.
*
* @param Params $params Parameter helper from controller
*
* @return array [response data, HTTP status code]
*/
public function handleRequest(Params $params)
{
if (!isset($this->config->General)) {
return $this->formatResponse(
'Configuration file boss.ini not found',
self::STATUS_HTTP_BAD_REQUEST
);
}
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
if ($this->fidClient->isLoggedOn()) {
$user = $this->fidClient->requestUserDetails();
$libraries = $this->fidClient->requestLibraryList();
$homeLibrary = $user->getHomeLibrary();
// Obtain user information from ILS:
$library = isset($libraries[$homeLibrary]) ?
$libraries[$homeLibrary] : $libraries['AAAAA'];
$network = $library->getNetwork();
$boss = $library->getBoss();
$driver = $this->recordLoader->load(
$params->fromQuery('id'),
$params->fromQuery('source')
);
$seq = isset($this->config->Search->sequence) ?
$this->config->Search->sequence : [];
$fields = $driver->getRawData();
$results = false;
foreach ($seq as $data) {
if (isset($fields[$data])) {
$method = $this->config->Search->$data;
$value = $driver->tryMethod($method);
$methodName = "getRequest" . strtoupper($data);
$results = $this->bossClient->$methodName(
$value, strtoupper($network)
);
if (!empty($results['data'])) {
break;
}
// default search of boss
if (empty($results)) {
$author = $driver->tryMethod('getCombinedAuthors');
$author = count($author) > 0 ? $author[0] : '';
$title = $driver->tryMethod('getTitle');
$year = $driver->tryMethod('getPublishDateSort');
$results = $this->bossClient->getRequestQuery(
$author, $title, $year, strtoupper($network)
);
}
$isilCallNumber = $this->getISILCallNumber($results['data']);
$networks = isset($this->config->General->networks) ?
$addNetworks = isset($this->config->General->addNetworks) ?
$this->config->General->addNetworks->toArray() : [];
$network = strtolower($network);
$inArray = in_array($network, $networks);
$zdbId = $driver->tryMethod('getZdbId');
$isbns = $driver->tryMethod('getISBNs');
$isbns = count($isbns) > 0 ? $isbns[0] : '';
$results['param'] = !empty($results['param']) ? $results['param'] : $isbns;
$isISXNZBD = (!empty($isbns) || !empty($zdbId)) ? true : false;
$tmp = $isilCallNumber;
unset($tmp['isils']);
$callnumber = $this->getCallnumbers($boss, $tmp);
$isISIL = $inArray && $isISXNZBD ?

Gregor Gawol
committed
$this->isISIL($isilCallNumber['isils'], $boss) : false;
'homeLibrary' => ($homeLibrary == "AAAAA") ? true : false,

Gregor Gawol
committed
'isISIL' => $isISIL,
'isAddNetwork' => in_array($network, $addNetworks) ? true : false,
'url' => sprintf($this->config->SearchUrls->$network, $results['param']),
];
$html = $this->renderer->render('ajax/boss.phtml', $view);

Gregor Gawol
committed
return $this->formatResponse(compact('html', 'isISIL'));
private function getCallnumbers($namespace, $data)
{
if ($this->isISIL(array_keys($data), $namespace)) {
$cnValue = [];
foreach ($data as $key => $value) {
if (preg_match('/' . $namespace . '/', $key) && !empty($value)) {
$cnValue[] = $value;
}
}
return $cnValue;
}
return [];
}
private function getISILCallNumber($results)
{
$retval = [];
foreach ($results as $result) {
foreach ($result as $holding) {
$tmp[] = $holding['isil'];
$retval[($holding['isil'])] = isset($holding['callnumber']) ?
$holding['callnumber'] : '';
}
}
$retval['isils'] = !empty($tmp) ? $tmp : [];
return $retval;
}
private function isISIL($data, $isil)
{
return preg_grep('/'.$isil.'/', $data) ?
true : false;
}