From 6f764bf873a2651203f03c75093d5e5797948f01 Mon Sep 17 00:00:00 2001
From: Gregor Gawol <gawol@ub.uni-leipzig.de>
Date: Wed, 29 Apr 2015 15:40:41 +0200
Subject: [PATCH] refs #5088: * added record tab additional items

---
 module/finc/config/module.config.php          | 10 +++
 module/finc/src/finc/RecordDriver/Factory.php | 42 +++++++++
 .../src/finc/RecordDriver/SolrDefault.php     | 90 +++++++++++--------
 .../finc/RecordDriver/SolrMarcRemoteFinc.php  |  3 +-
 module/finc/src/finc/RecordTab/Additional.php | 61 +++++++++++++
 module/finc/src/finc/RecordTab/Factory.php    | 58 ++++++++++++
 .../finc/templates/RecordTab/additional.phtml | 31 +++++++
 7 files changed, 255 insertions(+), 40 deletions(-)
 create mode 100644 module/finc/src/finc/RecordTab/Additional.php
 create mode 100644 module/finc/src/finc/RecordTab/Factory.php
 create mode 100644 themes/finc/templates/RecordTab/additional.phtml

diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php
index ed86e87b651..f7d2497a736 100644
--- a/module/finc/config/module.config.php
+++ b/module/finc/config/module.config.php
@@ -32,6 +32,11 @@ $config = [
                     'redi' => 'finc\Resolver\Driver\Factory::getRedi',
                 ],
             ],
+            'recordtab' => [
+                'invokables' => [
+                    'additional' => 'finc\RecordTab\Additional',
+                ],
+            ],
         ],
         'recorddriver_tabs' => [
             'finc\RecordDriver\SolrDefault' => [
@@ -41,6 +46,7 @@ $config = [
                     'Reviews' => 'Reviews', 'Excerpt' => 'Excerpt',
                     'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map',
                     'Details' => 'StaffViewArray',
+                    'Additional' => 'Additional',
                 ],
                 'defaultTab' => null,
             ],
@@ -51,6 +57,7 @@ $config = [
                     'Reviews' => 'Reviews', 'Excerpt' => 'Excerpt',
                     'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map',
                     'Details' => 'StaffViewMARC',
+                    'Additional' => 'Additional',
                 ],
                 'defaultTab' => null,
             ],
@@ -62,6 +69,7 @@ $config = [
                     'Preview' => 'preview',
                     'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map',
                     'Details' => 'StaffViewMARC',
+                    'Additional' => 'Additional',
                 ],
                 'defaultTab' => null,
             ],
@@ -73,6 +81,7 @@ $config = [
                     'Preview' => 'preview',
                     'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map',
                     'Details' => 'StaffViewMARC',
+                    'Additional' => 'Additional',
                 ],
                 'defaultTab' => null,
             ],
@@ -83,6 +92,7 @@ $config = [
                     'Reviews' => 'Reviews', 'Excerpt' => 'Excerpt',
                     'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map',
                     'Details' => 'StaffViewArray',
+                    'Additional' => 'Additional',
                 ],
                 'defaultTab' => null,
             ],
