From 615a46a1439443c113ad02066b309d69f95a6e95 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Tue, 26 Jan 2016 14:01:52 +0100 Subject: [PATCH] hotline #37288 improve localisation with cote --- VERSIONS_HOTLINE/37288 | 1 + library/Class/Exemplaire.php | 10 ++++++++ library/Class/Localisation.php | 11 +++++---- tests/library/Class/LocalisationTest.php | 30 ++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 VERSIONS_HOTLINE/37288 diff --git a/VERSIONS_HOTLINE/37288 b/VERSIONS_HOTLINE/37288 new file mode 100644 index 00000000000..9425e79c1d9 --- /dev/null +++ b/VERSIONS_HOTLINE/37288 @@ -0,0 +1 @@ + - ticket #37288 : Affinement de la localisation des exemplaires grace à la cote récupérée depuis le webservice \ No newline at end of file diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php index 697b53c3c03..618854ad9b7 100644 --- a/library/Class/Exemplaire.php +++ b/library/Class/Exemplaire.php @@ -79,6 +79,16 @@ 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()))) + return $sigb_cote; + + return $this->getCote(); + } + + public function getLibelleSite() { if (null === ($site = Class_CodifAnnexe::findFirstBy(['code' => (string)$this->getAnnexe()]))) return ''; diff --git a/library/Class/Localisation.php b/library/Class/Localisation.php index 3bfc0130b59..e6ef278ee1e 100644 --- a/library/Class/Localisation.php +++ b/library/Class/Localisation.php @@ -236,6 +236,7 @@ class Class_Localisation extends Storm_Model_Abstract { return null; $quality += $cote_quality; + return [$quality => $this]; } @@ -244,18 +245,20 @@ class Class_Localisation extends Storm_Model_Abstract { if(!$this->hasCoteDebut() && !$this->hasCoteFin()) return 0; - if($this->hasCoteFin() && ($item->getCote() > $this->getCoteFin())) + $item_cote = $item->getBestCote(); + + if($this->hasCoteFin() && ($item_cote > $this->getCoteFin())) return -1; - if($this->hasCoteDebut() && ($item->getCote() < $this->getCoteDebut())) + if($this->hasCoteDebut() && ($item_cote < $this->getCoteDebut())) return -1; $cote_quality = 0; - if($this->hasCoteDebut() && ($item->getCote() >= $this->getCoteDebut())) + if($this->hasCoteDebut() && ($item_cote >= $this->getCoteDebut())) $cote_quality++; - if($this->hasCoteFin() && ($item->getCote() <= $this->getCoteFin())) + if($this->hasCoteFin() && ($item_cote <= $this->getCoteFin())) $cote_quality++; return $cote_quality; diff --git a/tests/library/Class/LocalisationTest.php b/tests/library/Class/LocalisationTest.php index 73c9007c820..261a037d123 100644 --- a/tests/library/Class/LocalisationTest.php +++ b/tests/library/Class/LocalisationTest.php @@ -35,6 +35,13 @@ class LocalisationTest extends Storm_Test_ModelTestCase { 'section' => 'A', 'type_doc' => 1]); + $this->fixture('Class_Localisation', + ['id' => 55, + 'id_bib' => 1, + 'libelle' => 'Polar', + 'cote_debut' => 'ROM AAA', + 'cote_fin' => 'ROM ZZZ']); + $this->fixture('Class_Localisation', ['id' => 2, 'id_bib' => 1, @@ -171,6 +178,25 @@ class LocalisationTest extends Storm_Test_ModelTestCase { Class_Localisation::getItemLocalisation($item)['libelle']); } -} -?> \ No newline at end of file + /** @test */ + public function romanByCoteFromSigbLocalisationShouldBePolar() { + $item = $this->fixture('Class_Exemplaire', + ['id' => 4, + 'id_bib' => 1, + 'cote' => 'ROM', + 'section' => '1', + 'type_doc' => 1, + 'annexe' => 1, + 'notice' => $this->fixture('Class_Notice', + ['id' => 2, + 'type_doc' => 1])]); + + $item->setSigbExemplaire(Storm_Test_ObjectWrapper::mock() + ->whenCalled('getCote') + ->answers('ROM POL')); + + $this->assertEquals('Polar', + Class_Localisation::getItemLocalisation($item)['libelle']); + } +} -- GitLab