From f8a2f485124290705a4e4c146d2e2a3bcab88419 Mon Sep 17 00:00:00 2001
From: Robert Lange <robert.lange@uni-leipzig.de>
Date: Fri, 20 Nov 2020 19:29:31 +0100
Subject: [PATCH] refs #17613 [finc: VF5.1] barfs recent acquisitions feature

* use solr instead of ils
** because not every instance has an ils
** because ils driver has not to be configured anymore
** but still use ils on local alpha for demo driver and missing indexExtension

* add finc New Items Plugin and Controller
** use indexExtension to create query for date range

* use radio selects instead of buttons for range
* add label-for options
* add legend and better translations (Choose Period)

* removes styling br
* adds mainbody for styling
---
 local/alpha/config/vufind/searches.ini        |  5 +-
 local/config/vufind/searches.ini              |  2 +-
 local/languages/de.ini                        |  1 +
 local/languages/en.ini                        |  1 +
 module/finc/config/module.config.php          |  4 +-
 .../src/finc/Controller/Plugin/NewItems.php   | 80 +++++++++++++++++++
 .../Controller/Plugin/NewItemsFactory.php     | 63 +++++++++++++++
 themes/finc/scss/compiled.scss                |  8 +-
 themes/finc/templates/search/newitem.phtml    | 65 ++++++++-------
 9 files changed, 192 insertions(+), 37 deletions(-)
 create mode 100644 module/finc/src/finc/Controller/Plugin/NewItems.php
 create mode 100644 module/finc/src/finc/Controller/Plugin/NewItemsFactory.php

diff --git a/local/alpha/config/vufind/searches.ini b/local/alpha/config/vufind/searches.ini
index c259bc11f28..6ac686dcbd2 100644
--- a/local/alpha/config/vufind/searches.ini
+++ b/local/alpha/config/vufind/searches.ini
@@ -26,4 +26,7 @@ highlighting = true
 
 [IndexShards]
 ai = ai.ub.uni-leipzig.de/solr/biblio
