From 98b73d262df27c7358d61f4b6cd6e278d845cf1a Mon Sep 17 00:00:00 2001
From: Gregor Gawol <gawol@ub.uni-leipzig.de>
Date: Wed, 27 Mar 2019 12:50:57 +0100
Subject: [PATCH] modified ui

---
 res/theme/templates/ajax/boss.phtml | 22 ++++-----------
 src/AjaxHandler/GetBoss.php         | 43 +++++++++++++++++++++--------
 2 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/res/theme/templates/ajax/boss.phtml b/res/theme/templates/ajax/boss.phtml
index ea8cc1e..ca8a420 100644
--- a/res/theme/templates/ajax/boss.phtml
+++ b/res/theme/templates/ajax/boss.phtml
@@ -1,22 +1,10 @@
 <!-- dbis-module: ajax - dbis -->
 <div>
-    <? if (!empty($this->results)): ?>
-        <?=print_r($this->results);?>
-        <div class="openurls">
-            <ul>
-                <? /*foreach ($this->results as $result): ?>
-                    <li>
-                        <h3><?=$result['name']?></h3>
-                    </li>
-                    <? unset($result['name']); ?>
-                    <? foreach ($result as $db): ?>
-                        <li>
-                            <a href="<?=$db[0]->getUrl()?>" target="_blank"><?=$db[0]->getHeadline()?></a>
-                        </li>
-                    <? endforeach; ?>
-                <? endforeach;*/ ?>
-            </ul>
-        </div>
+    <? if (!empty($this->isISIL)): ?>
+        <?=$this->transEsc('Exemplar in Ihrer Heimatbibliothek vorhanden.');?>
+    <? else: ?>
+        <?=$this->transEsc('Nicht in Ihrer Heimatbibliothek vorhanden.');?>
     <? endif; ?>
+    <a href="<?=$this->url?>" target="_blank"><?=$this->transEsc('Mehr Informationen');?></a>
 </div>
 <!-- dbis-module: ajax - dbis - END -->
\ No newline at end of file
diff --git a/src/AjaxHandler/GetBoss.php b/src/AjaxHandler/GetBoss.php
index 9580999..d03135b 100644
--- a/src/AjaxHandler/GetBoss.php
+++ b/src/AjaxHandler/GetBoss.php
@@ -119,6 +119,12 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
      */
     public function handleRequest(Params $params)
     {
+        if (!isset($this->config->Search)) {
+            return $this->formatResponse(
+                'Configuration file boss.ini not found',
+                self::STATUS_HTTP_BAD_REQUEST
+            );
+        }
 //        if ($patron = $this->ils->patronLogin()) {
 //
 //            // Stop now if the user does not have valid catalog credentials available:
@@ -129,10 +135,15 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
 //                    $profile['homeLibrary'] : 'AAAAA';
 //                $this->rlm->checkLibConfig($bibId);
 //            }
+//        } else {
+//            $this->rlm->checkLibConfig('AAAAA');
 //        }
 
         // Sample BibId
         $this->rlm->checkLibConfig('UBL');
+        $networks = isset($this->config->Network->networks) ?
+            $this->config->Network->networks->toArray() : [];
+        $network = $this->rlm->getLibValue('network');
 
         $driver = $this->recordLoader->load(
             $params->fromQuery('id'),
@@ -149,7 +160,7 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
                 $methodName = "getRequest" . strtoupper($data);
                 // TODO library network value of configuration
                 $results = $this->bossClient->$methodName(
-                    $value, $this->rlm->getNetworkValueUpper()
+                    $value, strtoupper($this->rlm->getLibValue('network'))
                 );
                 if (!empty($results['data'])) {
                     break;
@@ -158,29 +169,35 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
         }
         // default search of boss
         if (empty($results)) {
-            $author = $driver->tryMethod('getAuthor');
+            $author = $driver->tryMethod('getCombinedAuthors');
+            $author = count($author) > 0 ? $author[0] : '';
             $title = $driver->tryMethod('getTitle');
-            $year = $driver->tryMethod('getYear');
-            $this->bossClient->getRequestQuery(
+            $year = $driver->tryMethod('getPublishDateSort');
+            $results = $this->bossClient->getRequestQuery(
                 $author, $title, $year,
-                $this->rlm->getNetworkValueUpper()
+                strtoupper($this->rlm->getLibValue('network'))
             );
         }
-        $isilCallNumber = $this->getISILCallNumber($results);
-        $network = $this->rlm->getNetworkValueLower();
+
+        $isilCallNumber = $this->getISILCallNumber($results['data']);
+        $inArray = in_array($network, $networks);
+        $isbns = $driver->tryMethod('getISBNs');
+        $isbns = count($isbns) > 0 ? $isbns[0] : '';
         $view = [
-            'isISIL' => $this->isISIL($isilCallNumber['isils'], $this->rlm->getBossValue()),
-            'url' => sprintf($this->config->Search->$network, $results['param'])
+            'isISIL' => ($inArray ?
+                $this->isISIL($isilCallNumber['isils'], $this->rlm->getLibValue('boss')) : false),
+            'url' => sprintf($this->config->SearchUrls->$network, ($inArray ?
+                $results['param'] : $isbns))
         ];
+
         $html = $this->renderer->render('ajax/boss.phtml', $view);
         return $this->formatResponse(compact('html'));
     }
 
     private function getISILCallNumber($results)
     {
-        $tmp = [];
         $retval = [];
-
+        $results = is_null($results) ? [] : $results;
         foreach ($results as $result) {
             foreach ($result as $holding) {
                 $tmp[] = $holding['isil'];
@@ -191,6 +208,10 @@ class GetBoss extends \VuFind\AjaxHandler\AbstractBase
 
         $retval['isils'] = !empty($tmp) ? $tmp : [];
 
+        if (empty($results)) {
+            $retval['isils'] = [];
+        }
+
         return $retval;
     }
 
-- 
GitLab