From f21164f2665fb4383c07d1a4db59c8d09372f3c0 Mon Sep 17 00:00:00 2001
From: lbrun <leo@sandbox.pergame.net>
Date: Fri, 12 Feb 2016 15:43:32 +0100
Subject: [PATCH] hotline#37288_localisation_d_un_exemplaire_inccorect :

fix getBestCote -> get sigb exemplaire
---
 VERSIONS_HOTLINE/37288                   |  1 +
 library/Class/Exemplaire.php             |  6 +++---
 library/Class/Localisation.php           |  5 ++++-
 tests/library/Class/LocalisationTest.php | 11 +++++++++++
 4 files changed, 19 insertions(+), 4 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/37288

diff --git a/VERSIONS_HOTLINE/37288 b/VERSIONS_HOTLINE/37288
new file mode 100644
index 00000000000..54f149ec3de
--- /dev/null
+++ b/VERSIONS_HOTLINE/37288
@@ -0,0 +1 @@
+ - ticket #37288 : Correction de la localisation des exemplaires
\ No newline at end of file
diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php
index 618854ad9b7..1486ef51fe4 100644
--- a/library/Class/Exemplaire.php
+++ b/library/Class/Exemplaire.php
@@ -80,9 +80,9 @@ class Class_Exemplaire extends Storm_Model_Abstract {
 
 
   public function getBestCote() {
-    if($this->_sigb_exemplaire &&
-       ($sigb_cote = $this->_sigb_exemplaire->getCote()) &&
-       (strlen($sigb_cote) > strlen($this->getCote())))
+    if ($this->getSigbExemplaire() &&
+        ($sigb_cote = $this->getSigbExemplaire()->getCote()) &&
+        (strlen($sigb_cote) > strlen($this->getCote())))
       return $sigb_cote;
 
     return $this->getCote();
diff --git a/library/Class/Localisation.php b/library/Class/Localisation.php
index e6ef278ee1e..7afe7020da6 100644
--- a/library/Class/Localisation.php
+++ b/library/Class/Localisation.php
@@ -232,12 +232,15 @@ class Class_Localisation extends Storm_Model_Abstract {
 
     $quality = count(array_intersect_assoc($matching_datas, $exemplaire_datas));
 
+    if ($quality < count($matching_datas) && $quality < (count($exemplaire_datas)))
+      return null;
+
     if( 0 > ($cote_quality = $this->coteMatchingQuality($exemplaire)))
       return null;
 
     $quality += $cote_quality;
 
-    return [$quality => $this];
+    return ($quality > 0) ? [$quality => $this] : null;
   }
 
 
diff --git a/tests/library/Class/LocalisationTest.php b/tests/library/Class/LocalisationTest.php
index 261a037d123..ef9eabc9c23 100644
--- a/tests/library/Class/LocalisationTest.php
+++ b/tests/library/Class/LocalisationTest.php
@@ -87,6 +87,17 @@ class LocalisationTest extends Storm_Test_ModelTestCase {
                     'libelle' => 'CD Jazz',
                     'cote_debut' => 'CDJazz A',
                     'cote_fin' => 'CDJazz Z']);
+
+    $this->fixture('Class_Localisation',
+                   ['id' => 22,
+                    'id_bib' => 1,
+                    'annexe' => 1,
+                    'section' => 'J',
+                    'genre' => 'B',
+                    'libelle' => 'CD Jazz Broken',
+                    'cote_debut' => 'CDJazz A',
+                    'cote_fin' => 'CDJazz Z',
+                    'type_doc' => 2]);
   }
 
 
-- 
GitLab