From 523e9fdd003e16009f57eae90ebb78ff31691724 Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Tue, 1 Dec 2015 16:14:07 +0100
Subject: [PATCH] dev #33757 fix rt comments

---
 .../admin/controllers/CatalogueController.php |  9 +--------
 .../opac/views/scripts/abonne/settings.phtml  |  2 --
 library/Class/MoteurRecherche/Facettes.php    | 17 ++++++++--------
 library/Class/User/Settings.php               | 20 +++++++++++++++----
 library/Class/Users.php                       |  2 +-
 .../AbonneControllerSettingsTest.php          |  2 +-
 6 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/application/modules/admin/controllers/CatalogueController.php b/application/modules/admin/controllers/CatalogueController.php
index d69f873ad9c..8b4d323dcbb 100644
--- a/application/modules/admin/controllers/CatalogueController.php
+++ b/application/modules/admin/controllers/CatalogueController.php
@@ -255,13 +255,6 @@ class Admin_CatalogueController extends ZendAfi_Controller_Action {
 
 
   public function viewableDomainsJsonAction() {
-    $this->_helper->viewRenderer->setNoRender();
-
-    $data = [];
-    $data[] = Class_Catalogue::getViewableDomainJson();
-    $JSON = json_encode($data);
-
-    $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8');
-    $this->getResponse()->setBody($JSON);
+    $this->_helper->json([Class_Catalogue::getViewableDomainJson()]);
   }
 }
\ No newline at end of file
diff --git a/application/modules/opac/views/scripts/abonne/settings.phtml b/application/modules/opac/views/scripts/abonne/settings.phtml
index 307efa9fd96..fb242e29dad 100644
--- a/application/modules/opac/views/scripts/abonne/settings.phtml
+++ b/application/modules/opac/views/scripts/abonne/settings.phtml
@@ -1,5 +1,3 @@
 <?php
-//$this->openBoite($this->_('Mes préférences'));
 echo $this->renderForm($this->form);
-//$this->closeBoite();
 ?>
diff --git a/library/Class/MoteurRecherche/Facettes.php b/library/Class/MoteurRecherche/Facettes.php
index cba27361b3c..bebda653688 100644
--- a/library/Class/MoteurRecherche/Facettes.php
+++ b/library/Class/MoteurRecherche/Facettes.php
@@ -182,16 +182,17 @@ class Class_MoteurRecherche_Facettes {
     $user_bookmarks_codes = array_map(function($domain) {return $domain->getFacetThesaurus();}, $user_bookmarks);
 
     foreach($user_bookmarks_codes as $bookmark_code) {
-      if(isset($codes_count[$bookmark_code])) {
-        if(!$facet = Class_Notice_Facette::find($bookmark_code))
-          continue;
+      if(!isset($codes_count[$bookmark_code]))
+        continue;
 
-        if (!$facet_label = $facet->getLibelleFacette())
-          continue;
+      if(!$facet = Class_Notice_Facette::find($bookmark_code))
+        continue;
 
-        $matches[] = ['id' => $bookmark_code,
-                      'label' => $facet->getCodeRubriqueLibelle() . ' : ' . $facet_label . ' (' . $codes_count[$bookmark_code] . ')'];
-      }
+      if (!$facet_label = $facet->getLibelleFacette())
+        continue;
+
+      $matches[] = ['id' => $bookmark_code,
+                    'label' => $facet->getCodeRubriqueLibelle() . ' : ' . $facet_label . ' (' . $codes_count[$bookmark_code] . ')'];
     }
 
     return $matches;
diff --git a/library/Class/User/Settings.php b/library/Class/User/Settings.php
index c227e5355b0..b22fd5a6896 100644
--- a/library/Class/User/Settings.php
+++ b/library/Class/User/Settings.php
@@ -22,17 +22,30 @@
 class Class_User_Settings {
   const BOOKMARKED_DOMAINS = 'domain_ids';
 
-  protected $_user;
+  protected $_user, $_user_settings;
 
 
-  public function visitUser($user) {
+  public function setUser($user) {
     $this->_user = $user;
-    $this->_user_settings = unserialize($this->_user->getSettings());
+    return $this;
+  }
 
+
+  public function setUserSettings($settings) {
+    $this->_user_settings = $settings;
     return $this;
   }
 
 
+  public static function newWith($user) {
+    $instance = new Self();
+    $instance
+      ->setUser($user)
+      ->setUserSettings(unserialize($user->getSettings()));
+    return $instance;
+  }
+
+
   public function getBookmarkedDomains() {
     if(!isset($this->_user_settings[self::BOOKMARKED_DOMAINS]))
       return '';
@@ -54,6 +67,5 @@ class Class_User_Settings {
       return [];
     return unserialize($data);
   }
-
 }
 ?>
\ No newline at end of file
diff --git a/library/Class/Users.php b/library/Class/Users.php
index 59f71431968..0d0608beea5 100644
--- a/library/Class/Users.php
+++ b/library/Class/Users.php
@@ -1605,7 +1605,7 @@ class Class_Users extends Storm_Model_Abstract {
 
   protected function getSettingsModel() {
     if(!$this->_settings)
-      return $this->_settings = (new Class_User_Settings())->visitUser($this);
+      return $this->_settings = Class_User_Settings::newWith($this);
     return $this->_settings;
   }
 }
diff --git a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php
index c1f24d74a47..9052762c1ca 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php
@@ -38,7 +38,7 @@ class AbonneControllerSettingsFormTest extends AbstractControllerTestCase {
 
 
 
-class AbonneControllserSettingsFormPostTest extends AbstractControllerTestCase {
+class AbonneControllerSettingsFormPostTest extends AbstractControllerTestCase {
   protected $_storm_default_to_volatile = true, $_user;
 
   public function setUp() {
-- 
GitLab