From 2458296ae3dfd30ad7a4f5a6658e05f7f17cb063 Mon Sep 17 00:00:00 2001
From: Anna Headley <anna3LC@gmail.com>
Date: Thu, 12 Dec 2013 11:27:48 -0500
Subject: [PATCH] favorites list menu viewable on all myresearch pages -
 eliminated treatment of lists as special-case facets - resolves VUFIND-939

---
 .../src/VuFind/Recommend/FavoriteFacets.php   |  2 +-
 .../src/VuFind/Search/Favorites/Results.php   | 23 +++++++++---------
 .../templates/Recommend/FavoriteFacets.phtml  | 24 -------------------
 .../blueprint/templates/myresearch/menu.phtml | 19 +++++++++++++++
 .../templates/myresearch/mylist.phtml         |  2 +-
 .../templates/myresearch/mylist.phtml         |  2 +-
 .../templates/Recommend/FavoriteFacets.phtml  | 12 ----------
 .../bootstrap/templates/myresearch/menu.phtml | 11 +++++++++
 .../templates/myresearch/mylist.phtml         |  4 ++--
 9 files changed, 46 insertions(+), 53 deletions(-)

diff --git a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
index a8032f5f38f..57f368ec8da 100644
--- a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
@@ -51,6 +51,6 @@ class FavoriteFacets extends SideFacets
      */
     public function setConfig($settings)
     {
-        $this->mainFacets = array('lists' => 'Your Lists', 'tags' => 'Your Tags');
+        $this->mainFacets = array('tags' => 'Your Tags');
     }
 }
