Skip to content
Snippets Groups Projects
Commit 9c47ff1f authored by Jean-Pascal Kanter's avatar Jean-Pascal Kanter :speech_balloon: Committed by Robert Lange
Browse files

adjusted Ajax Boss Handler:

* added some more in-depth doc texts
* deleted an unncessary function and replaced it with standard calls
* made callnumber retrival slightly more resilient
parent 5621afcf
Branches
Tags v1.0.1
No related merge requests found
Pipeline #18490 passed with stage
in 27 seconds
......@@ -6,6 +6,10 @@
{
"name": "Gregor Gawol",
"email": "gawol@ub.uni-leipzig.de"
},
{
"name": "Pascal Kanter",
"email": "kanter@ub.uni-leipzig.de"
}
],
"require": {
......
......@@ -132,8 +132,8 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
// Obtain user information from ILS:
$library = isset($libraries[$homeLibrary]) ?
$libraries[$homeLibrary] : $libraries['AAAAA'];
$network = $library->getNetwork();
$boss = $library->getBoss();
$network = strtolower($library->getNetwork());
$isil = $library->getIsil();
$driver = $this->recordLoader->load(
$params->fromQuery('id'),
......@@ -172,19 +172,15 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
$this->config->General->networks->toArray() : [];
$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);
$callnumber = $this->getCallnumbers($isil, $isilCallNumber);
$isISIL = $inArray && $isISXNZBD ?
$this->isISIL($isilCallNumber['isils'], $boss) : false;
$isISIL = $inArray && $isISXNZBD ? key_exists($isil, $isilCallNumber): false;
$view = [
'homeLibrary' => ($homeLibrary == "AAAAA") ? true : false,
......@@ -204,65 +200,46 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
/**
* Get the call numbers of a certain isil
*
* @param $namespace
* @param $data
* @param $isil - ISIL of the library, like DE-15
* @param $data - Array of CallNumbers with Key:Value equal to ISIL:Number (and sometimes ISIL:[Number])
*
* @return array
* @return array of deduplicated callnumbers
*/
private function getCallnumbers($namespace, $data)
private function getCallnumbers($isil, $data)
{
if ($this->isISIL(array_keys($data), $namespace)) {
$cnValue = [];
foreach ($data as $key => $value) {
if (preg_match('/' . $namespace . '/', $key) && !empty($value)) {
$cnValue[] = $value;
}
if ( !array_key_exists($isil, $data) ) {return [];}
// somestimes the value is just a value, sometimes its an array of value, untidy!
if ( !is_array($data[$isil])) { $data[$isil] = [$data[$isil]]; }
$cnValue = [];
foreach ( $data[$isil] as $number) {
if (!empty($number) && !in_array($number, $cnValue)) {
$cnValue[] = $number;
}
return $cnValue;
}
return [];
return $cnValue;
}
/**
* Get all call numbers with array structure
* [ isil => call number]
*
* @param $results
* @param array $raw_data as it comes from the interface
* usually [Holding => [ 0 => ['isil', 'callnumber', 'issue'] ] ]
*
* @return array
* @return array of key:value as ISIL: [Callnumber], Callnumbers may be singular or multivalued
*/
private function getISILCallNumber($results)
private function getISILCallNumber($raw_data)
{
$retval = [];
$results = is_null($results) ? [] : $results;
foreach ($results as $result) {
foreach ($result as $holding) {
$tmp[] = $holding['isil'];
$retval[($holding['isil'])] = isset($holding['callnumber']) ?
$holding['callnumber'] : '';
$raw_data = is_null($raw_data) ? [] : $raw_data;
foreach ($raw_data as $row) {
foreach ($row as $holding) {
$retval[$holding['isil']] = isset($holding['callnumber']) ? $holding['callnumber'] : '';
}
}
$retval['isils'] = !empty($tmp) ? $tmp : [];
if (empty($results)) {
$retval['isils'] = [];
}
return $retval;
}
/**
* Has the isil call numbers?
*
* @param $data
* @param $isil
*
* @return bool
*/
private function isISIL($data, $isil)
{
return preg_grep('/'.$isil.'/', $data) ?
true : false;
}
}
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