-main = index.ub.uni-leipzig.de/solr/biblio
\ No newline at end of file
+main = index.ub.uni-leipzig.de/solr/biblio
+
+[NewItem]
+method = ils
\ No newline at end of file
diff --git a/local/config/vufind/searches.ini b/local/config/vufind/searches.ini
index 64ab99beb2d..1dbec8eddd3 100644
--- a/local/config/vufind/searches.ini
+++ b/local/config/vufind/searches.ini
@@ -435,7 +435,7 @@ side[] = "ExpandFacets:Author"
 ; (see https://vufind.org/wiki/indexing:tracking_record_changes). If using the ILS,
 ; your driver must support the getNewItems() method.
 ; Valid options: ils, solr; default: ils
-method = ils
+method = solr
 ; Comma-separated list of date ranges to offer to the user (i.e. 1,5,30 = one day
 ; old, or five days old, or thirty days old). If using the "ils" method, be careful
 ; about raising the maximum age too high -- searching very long date ranges may put
diff --git a/local/languages/de.ini b/local/languages/de.ini
index dc6cfa7c850..b257ab271cb 100644
--- a/local/languages/de.ini
+++ b/local/languages/de.ini
@@ -217,6 +217,7 @@ Change Profile Data = "Benutzerdaten ändern"
 Change User PIN of Self-Checkout = "Benutzer-PIN für Selbstverbuchung ändern"
 Checkedout = "Ausgeliehene Medien"
 Checkedoutpermanent = "Längerfristige Ausleihen"
+Choose Period = Zeitraum auswählen
 Cite this = Zitieren
 Click here to view book = Volltext
 Clock = "Uhr"
diff --git a/local/languages/en.ini b/local/languages/en.ini
index be7410d3eeb..a4cb46bf4b9 100644
--- a/local/languages/en.ini
+++ b/local/languages/en.ini
@@ -355,6 +355,7 @@ By Alphabetical = "In Alphabetic Order"
 Cannot find similar records = "Cannot find similar records."
 Cassette = Cassette
 Checkedoutpermanent = "Checked Out Permanent Items"
+Choose Period = Choose Date Range
 # Chinese = "中文(繁體)"
 Chinese = Chinese
 Clock = ""
diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php
index f2631035d07..515cee83dff 100644
--- a/module/finc/config/module.config.php
+++ b/module/finc/config/module.config.php
@@ -51,9 +51,11 @@ $config = [
     'controller_plugins' => [
         'factories' => [
             'finc\Controller\Plugin\EmailHold' => 'finc\Controller\Plugin\EmailHoldFactory',
+            'finc\Controller\Plugin\NewItems' => 'finc\Controller\Plugin\NewItemsFactory'
         ],
         'aliases' => [
-            'emailHold' => 'finc\Controller\Plugin\EmailHold'
+            'emailHold' => 'finc\Controller\Plugin\EmailHold',
+            'newItems' => 'finc\Controller\Plugin\NewItems'
         ]
     ],
     'vufind' => [
diff --git a/module/finc/src/finc/Controller/Plugin/NewItems.php b/module/finc/src/finc/Controller/Plugin/NewItems.php
new file mode 100644
index 00000000000..25998371eac
--- /dev/null
+++ b/module/finc/src/finc/Controller/Plugin/NewItems.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * VuFind Action Helper - New Items Support Methods
+ *
+ * PHP version 7
+ *
+ * Copyright (C) Leipzig University Library 2020.
+ *
+ * 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  Controller_Plugins
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Robert Lange <lange@ub.uni-leipzig.de>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org Main Page
+ */
+namespace finc\Controller\Plugin;
+
+use Zend\Config\Config;
+use Zend\Mvc\Controller\Plugin\AbstractPlugin;
+
+/**
+ * Zend action helper to perform new items-related actions
+ *
+ * @category VuFind
+ * @package  Controller_Plugins
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Robert Lange <lange@ub.uni-leipzig.de>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org Main Page
+ */
+class NewItems extends \VuFind\Controller\Plugin\NewItems
+{
+    /**
+     * Main Configuration
+     *
+     * @var null|Config
+     */
+    protected $mainConfig;
+
+    /**
+     * Constructor
+     *
+     * @param Config $searchConfig Configuration
+     * @param Config $mainConfig Configuration
+     */
+    public function __construct(Config $searchConfig, Config $mainConfig)
+    {
+        $this->config = $searchConfig;
+        $this->mainConfig = $mainConfig;
+    }
+
+    /**
+     * Get a Solr filter to limit to the specified number of days.
+     *
+     * @param int $range Days to search
+     *
+     * @return string
+     */
+    public function getSolrFilter($range)
+    {
+        $field = 'first_indexed';
+        if (!empty($isilPrefix = $this->mainConfig->CustomIndex->indexExtension)) {
+            $field = "{$isilPrefix}_date";
+        }
+        return "$field:[NOW-{$range}DAY TO NOW]";
+    }
+}
diff --git a/module/finc/src/finc/Controller/Plugin/NewItemsFactory.php b/module/finc/src/finc/Controller/Plugin/NewItemsFactory.php
new file mode 100644
index 00000000000..42fe4cf4689
--- /dev/null
+++ b/module/finc/src/finc/Controller/Plugin/NewItemsFactory.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Factory for controller plugins.
+ *
+ * PHP version 7
+ *
+ * Copyright (C) Leipzig University Library 2020.
+ *
+ * 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  View_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Robert Lange <lange@ub.uni-leipzig.de>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ */
+namespace finc\Controller\Plugin;
+
+use Psr\Container\ContainerInterface;
+use finc\Controller\Plugin\NewItems;
+use Zend\ServiceManager\ServiceManager;
+
+/**
+ * Factory for controller plugins.
+ *
+ * @category VuFind
+ * @package  View_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   André Lahmann <lahmann@ub.uni-leipzig.de>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ *
+ * @codeCoverageIgnore
+ */
+class NewItemsFactory
+{
+    /**
+     * Construct the NewItems plugin.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return NewItems
+     */
+    public function __invoke(ContainerInterface $sm)
+    {
+        $search = $sm->get('VuFind\Config\PluginManager')->get('searches');
+        $config = isset($search->NewItem)
+            ? $search->NewItem : new \Zend\Config\Config([]);
+        return new NewItems($config, $sm->get('VuFind\Config\PluginManager')->get('config'));
+    }
+}
diff --git a/themes/finc/scss/compiled.scss b/themes/finc/scss/compiled.scss
index 2417d81d0df..21e429ef2b0 100644
--- a/themes/finc/scss/compiled.scss
+++ b/themes/finc/scss/compiled.scss
@@ -362,6 +362,11 @@ legend {
   padding-left: ($grid-gutter-width / 2);
   padding-right: ($grid-gutter-width / 2);
   width: auto;
+
+  // Recent acquisitions search form (search/NewItem)
+  .form-search-newitem & {
+    padding-left: 0;
+  }
 }
 
 //// label {}
@@ -521,7 +526,8 @@ select {
 }
 
 // remove icons in limiter select boxes in adv. search
-#advSearchForm .limiter-boxes select.form-control {
+#advSearchForm .limiter-boxes select.form-control,
+#newitem_department {
   background-image: none;
   height: auto;
 }
diff --git a/themes/finc/templates/search/newitem.phtml b/themes/finc/templates/search/newitem.phtml
index 90b2a2077bf..75049b76728 100644
--- a/themes/finc/templates/search/newitem.phtml
+++ b/themes/finc/templates/search/newitem.phtml
@@ -1,41 +1,40 @@
 <!-- finc - templates - search - newitem -->
 <?php
-    // Set up page title:
-    $this->headTitle($this->translate('New Item Search'));
-
-    // Set up breadcrumbs:
-    $this->layout()->breadcrumbs = '<li class="active">' . $this->transEsc('New Items') . '</li>';
-
-    // Convenience variable:
-    $offlineMode = $this->ils()->getOfflineMode();
+  // Set up page title:
+  $this->headTitle($this->translate('New Item Search'));
+  
+  // Set up breadcrumbs:
+  $this->layout()->breadcrumbs = '<li class="active">' . $this->transEsc('New Items') . '</li>';
+  
+  // Convenience variable:
+  $offlineMode = $this->ils()->getOfflineMode();
 ?>
-
-<h1><?=$this->transEsc('Find New Items')?></h1>
-<?php if ($offlineMode == "ils-offline"): ?>
-  <?=$this->render('Helpers/ils-offline.phtml', ['offlineModeMsg' => 'ils_offline_holdings_message'])?>
-<?php endif; ?>
-<form method="get" class="form-search-newitem">
-  <div class="form-group">
-    <label class="control-label"><?=$this->transEsc('Range')?>:</label>
-    <div class="btn-group" data-toggle="buttons">
+<div class="mainbody">
+  <h1><?= $this->transEsc('Find New Items') ?></h1>
+  <?php if ($offlineMode == "ils-offline"): ?>
+    <?= $this->render('Helpers/ils-offline.phtml', ['offlineModeMsg' => 'ils_offline_holdings_message']) ?>
+  <?php endif; ?>
+  <form method="get" class="form-search-newitem">
+    <div class="form-group">
+      <legend><?= $this->transEsc("Choose Period") ?>:</legend>
       <?php foreach ($this->ranges as $key => $range): ?>
-        <label class="btn btn-primary<?php if($key == 0): ?> active<?php endif ?>">
-          <input type="radio" name="range" id="newitem_range_<?=$this->escapeHtmlAttr($key)?>" value="<?=$this->escapeHtmlAttr($range)?>"<?=($key == 0) ? ' checked="checked"' : ''?>/>
-          <?=($range == 1) ? $this->transEsc('Yesterday') : $this->transEsc('past_days', ['%%range%%' => $this->escapeHtml($range)])?>
+        <input type="radio" name="range" id="newitem_range_<?= $this->escapeHtmlAttr($key) ?>" value="<?= $this->escapeHtmlAttr($range) ?>"<?= ($key == 0) ? ' checked="checked"' : '' ?>/>
+        <label for="newitem_range_<?= $this->escapeHtmlAttr($key) ?>">
+          <?= ($range == 1) ? $this->transEsc('From') . " " . $this->transEsc('Yesterday') : $this->transEsc('past_days', ['%%range%%' => $this->escapeHtml($range)]) ?>
         </label>
       <?php endforeach; ?>
     </div>
-  </div>
-  <?php if (is_array($this->fundList) && !empty($this->fundList)): ?>
-    <div class="form-group">
-      <label class="control-label" for="newitem_department"><?=$this->transEsc('Department')?>:</label>
-      <select id="newitem_department" name="department" size="10" class="form-control">
-      <?php foreach ($this->fundList as $fundId => $fund): ?>
-        <option value="<?=$this->escapeHtmlAttr($fundId)?>"><?=$this->transEsc($fund)?></option>
-      <?php endforeach; ?>
-      </select>
-    </div>
-  <?php endif; ?>
-  <input class="btn btn-primary" type="submit" name="submit" value="<?=$this->transEsc('Find')?>"/>
-</form>
+    <?php if (is_array($this->fundList) && !empty($this->fundList)): ?>
+      <div class="form-group">
+        <label class="control-label" for="newitem_department"><?= $this->transEsc('Department') ?>:</label>
+        <select id="newitem_department" name="department" size="10" class="form-control">
+          <?php foreach ($this->fundList as $fundId => $fund): ?>
+            <option value="<?= $this->escapeHtmlAttr($fundId) ?>"><?= $this->transEsc($fund) ?></option>
+          <?php endforeach; ?>
+        </select>
+      </div>
+    <?php endif; ?>
+    <input class="btn btn-primary" type="submit" name="submit" value="<?= $this->transEsc('Find') ?>"/>
+  </form>
+</div>
 <!-- finc - templates - search - newitem - END -->
-- 
GitLab