diff --git a/module/VuFind/src/VuFind/Search/Favorites/Results.php b/module/VuFind/src/VuFind/Search/Favorites/Results.php
index 1fa64498733..f2c4886bc99 100644
--- a/module/VuFind/src/VuFind/Search/Favorites/Results.php
+++ b/module/VuFind/src/VuFind/Search/Favorites/Results.php
@@ -40,7 +40,18 @@ use VuFind\Exception\ListPermission as ListPermissionException,
  */
 class Results extends BaseResults
 {
+    /**
+     * Object if user is logged in, false otherwise.
+     *
+     * @var \VuFind\Db\Row\User|bool
+     */
     protected $user = null;
+
+    /**
+     * Active user list (false if none).
+     *
+     * @var \VuFind\Db\Row\UserList|bool
+     */
     protected $list = false;
 
     /**
@@ -75,18 +86,6 @@ class Results extends BaseResults
                     'list' => array()
                 );
                 switch ($field) {
-                case 'lists':
-                    $lists = $this->user ? $this->user->getLists() : array();
-                    foreach ($lists as $list) {
-                        $this->facets[$field]['list'][] = array(
-                            'value' => $list->id,
-                            'displayText' => $list->title,
-                            'count' => $list->cnt,
-                            'isApplied' =>
-                                $this->getParams()->hasFilter("$field:".$list->id)
-                        );
-                    }
-                    break;
                 case 'tags':
                     if ($this->list) {
                         $tags = $this->list->getTags();
diff --git a/themes/blueprint/templates/Recommend/FavoriteFacets.phtml b/themes/blueprint/templates/Recommend/FavoriteFacets.phtml
index ff8343a82a2..13eafc7c047 100644
--- a/themes/blueprint/templates/Recommend/FavoriteFacets.phtml
+++ b/themes/blueprint/templates/Recommend/FavoriteFacets.phtml
@@ -2,30 +2,6 @@
 <div class="sidegroup">
   <? $sideFacetSet = $this->recommend->getFacetSet(); ?>
 
-  <? if (isset($sideFacetSet['lists']) && !empty($sideFacetSet['lists']['list'])): ?>
-    <div class="sidegroup">
-      <h4 class="list"><?=$this->transEsc($sideFacetSet['lists']['label'])?></h4>
-      <ul>
-        <? foreach ($sideFacetSet['lists']['list'] as $current): ?>
-          <li>
-            <? if ($current['isApplied']): ?>
-              <strong><?=$this->escapeHtml($current['displayText'])?></strong>
-            <? else: ?>
-              <a href="<?=$this->url('userList', array('id' => $current['value']))?>"><?=$this->escapeHtml($current['displayText'])?></a>
-            <? endif; ?>
-            (<?=$this->escapeHtml($current['count'])?>)
-          </li>
-        <? endforeach; ?>
-        <li>
-          <a href="<?=$this->url('editList', array('id'=>'NEW'))?>" title="<?=$this->transEsc('Create a List') ?>">
-            <?=$this->transEsc('Create a List') ?> 
-          </a>
-          <img src="<?=$this->imageLink('silk/add.png')?>" style="margin-left:2px;vertical-align:text-bottom"/>
-        </li>
-      </ul>
-    </div>
-  <? endif; ?>
-
   <? if (isset($sideFacetSet['tags']) && !empty($sideFacetSet['tags']['list'])): ?>
     <div class="sidegroup">
       <h4 class="tag"><?=$this->transEsc($sideFacetSet['tags']['label'])?></h4>
diff --git a/themes/blueprint/templates/myresearch/menu.phtml b/themes/blueprint/templates/myresearch/menu.phtml
index 77a27169746..5ada60e1006 100644
--- a/themes/blueprint/templates/myresearch/menu.phtml
+++ b/themes/blueprint/templates/myresearch/menu.phtml
@@ -10,4 +10,23 @@
     <? endif; ?>
     <li<?=$this->active == 'history' ? ' class="active"' : ''?>><a href="<?=$this->url('search-history')?>?require_login"><?=$this->transEsc('history_saved_searches')?></a></li>
   </ul>
+  <? if ($user = $this->auth()->isLoggedIn()): ?>
+    <h4 class="list"><?=$this->transEsc('Your Lists')?></h4>
+    <ul>
+      <li<?=$this->active == 'favorites' ? ' class="active"' : ''?>><a href="<?=$this->url('myresearch-favorites')?>"><?=$this->transEsc('Your Favorites')?></a></li>
+      <? $lists = $user->getLists() ?>
+      <? foreach ($lists as $list): ?>
+        <li<?=$this->active == 'list' . $list['id'] ? ' class="active"' : ''?>>
+          <a href="<?=$this->url('userList', array('id' => $list['id']))?>"><?=$this->escapeHtml($list['title'])?></a>
+          (<?=$list->cnt?>)
+        </li>
+      <? endforeach; ?>
+      <li>
+        <a href="<?=$this->url('editList', array('id'=>'NEW'))?>" title="<?=$this->transEsc('Create a List') ?>">
+          <?=$this->transEsc('Create a List') ?> 
+        </a>
+        <img src="<?=$this->imagelink('silk/add.png')?>" style="margin-left:2px;vertical-align:text-bottom"/>
+      </li>
+    </ul>
+  <? endif ?>
 </div>
diff --git a/themes/blueprint/templates/myresearch/mylist.phtml b/themes/blueprint/templates/myresearch/mylist.phtml
index a2b5c8346f6..6a7eb6cba1f 100644
--- a/themes/blueprint/templates/myresearch/mylist.phtml
+++ b/themes/blueprint/templates/myresearch/mylist.phtml
@@ -70,7 +70,7 @@
 </div>
 
 <div class="<?=$this->layoutClass('sidebar')?>">
-  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", array('active' => isset($list) ? 'list' : 'favorites'))?>
+  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", array('active' => isset($list) ? 'list' . $list['id'] : 'favorites'))?>
 
   <? foreach ($this->results->getRecommendations('side') as $current): ?>
     <?=$this->recommend($current)?>
diff --git a/themes/bootprint/templates/myresearch/mylist.phtml b/themes/bootprint/templates/myresearch/mylist.phtml
index 9725d17617b..5a747ecb509 100644
--- a/themes/bootprint/templates/myresearch/mylist.phtml
+++ b/themes/bootprint/templates/myresearch/mylist.phtml
@@ -74,7 +74,7 @@
 </div>
 
 <div class="<?=$this->layoutClass('sidebar')?>">
-  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", array('active' => isset($list) ? 'list' : 'favorites'))?>
+  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", array('active' => isset($list) ? 'list' . $list['id'] : 'favorites'))?>
 
   <? foreach ($this->results->getRecommendations('side') as $current): ?>
     <?=$this->recommend($current)?>
diff --git a/themes/bootstrap/templates/Recommend/FavoriteFacets.phtml b/themes/bootstrap/templates/Recommend/FavoriteFacets.phtml
index ea62ff471db..c6fe3fabcb3 100644
--- a/themes/bootstrap/templates/Recommend/FavoriteFacets.phtml
+++ b/themes/bootstrap/templates/Recommend/FavoriteFacets.phtml
@@ -1,18 +1,6 @@
 <? $results = $this->recommend->getResults(); ?>
 <? $sideFacetSet = $this->recommend->getFacetSet(); ?>
 
-<? if (isset($sideFacetSet['lists']) && !empty($sideFacetSet['lists']['list'])): ?>
-  <h4 class="list"><?=$this->transEsc($sideFacetSet['lists']['label'])?></h4>
-  <ul class="nav nav-list">
-  <? foreach ($sideFacetSet['lists']['list'] as $current): ?>
-    <li<? if ($current['isApplied']): ?> class="active"<? endif ?>>
-      <a href="<?=$this->url('userList', array('id' => $current['value']))?>"><?=$this->escapeHtml($current['displayText'])?> <span class="pull-right"><?=$this->escapeHtml($current['count'])?></span></a>
-    </li>
-  <? endforeach; ?>
-    <li><a href="<?=$this->url('editList', array('id'=>'NEW'))?>" title="<?=$this->transEsc('Create a List') ?>"><?=$this->transEsc('Create a List') ?> <span class="pull-right"><i class="icon-plus"></i></span></a></li>
-  </ul>
-<? endif; ?>
-
 <? if (isset($sideFacetSet['tags']) && !empty($sideFacetSet['tags']['list'])): ?>
   <h4 class="tag"><?=$this->transEsc($sideFacetSet['tags']['label'])?></h4>
   <ul class="nav nav-list">
diff --git a/themes/bootstrap/templates/myresearch/menu.phtml b/themes/bootstrap/templates/myresearch/menu.phtml
index 95da56187d4..969e8ae2840 100644
--- a/themes/bootstrap/templates/myresearch/menu.phtml
+++ b/themes/bootstrap/templates/myresearch/menu.phtml
@@ -10,3 +10,14 @@
   <li<?=$this->active == 'history' ? ' class="active"' : ''?>><a href="<?=$this->url('search-history')?>?require_login"><?=$this->transEsc('history_saved_searches')?> <i class="icon-search pull-right"></i></a></li>
   <li><a href="<?=$this->url('myresearch-logout')?>"><?=$this->transEsc("Log Out")?> <i class="icon-signout pull-right"></i></a></li>
 </ul>
+  <? if ($user = $this->auth()->isLoggedIn()): ?>
+    <h4 class="list"><?=$this->transEsc('Your Lists')?></h4>
+    <ul class="nav nav-list">
+      <li<?=$this->active == 'favorites' ? ' class="active"' : ''?>><a href="<?=$this->url('myresearch-favorites')?>"><?=$this->transEsc('Your Favorites')?> <i class="icon-star pull-right"></i></a></li>
+      <? $lists = $user->getLists() ?>
+      <? foreach ($lists as $list): ?>
+          <li<?=$this->active == 'list' . $list['id'] ? ' class="active"' : ''?>> <a href="<?=$this->url('userList', array('id' => $list['id']))?>"><?=$this->escapeHtml($list['title'])?> <span class="pull-right"><?=$list->cnt?></span></a></li>
+      <? endforeach; ?>
+      <li><a href="<?=$this->url('editList', array('id'=>'NEW'))?>" title="<?=$this->transEsc('Create a List') ?>"><?=$this->transEsc('Create a List') ?> <span class="pull-right"><i class="icon-plus"></i></span></a></li>
+    </ul>
+  <? endif ?>
diff --git a/themes/bootstrap/templates/myresearch/mylist.phtml b/themes/bootstrap/templates/myresearch/mylist.phtml
index 5c51fc71012..b3698cf8200 100644
--- a/themes/bootstrap/templates/myresearch/mylist.phtml
+++ b/themes/bootstrap/templates/myresearch/mylist.phtml
@@ -74,9 +74,9 @@
 </div>
 
 <div class="<?=$this->layoutClass('sidebar')?>">
-  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", array('active' => isset($list) ? 'list' : 'favorites'))?>
+  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", array('active' => isset($list) ? 'list' . $list['id'] : 'favorites'))?>
 
   <? foreach ($this->results->getRecommendations('side') as $current): ?>
     <?=$this->recommend($current)?>
   <? endforeach; ?>
-</div>
\ No newline at end of file
+</div>
-- 
GitLab