diff --git a/module/finc/src/finc/RecordDriver/Factory.php b/module/finc/src/finc/RecordDriver/Factory.php
index 1336afd0ad0..6422c354fe7 100644
--- a/module/finc/src/finc/RecordDriver/Factory.php
+++ b/module/finc/src/finc/RecordDriver/Factory.php
@@ -40,6 +40,46 @@ use Zend\ServiceManager\ServiceManager;
  */
 class Factory
 {
+    /**
+     * Factory for SolrDefault record driver.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return SolrDefault
+     */
+    public static function getSolrDefault(ServiceManager $sm)
+    {
+        $driver = new SolrDefault(
+            $sm->getServiceLocator()->get('VuFind\Config')->get('config'),
+            null,
+            $sm->getServiceLocator()->get('VuFind\Config')->get('searches')
+        );
+        $driver->attachSearchService($sm->getServiceLocator()->get('VuFind\Search'));
+        return $driver;
+    }
+
+    /**
+     * Factory for SolrMarc record driver.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return SolrMarc
+     */
+    public static function getSolrMarc(ServiceManager $sm)
+    {
+        $driver = new SolrMarc(
+            $sm->getServiceLocator()->get('VuFind\Config')->get('config'),
+            null,
+            $sm->getServiceLocator()->get('VuFind\Config')->get('searches')
+        );
+        $driver->attachILS(
+            $sm->getServiceLocator()->get('VuFind\ILSConnection'),
+            $sm->getServiceLocator()->get('VuFind\ILSHoldLogic'),
+            $sm->getServiceLocator()->get('VuFind\ILSTitleHoldLogic')
+        );
+        $driver->attachSearchService($sm->getServiceLocator()->get('VuFind\Search'));
+        return $driver;
+    }
 
     /**
      * Factory for SolrMarcRemote record driver.
@@ -60,6 +100,7 @@ class Factory
             $sm->getServiceLocator()->get('VuFind\ILSHoldLogic'),
             $sm->getServiceLocator()->get('VuFind\ILSTitleHoldLogic')
         );
+        $driver->attachSearchService($sm->getServiceLocator()->get('VuFind\Search'));
         return $driver;
     }
 
@@ -98,6 +139,7 @@ class Factory
             $sm->getServiceLocator()->get('VuFind\ILSHoldLogic'),
             $sm->getServiceLocator()->get('VuFind\ILSTitleHoldLogic')
         );
+        $driver->attachSearchService($sm->getServiceLocator()->get('VuFind\Search'));
         return $driver;
     }
 }
diff --git a/module/finc/src/finc/RecordDriver/SolrDefault.php b/module/finc/src/finc/RecordDriver/SolrDefault.php
index 650787cf654..0a32460781f 100644
--- a/module/finc/src/finc/RecordDriver/SolrDefault.php
+++ b/module/finc/src/finc/RecordDriver/SolrDefault.php
@@ -31,6 +31,7 @@
  * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  */
 namespace finc\RecordDriver;
+use VuFindSearch\ParamBag;
 
 /**
  * finc specific model for Solr records based on the stock
@@ -325,20 +326,16 @@ class SolrDefault extends \VuFind\RecordDriver\SolrDefault
      * This method can be used to indicate a direct link than to form a general
      * look for query.
      *
-     * @todo                    1. Check if this method is still needed
-     * @todo                    2. Refactor Solr-Query to be compatible with VuFind2
-     *
      * @param array $rids Array of record ids to test.
      *
      * @return int mixed  If success return at least one finc id otherwise null.
-     * @deprecated        Not used.
      */
-    protected function addFincIDToRecord ( $array ) {
-/*
+    protected function addFincIDToRecord ( $array )
+    {
         // record ids
-        $rids = array();
+        $rids = [];
         // return array
-        $retval = array();
+        $retval = [];
 
         // check if array contain record_ids and collect it as an array to
         // use only one solr request for all
@@ -349,47 +346,36 @@ class SolrDefault extends \VuFind\RecordDriver\SolrDefault
                 }
             }
         }
-        // solr call
-        // call index
-        $index = $this->getIndexEngine();
-
-        // build query and accept limit of solr
-        $limit = $index->getBooleanClauseLimit();
-        if (count($rids) > $limit) {
-            $rids = array_slice($rids, 0, $limit);
-            $retVal = array();
-        }
+
         // build the query:
         if (count($rids) == 1) {
             // single query:
-            $query = "(record_id:". $rids[0] .")";
+            $value = '"'. $rids[0] .'"';
         } elseif (count($rids) > 1) {
             // multi query:
-            $query = 'record_id:(' . implode(' OR ', $rids) . ')';
+            $value = '(' . implode(' OR ', $rids) . ')';
         } else {
             return $array;
         }
-        // set hidden filter to limited the range
-        $this->setHiddenFilters();
-        // limited search for id and record_id values only
-        $result = $index->search($query, null, $this->hiddenFilters, 0, 100, null, '', null, null, 'id, record_id',  HTTP_REQUEST_METHOD_POST , false, false);
-
-        // log to find test data
-        // temporary logger
-        if (isset($result['response']['numFound'])
-            && isset($result['response']['numFound']) != 0) {
-        }
-        // if error break down
-        if (PEAR::isError($result)) {
-            return null;
-        }
-        if (isset($result['response']['docs'])
-            && !empty($result['response']['docs'])
+        $query = new \VuFindSearch\Query\Query(
+            'record_id:'. $value
+        );
+        //echo '</pre>'; print_r($query); echo '</pre>';
+
+        $bag = new ParamBag();
+        $bag->set('fl', 'id,record_id');
+        $records =  $this->searchService
+            ->search('Solr', $query, 0, count($rids), $bag);
+
+        $records = $records->getRecords();
+        if (isset($records)
+            && !empty($records)
         ) {
-            foreach( $result['response']['docs'] as $key => $doc) {
-                $retval[($doc['record_id'])]=$doc['id'];
+            foreach ($records as $record) {
+                $retval[$record->getRID()] = $record->getUniqueID();
             }
         }
+
         // write back in array
         foreach ($array as &$val) {
             if (isset($val['record_id'])) {
@@ -399,7 +385,7 @@ class SolrDefault extends \VuFind\RecordDriver\SolrDefault
             }
         }
         unset($val);
-        //echo "<pre>"; print_r($array); echo "</pre>";*/
+
         return $array;
     }
 
@@ -513,6 +499,32 @@ class SolrDefault extends \VuFind\RecordDriver\SolrDefault
             $this->fields['publishPlace'] : [];
     }
 
