diff --git a/VERSIONS_HOTLINE/161009 b/VERSIONS_HOTLINE/161009 new file mode 100644 index 0000000000000000000000000000000000000000..121b91b2319fe56dc7cc4c8fb35898b0e399c751 --- /dev/null +++ b/VERSIONS_HOTLINE/161009 @@ -0,0 +1 @@ + - correctif #161009 : Recherche : Les données des exemplaires, tels que la côte, sont de nouveaux utilisables pour la recherche. \ No newline at end of file diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php index ec39cb870ead4e0bbb038f6f0ba5faff03e2fb4c..6126bfebdbf83ebe8308e145118cd0a1ab525020 100644 --- a/library/Class/Exemplaire.php +++ b/library/Class/Exemplaire.php @@ -194,6 +194,15 @@ class Class_Exemplaire extends Storm_Model_Abstract { } + public function getItemZone() : string { + + return (($data_profile = $this->getDataProfile()) + && ($item_zone = $data_profile->getItemZone())) + ? $item_zone + : Class_IntProfilDonnees::FIELD_ITEM_ZONE_DEFAULT; + } + + public function getBestCote() : string { $cote = $this->getCote(); diff --git a/library/Class/Exemplaire/Fields.php b/library/Class/Exemplaire/Fields.php index 13cce0f18b343844b2dbc70858dcc1dcce23efb8..735382a261ceb691010368fb3e3e91f8fbf57e31 100644 --- a/library/Class/Exemplaire/Fields.php +++ b/library/Class/Exemplaire/Fields.php @@ -74,20 +74,20 @@ class Class_Exemplaire_Fields { : ''; $writer->setNotice($unimarc); - $writer->add_field('995', ' 1', $this->_asKeyValue()); + $writer->add_field('995', ' 1', $this->asKeyValue()); return $writer->toUnimarcIso2709(); } public function toString() { $ret = ''; - foreach($this->_asKeyValue() as $key_value) + foreach($this->asKeyValue() as $key_value) $ret .= $key_value[0] . '=' . $key_value[1] . '<br>'; return $ret; } - protected function _asKeyValue() { + public function asKeyValue() : array { $subfields = []; foreach ($this->_fields as $key => $values) array_map(function($value) use (&$subfields, $key) diff --git a/library/Class/IntProfilDonnees.php b/library/Class/IntProfilDonnees.php index e7cc3dfc75d13470b8fd90088935b6cd29708331..de194ff6d3773db3abf8093c9d5245cb57ad5c03 100644 --- a/library/Class/IntProfilDonnees.php +++ b/library/Class/IntProfilDonnees.php @@ -377,6 +377,7 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { FIELD_TYPE_DOC_RECOGNITION = 'type_doc', FIELD_ITEM_ZONE = 'item_zone', + FIELD_ITEM_ZONE_DEFAULT = '995', FIELD_ITEM_TYPE_DOC = 'champ_type_doc', FIELD_ITEM_BARCODE = 'champ_code_barres', FIELD_ITEM_COTE = 'champ_cote', diff --git a/library/Class/Notice/Indexation.php b/library/Class/Notice/Indexation.php index dec9706296941a38abb02f5a8ae6bd487812ddad..dc8d6042d1d33b7091f599f8f0dee5f2b80a64cd 100644 --- a/library/Class/Notice/Indexation.php +++ b/library/Class/Notice/Indexation.php @@ -25,6 +25,7 @@ class Class_Notice_Indexation { protected Class_Notice $_record; protected Class_Indexation $_indexation; + protected string $_item_zone_cache; public function __construct(Class_Notice $record) { $this->_record = $record; @@ -54,7 +55,10 @@ class Class_Notice_Indexation { protected function _getOtherTerms() : string { - return trim($this + if ($this->_itemsDataUsage()) + $this->_addItems(); + + $html = trim($this ->_indexation->getFulltextOtherTerms($this->_record->getOtherIndexedTerms(), [$this->_record->getTitres(), $this->_record->getAuteurs(), @@ -63,6 +67,66 @@ class Class_Notice_Indexation { $this->_record->getMatieres()]) . ' ' . $this->_getIndexedThesauriTerms()); + + if ($this->_itemsDataUsage()) + $this->_cleanItems(); + + return $html; + } + + + protected function getItemZone() :string { + if (isset($this->_item_zone_cache)) + return $this->_item_zone_cache; + return $this->_item_zone_cache = $this->_getRecordItemZone(); + } + + + protected function _getRecordFirstItem() : ?Class_Exemplaire { + if (get_class($this->_record) == Class_Notice::class) + return $this->_record->getFirstExemplaire(); + return null; + } + + + protected function _getRecordItemZone() : string { + if ($item = $this->_record->getFirstExemplaire()) + return $item->getItemZone(); + return ''; + } + + + protected function _getRecordItems() : array { + return $this->_record->getExemplaires(); + } + + + protected function _addItemToRecord($item) : Class_NoticeUnimarc { + return $this->_record->addItem($item, $this->getItemZone()); + } + + + protected function _addItems() : self { + array_map(fn($item) => $this->_addItemToRecord($item), $this->_getRecordItems()); + + return $this; + } + + + protected function _itemsDataUsage() : bool { + if (!$other_index_fields = trim(Class_Cosmovar::get('other_index_fields'))) + return false; + + if (!($item_zone = $this->getItemZone())) + return false; + + return (false !== strpos($other_index_fields, $item_zone)); + } + + + protected function _cleanItems() : self { + $this->_record->deleteZone($this->getItemZone()); + return $this; } diff --git a/library/Class/NoticeUnimarc.php b/library/Class/NoticeUnimarc.php index a87a4ccce41bad92cfb503deccf9f033f338f638..7f6f93331ae29dcc856d4e3ab7a3d9d745f1a9e0 100644 --- a/library/Class/NoticeUnimarc.php +++ b/library/Class/NoticeUnimarc.php @@ -337,6 +337,37 @@ class Class_NoticeUnimarc { } + public function addZone(Class_NoticeUnimarc_Zone $zone) :self { + $field_number = $zone->getLabel(); + if (!isset($this->inner_data[$field_number])){ + $this->inner_data[$field_number] = [$zone->render()]; + return $this; + } + $this->inner_data[$field_number] []= $zone->render(); + return $this; + } + + + public function deleteZone(string $label) :self { + + if (!isset($this->inner_data[$label])){ + unset($this->inner_data[$label]); + } + return $this; + } + + + public function addItem(Class_Exemplaire $item, string $item_zone) :self{ + $subfields = (new Class_Exemplaire_Fields($item))->asKeyValue(); + $zone = (new Class_NoticeUnimarc_Zone())->label($item_zone); + foreach ($subfields as $subfield) + $zone->addChildFrom($subfield); + + $this->addZone($zone); + return $this; + } + + public function get_zone(string $label, string $content) : Class_NoticeUnimarc_Zone { $content = str_replace($this->rgx_field_end, '', $content); $instance = (new Class_NoticeUnimarc_Zone)->label($label); diff --git a/library/Class/NoticeUnimarc/Zone.php b/library/Class/NoticeUnimarc/Zone.php index 6c95c613c774acf3a800180b4814cceac395a5d1..28f829ad78e8fde36df429c3238df8cb8f8893d2 100644 --- a/library/Class/NoticeUnimarc/Zone.php +++ b/library/Class/NoticeUnimarc/Zone.php @@ -43,6 +43,11 @@ class Class_NoticeUnimarc_Zone { } + public function getLabel() : string { + return (string) $this->_label; + } + + public function content(string $content) : self { $this->_content = $content; $this->_sub_zones = new Storm_Collection; @@ -58,6 +63,12 @@ class Class_NoticeUnimarc_Zone { } + public function addChildFrom(array $subfield) : self { + if (isset($subfield[0]) && isset($subfield[1])) + return $this->addChild($subfield[0], $subfield[1]); + } + + public function addChild(string $code, string $value) : self { $this->_sub_zones ->append(new Class_NoticeUnimarc_SubZone($code, $value)); diff --git a/tests/library/Class/Notice/IndexationTest.php b/tests/library/Class/Notice/IndexationTest.php index 94e176a14aeedf625454dcc93bb29efb755c5b3c..8be78ed5fd8a8922c9866e1cbeaa551af8063443 100644 --- a/tests/library/Class/Notice/IndexationTest.php +++ b/tests/library/Class/Notice/IndexationTest.php @@ -137,3 +137,69 @@ class IndexationWithLotOfTitlesTest extends ModelTestCase { $this->assertEquals('DROIT FONDAMENTAL DROI FONDAMANTAL', Class_Notice::find(3)->getCollection()); } } + + + + +class IndexationWithOtherIndexTermsWithItemsElementsTest extends ModelTestCase { + + public function setUp() { + parent::setUp(); + Class_CosmoVar::setValueOf('other_index_fields', '200$a;200$f;995$k'); + + $this->fixture(Class_Notice::class, + ['id' => 3, + 'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/unimarc_droit_administratif.txt')]); + + $this->fixture(Class_Exemplaire::class, + ['id' => 3, + 'id_notice' => 3 + ])->setZone995(serialize([ + ['code' => 'a', + 'valeur' => 'UMEA'], + ['code' => 'c', + 'valeur' => 'qdsf'], + ['code' => 'f', + 'valeur' => '0123456789'], + ['code' => 'n', + 'valeur' => 'orderlineid'], + ['code' => 'v', + 'valeur' => 'activite'], + ['code' => 'k', + 'valeur' => '1E11 302.801']])); + + $this->fixture(Class_Exemplaire::class, + ['id' => 4, + 'id_notice' => 3 + ])->setZone995(serialize([ + ['code' => 'a', + 'valeur' => 'UMEA'], + ['code' => 'c', + 'valeur' => 'qdsf'], + ['code' => 'f', + 'valeur' => '0123456799'], + ['code' => 'n', + 'valeur' => 'orderlineid'], + ['code' => 'v', + 'valeur' => 'activite'], + ['code' => 'k', + 'valeur' => '305.801']])); + + array_map(fn($n) => (new Class_Notice_Indexation($n))->indexAndSave(), + Class_Notice::findAll()); + } + + + /** @test */ + public function otherTermsForRecordThreeShouldContainsFirstItemCallnumber() { + $this->assertContains('1E11', + Class_Notice::find(3)->getOtherTerms()); + } + + + /** @test */ + public function otherTermsForRecordThreeShouldContainsSecondItemCallnumber() { + $this->assertContains('305 801', + Class_Notice::find(3)->getOtherTerms()); + } +}