From 8652eeec296fd6edbcb1bf0b6b99a738a6ef07df Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Fri, 16 Dec 2016 15:37:09 +0100
Subject: [PATCH] dev #50182 reporting : better variables filtering

---
 library/Class/AdminVar.php                    |  2 +-
 library/Class/Systeme/Report.php              | 25 +++++++---
 library/Class/WebService/Redmine.php          | 48 +++++++++++--------
 .../Class/WebService/SIGB/Nanook/Service.php  |  2 +-
 public/admin/skins/bokeh74/global.css         |  2 +-
 .../ZendAfi/View/Helper/Status/HtmlTest.php   | 15 ++++--
 .../ZendAfi/View/Helper/Status/JsonTest.php   |  3 +-
 .../ZendAfi/View/Helper/Status/TestCase.php   |  2 +-
 8 files changed, 63 insertions(+), 36 deletions(-)

diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php
index a21e42f2f9a..2a9d6f7acce 100644
--- a/library/Class/AdminVar.php
+++ b/library/Class/AdminVar.php
@@ -393,7 +393,7 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
 
     foreach(explode(';', strtolower($langues_value)) as $langue)
       $langues []= trim($langue);
-    return array_unique(array_filter($langues));
+    return array_values(array_unique(array_filter($langues)));
   }
 
 
diff --git a/library/Class/Systeme/Report.php b/library/Class/Systeme/Report.php
index a5470abaf6d..2b0dd27db79 100644
--- a/library/Class/Systeme/Report.php
+++ b/library/Class/Systeme/Report.php
@@ -185,6 +185,8 @@ class Class_Systeme_Report_DigitalConnectors extends Class_Systeme_Report_Abstra
 }
 
 