+    /**
+     * Get specific marc information about additional items. Unflexible solution
+     * for UBL only implemented.
+     *
+     * @return array
+     * @access protected
+     * @link https://intern.finc.info/fincproject/issues/1315
+     */
+    public function getAdditionals()
+    {
+        return [];
+    }
+
+    /**
+     * Check if Additional Items exists. Realized for instance of UBL only.
+     *
+     * @return boolean      True if additional items exists.
+     * @access public
+     * @link https://intern.finc.info/fincproject/issues/1315
+     */
+    public function hasAdditionalItems()
+    {
+        $array = $this->getAdditionals();
+        return (is_array($array) && count($array) > 0) ? true : false;
+    }
+
     /**
      * Filter author data for author year of birth and death
      * to give a better mark up.
diff --git a/module/finc/src/finc/RecordDriver/SolrMarcRemoteFinc.php b/module/finc/src/finc/RecordDriver/SolrMarcRemoteFinc.php
index ae17961f3e7..ced82917a5c 100644
--- a/module/finc/src/finc/RecordDriver/SolrMarcRemoteFinc.php
+++ b/module/finc/src/finc/RecordDriver/SolrMarcRemoteFinc.php
@@ -820,7 +820,7 @@ class SolrMarcRemoteFinc extends SolrMarcRemote
      * @access protected
      * @link https://intern.finc.info/fincproject/issues/1315
      */
-    protected function getAdditionals()
+    public function getAdditionals()
     {
         $array = [];
         $fields = ['770','775','776'];
@@ -854,6 +854,7 @@ class SolrMarcRemoteFinc extends SolrMarcRemote
                 } // end foreach
             }
         }
+
         return $this->addFincIDToRecord($array);
     }
 
