diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php index 374ff645e5622b381a9c8fbf54051fc93e15cfe9..b0e83c8d593279ed940399640b8c281d9f80554f 100644 --- a/library/Class/Exemplaire.php +++ b/library/Class/Exemplaire.php @@ -247,6 +247,11 @@ class Class_Exemplaire extends Storm_Model_Abstract { } + public function getTypeDoc() { + return $this->getNotice()->getTypeDoc(); + } + + public function getMailIntBib() { return $this->getIntBib()->getMail(); } diff --git a/library/Class/Notice/DoubleFinder.php b/library/Class/Notice/DoubleFinder.php index 603269183adc87a54249361b6361c221783e26be..0ac1edbf6d358056ce5179d2c86010e162018324 100644 --- a/library/Class/Notice/DoubleFinder.php +++ b/library/Class/Notice/DoubleFinder.php @@ -34,7 +34,7 @@ class Class_Notice_DoubleFinder { $_id; public function __construct($data, $library_id, $profil_id = null) { - $this->_data = (new Class_Entity())->updateAttributes($data); + $this->_data = new Class_Entity($data); $this->_barcode_uniq_mode = Class_CosmoVar::get(static::VAR_BARCODE_UNIQ_MODE); $this->_double_mode = Class_CosmoVar::get(static::VAR_DOUBLE_MODE); $this->_profil = Class_IntProfilDonnees::find($profil_id); @@ -65,6 +65,16 @@ class Class_Notice_DoubleFinder { } + public function getMatchedCriteria() { + return $this->_found_on; + } + + + public function getId() { + return $this->_id; + } + + protected function findByBarcodes() { if (!$this->_hasItems()) return; @@ -79,12 +89,11 @@ class Class_Notice_DoubleFinder { if (!$item['code_barres']) return; - $condition = ['code_barres' => $item['code_barres']]; + $conditions = ['code_barres' => $item['code_barres']]; if ($this->_barcode_uniq_mode == '1') - $condition['id_int_bib'] = (int) $this->_library->getId(); + $conditions['id_int_bib'] = (int) $this->_library->getId(); - if ($found = Class_Exemplaire::findFirstBy($condition)) - return $found->getIdNotice(); + return $this->_getRecordIdByItem($conditions); } @@ -93,8 +102,18 @@ class Class_Notice_DoubleFinder { || !$this->_library->isPergame()) return; - if ($found = Class_Exemplaire::findFirstBy(['id_origine' => $this->_data->getid_origine()])) - return $found->getIdNotice(); + return $this->_getRecordIdByItem(['id_origine' => $this->_data->getid_origine()]); + } + + + protected function _getRecordIdByItem($conditions) { + $founds = Class_Exemplaire::findAllBy($conditions); + if(empty($founds)) + return; + + foreach($founds as $found) + if($this->_data->gettype_doc() == $found->getTypeDoc()) + return $found->getIdNotice(); } @@ -141,14 +160,4 @@ class Class_Notice_DoubleFinder { return ($statuses = $this->_data->getstatut_exemplaires()) || $statuses['nb_ex'] > 0; } - - - public function getMatchedCriteria() { - return $this->_found_on; - } - - - public function getId() { - return $this->_id; - } } \ No newline at end of file diff --git a/tests/library/Class/Notice/DoubleFinderTest.php b/tests/library/Class/Notice/DoubleFinderTest.php index bdc96e966d421bf6e11de99df2e75170f44a912e..ff1204e1b8e556ef073d7a8341fc8cc61b1758f6 100644 --- a/tests/library/Class/Notice/DoubleFinderTest.php +++ b/tests/library/Class/Notice/DoubleFinderTest.php @@ -23,10 +23,12 @@ abstract class DoubleFinderTestCase extends ModelTestCase { protected $_storm_default_to_volatile = true, - $_data = [], $_library_id = 1, + $_data = [], + $_library_id = 1, $_finder, $_found; + public function setUp() { parent::setUp(); @@ -37,6 +39,32 @@ abstract class DoubleFinderTestCase extends ModelTestCase { protected function _prepareFixtures() { + $dilicom_item = $this->fixture('Class_Exemplaire', + ['id' => 2, + 'code_barres' => '0001-2', + 'id_origine' => '88903', + 'id_int_bib' => 1]); + + $this->fixture('Class_Notice', + ['id' => 2, + 'type_doc' => Class_TypeDoc::DILICOM, + 'isbn' => '2-85868-161-9', + 'clef_alpha' => 'JESUISNEBONHOMME--SARA--EDTHIERRYMAGNIER-2010-1', + 'exemplaires' => [$dilicom_item]]); + + $rss_item = $this->fixture('Class_Exemplaire', + ['id' => 3, + 'code_barres' => '159', + 'id_origine' => '789', + 'id_int_bib' => 1]); + + $this->fixture('Class_Notice', + ['id' => 3, + 'type_doc' => Class_TypeDoc::RSS, + 'isbn' => '2-85868-161-9', + 'clef_alpha' => 'JESUISNEBONHOMME--SARA--EDTHIERRYMAGNIER-2010-1', + 'exemplaires' => [$rss_item]]); + $item = $this->fixture('Class_Exemplaire', ['id' => 1, 'code_barres' => '159', @@ -45,6 +73,7 @@ abstract class DoubleFinderTestCase extends ModelTestCase { $this->fixture('Class_Notice', ['id' => 1, + 'type_doc' => Class_TypeDoc::LIVRE, 'isbn' => '2-85868-161-9', 'clef_alpha' => 'JESUISNEBONHOMME--SARA--EDTHIERRYMAGNIER-2010-1', 'exemplaires' => [$item]]); @@ -157,7 +186,8 @@ class DoubleFinderWithExistingItemInAnotherLibraryTest extends DoubleFinderTestC class DoubleFinderWithExistingItemAndNoDedupModeTest extends DoubleFinderWithRecordMatchingTestCase { - protected $_data = ['statut_exemplaires' => ['nb_ex' => 1], + protected $_data = ['type_doc' => Class_TypeDoc::LIVRE, + 'statut_exemplaires' => ['nb_ex' => 1], 'exemplaires' => [ ['code_barres' => '159'] ]]; @@ -199,7 +229,8 @@ class DoubleFinderWithExistingIdOrigneNoDedupModeDefaultTest extends DoubleFinde class DoubleFinderWithExistingIdOrigneNoDedupModeForNanookTestTest extends DoubleFinderWithRecordMatchingTestCase { - protected $_data = ['id_origine' => '88903']; + protected $_data = ['type_doc' => Class_TypeDoc::LIVRE, + 'id_origine' => '88903']; protected function _prepareFixtures() { parent::_prepareFixtures(); @@ -215,7 +246,7 @@ class DoubleFinderWithExistingIdOrigneNoDedupModeForNanookTestTest extends Doubl /** @test */ - public function shouldHaveMatchedBarcode() { + public function shouldHaveMatchedIdOrigine() { $this->assertEquals('id_origine', $this->_finder->getMatchedCriteria()); } }