+
+
 class Class_Systeme_Report_Libraries extends Class_Systeme_Report_Abstract {
   public function acceptVisitor($visitor) {
     $visitor->visitRecordHeader(['label' => $this->_('Label'),
@@ -206,14 +208,25 @@ class Class_Systeme_Report_Libraries extends Class_Systeme_Report_Abstract {
 
 }
 
+
+
+
 class Class_Systeme_Report_Variables extends Class_Systeme_Report_Abstract {
   public function acceptVisitor($visitor) {
-    foreach(Class_AdminVar::findAll() as $variable) {
-      if ($variable->getType() == 'raw-text' || $variable->getType() == "default"
-          || empty($variable->getValeur()))
-        continue;
-      $visitor->visitData($variable->getClef(), $variable->getClef(), $variable->getValeur());
-    }
+    $visitor->visitData('LANGUES', 'LANGUES', Class_AdminVar::getLangues());
+    (new Storm_Model_Collection(Class_AdminVar::findAll()))
+      ->select('isOnOff')
+      ->eachDo(function($variable) use ($visitor)
+               {
+                 $this->_reportVariable($visitor, $variable);
+               });
+  }
+
+
+  protected function _reportVariable($visitor, $variable) {
+    $visitor->visitData($variable->getClef(),
+                        $variable->getClef(),
+                        $variable->getValeur() ? $variable->getValeur() : 0);
   }
 }
 
diff --git a/library/Class/WebService/Redmine.php b/library/Class/WebService/Redmine.php
index 6cbc609bad0..02413d22508 100644
--- a/library/Class/WebService/Redmine.php
+++ b/library/Class/WebService/Redmine.php
@@ -19,35 +19,35 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
-class Class_WebService_Redmine extends Class_WebService_Abstract {
-  use Trait_Translator;
+ class Class_WebService_Redmine extends Class_WebService_Abstract {
+   use Trait_Translator;
 
-  const CUSTOM_PRIORITY_ID = 5;
-  const CUSTOM_MODULE_ID = 37;
-  const CUSTOM_CONTACT_PERSON = 43;
-  const CUSTOM_CUSTOMER = 1;
-  const CUSTOM_QUALIFICATION = 38;
+   const CUSTOM_PRIORITY_ID = 5;
+   const CUSTOM_MODULE_ID = 37;
+   const CUSTOM_CONTACT_PERSON = 43;
+   const CUSTOM_CUSTOMER = 1;
+   const CUSTOM_QUALIFICATION = 38;
 
-  protected static $_redmine_client, $_admin_client;
+   protected static $_redmine_client, $_admin_client;
 
-  protected
-    $_library,
-    $_custom_fields_cache,
-    $_issue_statuses_cache,
-    $_issue_priorities_cache;
+   protected
+     $_library,
+     $_custom_fields_cache,
+     $_issue_statuses_cache,
+     $_issue_priorities_cache;
 
 
-  public function __construct($library) {
-    $this->_library = $library;
-  }
+   public function __construct($library) {
+     $this->_library = $library;
+   }
 
 
-  public function getLibrary() {
-    return $this->_library;
-  }
+   public function getLibrary() {
+     return $this->_library;
+   }
 
 
-  protected function missingApiRequirement() {
+   protected function missingApiRequirement() {
     return ($error_message = $this->validate())
       ? ['error_message' => $error_message]
       : null;
@@ -139,10 +139,16 @@ class Class_WebService_Redmine extends Class_WebService_Abstract {
   protected function getIssuesWithParams($params=[]) {
     $params['project_id'] = Class_AdminVar::get('REDMINE_PROJECT_ID');
 
-    $data = $this->getIssueApi()->all($params);
+    try {
+      $data = $this->getIssueApi()->all($params);
+    } catch (Exception $e) {
+      return [];
+    }
+
     if (!isset($data['issues']))
       return [];
 
+
     return array_map([$this, 'newIssue'],
                      $data['issues']);
 
diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php
index d0f2e12c87b..c61bcdfe0b8 100644
--- a/library/Class/WebService/SIGB/Nanook/Service.php
+++ b/library/Class/WebService/SIGB/Nanook/Service.php
@@ -187,7 +187,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
     $validator = new ZendAfi_Validate_Url();
     if (!$validator->isValid($this->getServerRoot()))
       return implode("\n", $validator->getMessages());
-    xdebug_break();
+
     try {
       $this
         ->ilsdiGetRecords(1,
diff --git a/public/admin/skins/bokeh74/global.css b/public/admin/skins/bokeh74/global.css
index c71e47a09c6..47ae929ee8c 100755
--- a/public/admin/skins/bokeh74/global.css
+++ b/public/admin/skins/bokeh74/global.css
@@ -795,7 +795,7 @@ form .droite {
 
 
 .systeme_status dt {
-    width: 200px;
+    width: 400px;
     text-align: right;
     display: inline-block;
 }
diff --git a/tests/library/ZendAfi/View/Helper/Status/HtmlTest.php b/tests/library/ZendAfi/View/Helper/Status/HtmlTest.php
index c8b3bc6f427..8f906a85ccd 100644
--- a/tests/library/ZendAfi/View/Helper/Status/HtmlTest.php
+++ b/tests/library/ZendAfi/View/Helper/Status/HtmlTest.php
@@ -144,13 +144,20 @@ class ZendAfi_View_Helper_Status_HtmlTest extends ZendAfi_View_Helper_Status_Tes
 
 
   /** @test */
-  public function variablesOnOffShouldBeDisplayed() {
+  public function variableOnOffBibnumShouldBeDisplayed() {
      $this->assertXPathContentContains($this->_html,
                                       '//dl/dd[preceding-sibling::dt[text()="BIBNUM"]]',
                                       '1');
   }
 
 
+  /** @test */
+  public function variableUnsettedFormationsShouldBeDisplayed() {
+     $this->assertXPath($this->_html,
+                        '//dl/dd[preceding-sibling::dt[text()="FORMATIONS"]][text()="0"]');
+  }
+
+
   /** @test */
   public function variablesStringShouldNotBeDisplayed() {
      $this->assertNotXPathContentContains($this->_html,
@@ -160,10 +167,10 @@ class ZendAfi_View_Helper_Status_HtmlTest extends ZendAfi_View_Helper_Status_Tes
 
 
   /** @test */
-  public function variablesMultipleValuesShouldBeDisplayed() {
+  public function variablesLanguesValuesShouldBeDisplayed() {
     $this->assertXPathContentContains($this->_html,
-                                          '//dl/dd[preceding-sibling::dt[text()="LANGUES"]]',
-                                          'fr;en');
+                                      '//dl/dd[preceding-sibling::dt[text()="LANGUES"]]',
+                                      'fr,en');
   }
 
 }
diff --git a/tests/library/ZendAfi/View/Helper/Status/JsonTest.php b/tests/library/ZendAfi/View/Helper/Status/JsonTest.php
index 4415c13680d..4b6919382b3 100644
--- a/tests/library/ZendAfi/View/Helper/Status/JsonTest.php
+++ b/tests/library/ZendAfi/View/Helper/Status/JsonTest.php
@@ -413,7 +413,8 @@ class ZendAfi_View_Helper_Status_JsonTest extends ZendAfi_View_Helper_Status_Tes
   /** @test */
   public function booleanAndMultiplesVariablesShouldBeAvailable() {
     $this->assertEquals(['BIBNUM' => '1',
-                         'LANGUES' => 'fr;en'],
+                         'LANGUES' => ['fr', 'en'],
+                         'FORMATIONS' => '0'],
                         $this->_report['variables']);;
 
   }
diff --git a/tests/library/ZendAfi/View/Helper/Status/TestCase.php b/tests/library/ZendAfi/View/Helper/Status/TestCase.php
index c1550417ffb..1912afaa398 100644
--- a/tests/library/ZendAfi/View/Helper/Status/TestCase.php
+++ b/tests/library/ZendAfi/View/Helper/Status/TestCase.php
@@ -157,7 +157,7 @@ abstract class ZendAfi_View_Helper_Status_TestCase extends ViewHelperTestCase {
     Class_AdminVar::set('ARTE_VOD_SSO_KEY','secret');
     Class_AdminVar::set('BIBNUM', '1');
     Class_AdminVar::set('LANGUES', 'fr;en');
-
+    Class_AdminVar::set('FORMATIONS', '');
   }
 
 
-- 
GitLab