diff --git a/module/finc/src/finc/RecordTab/Additional.php b/module/finc/src/finc/RecordTab/Additional.php
new file mode 100644
index 00000000000..c1b3b3ef793
--- /dev/null
+++ b/module/finc/src/finc/RecordTab/Additional.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Description tab
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2010.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @category VuFind2
+ * @package  RecordTabs
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:record_tabs Wiki
+ */
+namespace finc\RecordTab;
+
+/**
+ * Additional Items tab
+ *
+ * @category VuFind2
+ * @package  RecordTabs
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Gregor Gawol <gawol@ub.uni-leipzig.de>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:record_tabs Wiki
+ */
+class Additional extends \VuFind\RecordTab\AbstractBase
+{
+    /**
+     * Get the on-screen description for this tab.
+     *
+     * @return string
+     */
+    public function getDescription()
+    {
+        return 'Additional Items';
+    }
+
+    /**
+     * Is this tab active?
+     *
+     * @return bool
+     */
+    public function isActive()
+    {
+        return $this->getRecordDriver()->tryMethod('hasAdditionalItems');;
+    }
+}
\ No newline at end of file
diff --git a/module/finc/src/finc/RecordTab/Factory.php b/module/finc/src/finc/RecordTab/Factory.php
new file mode 100644
index 00000000000..b60934fa2a1
--- /dev/null
+++ b/module/finc/src/finc/RecordTab/Factory.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Record Tab Factory Class
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2014.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @category VuFind2
+ * @package  RecordDrivers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:hierarchy_components Wiki
+ */
+namespace finc\RecordTab;
+use Zend\ServiceManager\ServiceManager;
+
+/**
+ * Record Tab Factory Class
+ *
+ * @category VuFind2
+ * @package  RecordDrivers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Gregor Gawol <gawol@ub.uni-leipzig.de>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:hierarchy_components Wiki
+ *
+ * @codeCoverageIgnore
+ */
+class Factory extends \VuFind\RecordTab\Factory
+{
+    /**
+     * Factory for Additional Items tab plugin.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return Additional Items
+     */
+    public static function getAdditional(ServiceManager $sm)
+    {
+        return new Additional(
+            $sm->getServiceLocator()->get('VuFind\Config')->get('config')
+        );
+    }
+}
diff --git a/themes/finc/templates/RecordTab/additional.phtml b/themes/finc/templates/RecordTab/additional.phtml
new file mode 100644
index 00000000000..c5d6cacea3b
--- /dev/null
+++ b/themes/finc/templates/RecordTab/additional.phtml
@@ -0,0 +1,31 @@
+<?
+// Set page title.
+$this->headTitle($this->translate('Additionals') . ': ' . $this->driver->getBreadcrumb());
+
+// Grab clean ISBN for convenience:
+?>
+<table class="table table-striped" summary="<?=$this->transEsc('Description')?>">
+    <? $additionals = $this->driver->getAdditionals(); if (!empty($additionals) && is_array($additionals)): ?>
+        <? $contentDisplayed = true; ?>
+        <? foreach($additionals as $additional) :?>
+            <tr>
+                <th><?=$this->escapeHtml($additional['identifier'])?>: </th>
+                <td>
+                    <? if(isset($additional['id'])): ?>
+                    <a href="<?=$this->url('record')?><?=$this->escapeHtml($additional['id'])?>">
+                    <? endif; ?>
+                        <?=$this->escapeHtml($additional['text'])?>
+                    <? if(isset($additional['id'])): ?>
+                    </a>
+                    <? endif; ?>
+                </td>
+            </tr>
+        <? endforeach; ?>
+    <? else: ?>
+        <tr><td><?=$this->transEsc('Additional Items unavailable')?></td></tr>
+    <? endif; ?>
+
+    <? if (!isset($contentDisplayed) || !$contentDisplayed): // Avoid errors if there were no rows above ?>
+        <tr><td><?=$this->transEsc('Additional Items unavailable')?></td></tr>
+    <? endif; ?>
+</table>
-- 
GitLab