From c69448465073c8251b1335bd800e8b52e5ab1a73 Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Thu, 10 Nov 2016 17:11:49 +0100
Subject: [PATCH] hackfest : library widget default values

---
 .../ZendAfi/View/Helper/Accueil/Library.php   |  1 +
 .../View/Helper/Filters/Strategy/Elements.php |  6 +++--
 .../View/Helper/Filters/Strategy/Facet.php    | 22 ++++++++++++++++++-
 public/opac/js/renderFilters/list.css         | 12 ++++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/library/ZendAfi/View/Helper/Accueil/Library.php b/library/ZendAfi/View/Helper/Accueil/Library.php
index 9c9734ba81a..b724e676dda 100644
--- a/library/ZendAfi/View/Helper/Accueil/Library.php
+++ b/library/ZendAfi/View/Helper/Accueil/Library.php
@@ -26,6 +26,7 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba
     $_selected_filters = [],
     $_filter_settings;
 
+
   public function shouldCacheContent() {
     return false;
   }
diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php
index 3e71b453d22..14f9289cb89 100644
--- a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php
+++ b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php
@@ -50,8 +50,10 @@ abstract class ZendAfi_View_Helper_Filters_Strategy_Elements extends ZendAfi_Vie
   protected function _getSelectedElementsLabel() {
     $labels = [];
     foreach ($this->_getElements() as $value => $label) {
-      if ($this->_isSelected($value))
-        $labels [] = $label;
+      if (!$this->_isSelected($value))
+        return;
+
+      $labels [] = $label;
     }
 
     return $labels;
diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php
index 4605a625833..0715173891d 100644
--- a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php
+++ b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php
@@ -44,8 +44,28 @@ class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Fil
     $url = $this->view->url($url_params, null, true);
 
     return $this->_tag('li',
-                       $this->_getView()->tagAnchor($url, $label),
+                       $this->view->tagAnchor($url, $label)
+                       . $this->_setDefaultValue($value, $label),
                        $selected ? ['class' => 'selected'] : []);
   }
 
+
+  protected function _setDefaultValue($value, $label) {
+    if(!Class_Users::isCurrentUserCanAccesBackend())
+      return '';
+
+    $url_params = array_merge($this->_getUrlParams(),
+                              [$this->_getFilterKey() => $value],
+                              ['save_' . $this->_getFilterKey() => $value]);
+    $url = $this->view->url($url_params, null, true);
+
+    $saved_label = 'save_' . $label;
+    return $this->view->tag('input',
+                            '',
+                            ['type' => 'checkbox',
+                             'name' => $saved_label,
+                             'value' => $saved_label,
+                             'title' => $this->view->_('Appliquer le filtre %s par défaut', $label),
+                             'data-url' => $url]);
+  }
 }
\ No newline at end of file
diff --git a/public/opac/js/renderFilters/list.css b/public/opac/js/renderFilters/list.css
index 4bdcfeb1858..dcb111d3bc6 100644
--- a/public/opac/js/renderFilters/list.css
+++ b/public/opac/js/renderFilters/list.css
@@ -67,6 +67,7 @@
 
 .boite ul.filters.list ul li {
     display: block;
+    position: relative;
 }
 
 .boite ul.filters.list ul li input {
@@ -81,3 +82,14 @@
 .boite ul.filters.list .search h2 {
   display: none;
 }
+
+.boite ul.filters.list ul li a + input {
+    display: none;
+    position: absolute;
+    right: 5px;
+    top: 5px;
+}
+
+.boite ul.filters.list ul li:hover a + input {
+    display: block;
+}
\ No newline at end of file
-- 
GitLab