From 7b83ab1b5c304d1c21300e958900f1cd307cebe7 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 5 Aug 2013 15:48:54 -0400
Subject: [PATCH] Extra columns in alphabrowse (resolves VUFIND-863). Thanks to
 Tod Olson.

---
 config/vufind/config.ini                      |  8 ++++
 .../Controller/AlphabrowseController.php      | 24 ++++++++++-
 themes/blueprint/css/styles.css               | 42 +++++++++++++++++++
 .../templates/alphabrowse/home.phtml          | 18 +++++++-
 4 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/config/vufind/config.ini b/config/vufind/config.ini
index 09655bcff3e..d452fc6c4f4 100644
--- a/config/vufind/config.ini
+++ b/config/vufind/config.ini
@@ -791,6 +791,14 @@ title = "By Title"
 lcc = "By Call Number"
 ;dewey = "By Call Number"
 
+; This section controls the return of extra columns for the different browses.
+; The key is the browse index, the value is a colon-separated string of extra 
+; Solr fields to return for display to the user.
+[AlphaBrowse_Extras]
+title = "author:format:publishDate"
+lcc = title
+dewey = title
+
 ; This section allows you to configure the values used for Cryptography; the
 ; HMACkey can be set to any value you like and should never be shared.  It is used
 ; to prevent users from tampering with certain URLs (for example, "place hold" form
diff --git a/module/VuFind/src/VuFind/Controller/AlphabrowseController.php b/module/VuFind/src/VuFind/Controller/AlphabrowseController.php
index dd66a7ef41e..702e7bba5c9 100644
--- a/module/VuFind/src/VuFind/Controller/AlphabrowseController.php
+++ b/module/VuFind/src/VuFind/Controller/AlphabrowseController.php
@@ -28,6 +28,7 @@
  */
 namespace VuFind\Controller;
 
+use VuFindSearch\ParamBag;
 /**
  * AlphabrowseController Class
  *
@@ -68,6 +69,14 @@ class AlphabrowseController extends AbstractBase
             );
         }
 
+        // Load any extras from config file
+        $extras = array();
+        if (isset($config->AlphaBrowse_Extras)) {
+            foreach ($config->AlphaBrowse_Extras as $key => $value) {
+                $extras[$key] = $value;
+            }
+        }
+
         // Connect to Solr:
         $db = $this->getServiceLocator()->get('VuFind\Search\BackendManager')
             ->get('Solr');
@@ -79,6 +88,12 @@ class AlphabrowseController extends AbstractBase
         $limit  = isset($config->AlphaBrowse->page_size)
             ? $config->AlphaBrowse->page_size : 20;
 
+        // Set up any extra parameters to pass
+        $extraParams = new ParamBag(); 
+        if (isset($extras[$source])) {
+            $extraParams->add('extras', $extras[$source]);
+        }
+
 
         // Create view model:
         $view = $this->createViewModel();
@@ -86,13 +101,13 @@ class AlphabrowseController extends AbstractBase
         // If required parameters are present, load results:
         if ($source && $from !== false) {
             // Load Solr data or die trying:
-            $result = $db->alphabeticBrowse($source, $from, $page, $limit);
+            $result = $db->alphabeticBrowse($source, $from, $page, $limit, $extraParams);
 
             // No results?    Try the previous page just in case we've gone past
             // the end of the list....
             if ($result['Browse']['totalCount'] == 0) {
                 $page--;
-                $result = $db->alphabeticBrowse($source, $from, $page, $limit);
+                $result = $db->alphabeticBrowse($source, $from, $page, $limit, $extraParams);
             }
 
             // Only display next/previous page links when applicable:
@@ -108,6 +123,11 @@ class AlphabrowseController extends AbstractBase
         $view->alphaBrowseTypes = $types;
         $view->from = $from;
         $view->source = $source;
+
+        // Pass information about extra columns on to theme
+        if (isset($extras[$source])) {
+            $view->extras = explode(':', $extras[$source]);
+        }
         return $view;
     }
 }
\ No newline at end of file
diff --git a/themes/blueprint/css/styles.css b/themes/blueprint/css/styles.css
index 3abc45c72bd..fd060b3d9da 100644
--- a/themes/blueprint/css/styles.css
+++ b/themes/blueprint/css/styles.css
@@ -201,6 +201,13 @@ ul.cartContent {
     background-color: #fff;
 }
 
+.alphaBrowseExtra {
+    display: block;
+    float: left;
+    padding-left: .75em;
+    line-height: 1.31em;
+}
+
 .alphaBrowseForm {
     zoom: 1;
 }
@@ -211,6 +218,41 @@ ul.cartContent {
     line-height: 1.31em;
 }
 
+.alphaBrowseSource_dewey .alphaBrowseHeading {
+    width: 200px;
+    padding-right: .5em;
+}
+
+.alphaBrowseSource_dewey .alphaBrowseColumn_title {
+    width: 450px;
+}
+
+.alphaBrowseSource_lcc .alphaBrowseHeading {
+    width: 200px;
+    padding-right: .5em;
+}
+
+.alphaBrowseSource_lcc .alphaBrowseColumn_title {
+    width: 450px;
+}
+
+.alphaBrowseSource_title .alphaBrowseHeading {
+    width: 300px;
+    padding-right: .5em;
+}
+
+.alphaBrowseSource_title .alphaBrowseColumn_author {
+    width: 200px;
+}
+
+.alphaBrowseSource_title .alphaBrowseColumn_format {
+    width: 100px;
+}
+
+.alphaBrowseSource_title .alphaBrowseColumn_publishDate {
+    width: 45px;
+}
+
 .alphaBrowseCount {
     float: right;
 }
diff --git a/themes/blueprint/templates/alphabrowse/home.phtml b/themes/blueprint/templates/alphabrowse/home.phtml
index a51ed02331c..346afbf9cd6 100644
--- a/themes/blueprint/templates/alphabrowse/home.phtml
+++ b/themes/blueprint/templates/alphabrowse/home.phtml
@@ -40,8 +40,8 @@
 
     <div class="alphaBrowseHeader"><?=$this->transEsc("alphabrowse_matches") ?></div>
       <? foreach ($this->result['Browse']['items'] as $i => $item): ?>
-        <div class="alphaBrowseEntry<? if ($i%2==1): echo ' alt'; endif; ?>">
-        <div class="alphaBrowseHeading">
+        <div class="alphaBrowseEntry<? if ($i%2==1): echo ' alt'; endif; ?> alphaBrowseSource_<?=$this->escapeHtml($this->source)?>">
+        <div class="alphaBrowseHeading alphaBrowseHeading_<?=$this->escapeHtml($this->source)?>">
           <? if ($item['count'] > 0): ?>
             <?/* linking using bib ids is generally more reliable than
               doing searches for headings, but headings give shorter
@@ -56,6 +56,20 @@
             <?=$this->escapeHtml($item['heading'])?>
           <? endif; ?>
         </div>
+        <? 
+          foreach ($this->extras as $ei => $extraName):
+            $extraData = $item['extras'][$extraName];
+        ?>
+          <div class="alphaBrowseExtra alphaBrowseColumn_<? echo $extraName?>">
+            <?
+              $extraDisplayArray = array();
+              foreach ($extraData as $j => $e) {
+                $extraDisplayArray = array_unique(array_merge($extraDisplayArray, $e));
+              }
+              echo (empty($extraDisplayArray)) ? '&nbsp;' : implode('<br />', $extraDisplayArray);
+            ?>
+          </div>
+        <? endforeach; ?>
         <div class="alphaBrowseCount"><? if ($item['count'] > 0): echo $item['count']; endif; ?></div>
         <div class="clear"></div>
 
-- 
GitLab