diff --git a/VERSIONS_WIP/109170 b/VERSIONS_WIP/109170 new file mode 100644 index 0000000000000000000000000000000000000000..50336c994a0146ce346b7835cc626557ef9da4b1 --- /dev/null +++ b/VERSIONS_WIP/109170 @@ -0,0 +1 @@ + - ticket #109170 : Import des périodiques Koha : les facettes des articles et des titres reprennent celles des exemplaires du fascicule (Annexe, section, emplacement, ...) \ No newline at end of file diff --git a/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php b/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php index a3c126b404d9688f6b43ca8232ba409bd32ff18a..0286ff14bcf5e7ce0c3019d8fd7a134712e31827 100644 --- a/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php +++ b/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php @@ -456,6 +456,7 @@ class KohaPeriodiquesMatriculeAngesTest extends KohaPeriodiquesWithArticlesTestC $this->fixture('Class_CodifAnnexe', ['id' => 3, 'id_origine' => 'CHY-JR', + 'id_bib' => 1, 'code' => 'CHYJR', 'libelle' => 'Bibliothèque Jean-Jacques Rousseau']); @@ -608,8 +609,8 @@ class KohaPeriodiquesMatriculeAngesTest extends KohaPeriodiquesWithArticlesTestC public function titleRecordMatriculeFacettesShouldContainsTper_title() { $this->assertContains('Tper_title', Class_Notice::findFirstBy(['order' => 'id desc', - 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE]) - ->getFacettes()); + 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE]) + ->getFacettes()); } @@ -630,6 +631,31 @@ class KohaPeriodiquesMatriculeAngesTest extends KohaPeriodiquesWithArticlesTestC $this->assertContains('YCHYJR', $record->getFacettes(), 'at position: ' . $index . ', title: ' . $record->getTitrePrincipal()); } + + + /** @test */ + public function allMatriculeAngesArticlesFacettesShouldContainsYCHYJR() { + $records = Class_Notice::findAllBy(['type_doc' => Class_TypeDoc::PERIODIQUE_ARTICLE, + 'clef_chapeau' => 'MATRICULE DES ANGES LE 202']); + foreach($records as $index => $record) { + $record->updateFacetsFromExemplaires(); + $this->assertContains('YCHYJR', $record->getFacettes(), + 'at position: ' . $index . ', title: ' . $record->getTitrePrincipal()); + } + } + + + /** @test */ + public function titleRecordMatriculeFacettesShouldContainsYCHYJR() { + $title = Class_Notice::findFirstBy(['order' => 'id desc', + 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE]); + + $title->updateFacetsFromExemplaires(); + + $this->assertEquals('D800 Lfre Tper_title B1 YCHYJR', + $title->getFacettes()); + } + } diff --git a/library/Class/Codification.php b/library/Class/Codification.php index 70b8cdf0b03e56ca93754d8d3e44485fb2445283..0879217f8239e074ff16e62261ee689070d14585 100644 --- a/library/Class/Codification.php +++ b/library/Class/Codification.php @@ -51,6 +51,7 @@ * 5: données autorités * 8: urlg * 9: nouveauté + * 2: date de nouveauté */ class Class_Codification { use Trait_Singleton, Trait_Translator; @@ -69,6 +70,7 @@ class Class_Codification { CODE_AUTHORITY_DATAS='5', CODE_URL = '8', CODE_NOUVEAUTE = '9', + CODE_DATE_NOUVEAUTE = '2', CODE_INDEX_DEWEY_PCDM4 = 'X', CODE_THUMBNAIL = 'U'; diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php index f2b6e49e309e2545a15c1cd469249a6c77808d9d..9a32e52779dd39bf274024fc4014973b35d4bd98 100644 --- a/library/Class/Exemplaire.php +++ b/library/Class/Exemplaire.php @@ -553,4 +553,35 @@ class Class_Exemplaire extends Storm_Model_Abstract { return $this->isLoanable() && (!$record->isDilicom()); } + + + public function getFacets() { + $facets = [Class_Bib::CODE_FACETTE . $this->getIdBib()]; + + if ($genre = trim((string)$this->getGenre())) + $facets []= Class_CodifGenre::CODE_FACETTE.$genre; + + if ($section = trim((string)$this->getSection())) + $facets []= Class_CodifSection::CODE_FACETTE.$section; + + if ($emplacement = trim((string)$this->getEmplacement())) + $facets []= Class_CodifEmplacement::CODE_FACETTE.$emplacement; + + if ($annexe = trim((string)$this->getAnnexe())) + $facets []= Class_CodifAnnexe::CODE_FACETTE.$annexe; + + if ($this->isDisponible(true)) + $facets []= Class_Codification::CODE_AVAILABILITY.$this->getIdBib(); + + if (!$this->isNouveaute()) + return $facets; + + if ($novelty = Class_CodifThesaurus::findForItemLibraryNovelty($this)) + $facets[] = $novelty; + + if ($novelty = Class_CodifThesaurus::findForItemAnnexeNovelty($this)) + $facets[] = $novelty; + + return $facets; + } } \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index d4cc5d61bf78060fc69c30a84b24e1ed60fff369..0a0f2a2df2345d7d51935ec1e8d202699243f813 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -682,26 +682,6 @@ class Class_Notice extends Storm_Model_Abstract { } -// ---------------------------------------------------------------- -// Champ 200$b -// ---------------------------------------------------------------- - public function get200b() - { - $data = $this->get_subfield("200", "b"); - return $this->filtreTitre($data[0]); - } - -// ---------------------------------------------------------------- -// Renvoie la clef chapeau et le no de partie -// ---------------------------------------------------------------- - public function getDataSerie($id_notice) { - $data = fetchEnreg("select clef_chapeau,tome_alpha from notices where id_notice=$id_notice"); - return $data; - } - -// ---------------------------------------------------------------- -// Renvoie les articles d'un périodique -// ---------------------------------------------------------------- public function getArticlesPeriodique() { // lire dans la base $datas = Class_Notice_SerialArticles::findAllBy(['clef_chapeau' => $this->getClefChapeau(), @@ -1793,7 +1773,6 @@ class Class_Notice extends Storm_Model_Abstract { public function getAuteurWith($codif_auteur_forme) { - if(!$auteurs = $this->getAuteursUnimarc()) return ''; @@ -1811,69 +1790,54 @@ class Class_Notice extends Storm_Model_Abstract { } - public function updateFacetsFromExemplaires() { - $facettes = []; + + public function getFacetCodesWithoutItemFacets() { $filtered = [Class_Bib::CODE_FACETTE, Class_CodifEmplacement::CODE_FACETTE, Class_CodifSection::CODE_FACETTE, Class_CodifAnnexe::CODE_FACETTE, Class_CodifTypeDoc::CODE_FACETTE, - '2', + Class_Codification::CODE_DATE_NOUVEAUTE, Class_Codification::CODE_AVAILABILITY]; - foreach (array_filter(explode(' ', $this->getFacettes())) as $f) { - $type = substr($f, 0, 1); - if (in_array($type, $filtered)) - continue; - $facettes []= $f; - } - - $facettes []= Class_CodifTypeDoc::CODE_FACETTE. $this->getTypeDoc(); - - $date_nouveaute = ""; - $exemplaires = $this->getExemplaires(); - - foreach($exemplaires as $exemplaire) { - $facettes []= Class_Bib::CODE_FACETTE.$exemplaire->getIdBib(); - - if ($genre = trim((string)$exemplaire->getGenre())) - $facettes []= Class_CodifGenre::CODE_FACETTE.$genre; - - if ($section = trim((string)$exemplaire->getSection())) - $facettes []= Class_CodifSection::CODE_FACETTE.$section; + return array_filter($this->getFacetCodes(), + function($code) use ($filtered) + { + return !in_array(substr($code, 0, 1), + $filtered); + }); + } - if ($emplacement = trim((string)$exemplaire->getEmplacement())) - $facettes []= Class_CodifEmplacement::CODE_FACETTE.$emplacement; - if ($annexe = trim((string)$exemplaire->getAnnexe())) - $facettes []= Class_CodifAnnexe::CODE_FACETTE.$annexe; + protected function _fetchItemsToInjectInFacets() { + if ($this->isPeriodiqueArticle() && ($linked_record = $this->getLinkedSerialRecord())) + return $linked_record->getExemplaires(); - if ($exemplaire->isDisponible(true)) - $facettes []= Class_Codification::CODE_AVAILABILITY.$exemplaire->getIdBib(); + if (!$this->isPeriodiqueTitle()) + return $this->getExemplaires(); - $date_exemplaire = $exemplaire->getDateNouveaute(); - if ($date_exemplaire > $date_nouveaute) - $date_nouveaute = $date_exemplaire; + $clef_chapeau = Class_Indexation::getInstance()->codeAlphaTitre($this->getTitrePrincipal()); + $records = $this->getLoader()->getAllNoticesByClefChapeau($clef_chapeau); + $record_ids = (new Storm_Model_Collection($records))->collect('id'); + return Class_Exemplaire::findAllBy(['id_notice' => $record_ids->getArrayCopy()]); + } - if($exemplaire->isNouveaute()) { - if ($novelty = Class_CodifThesaurus::findForItemLibraryNovelty($exemplaire)) - $facettes[] = $novelty; - if ($novelty = Class_CodifThesaurus::findForItemAnnexeNovelty($exemplaire)) - $facettes[] = $novelty; - } - } + public function updateFacetsFromExemplaires() { + $facettes = $this->getFacetCodesWithoutItemFacets(); + $facettes []= Class_CodifTypeDoc::CODE_FACETTE. $this->getTypeDoc(); - if ($date_nouveaute) { - if (substr($date_exemplaire, 0, 1) == "2") - $facettes []= substr($date_nouveaute, 0, 7); - $date_nouveaute.=" 00:00:00"; + $date_nouveaute = ''; + foreach($this->_fetchItemsToInjectInFacets() as $exemplaire) { + $facettes = array_merge($facettes, $exemplaire->getFacets()); + $date_nouveaute = ($exemplaire->getDateNouveaute() > $date_nouveaute) + ? $exemplaire->getDateNouveaute() + : $date_nouveaute; } - else $date_nouveaute=null; return $this - ->setFacettes(implode(' ', array_unique($facettes))) - ->setDateCreation($date_nouveaute); + ->setFacettes(array_unique($facettes)) + ->setDateCreation($date_nouveaute ? ($date_nouveaute . ' 00:00:00') : null); } @@ -1972,4 +1936,17 @@ class Class_Notice extends Storm_Model_Abstract { ? $item->getLinkedSerialRecord() : null; } + + + public function getSerialTitleParentRecord() { + if (!$this->isPeriodique()) + return null; + + $clef_oeuvre_parent = explode('-', $this->getClefOeuvre()); + array_pop($clef_oeuvre_parent); + $clef_oeuvre_parent[] = ''; + + return $this->getLoader()->findFirstBy(['clef_oeuvre' => implode('-', $clef_oeuvre_parent), + 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE]); + } } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Notice/ArticlesPeriodiques.php b/library/ZendAfi/View/Helper/Notice/ArticlesPeriodiques.php index 9f6fd200961ae4865010ccd203c046d13243b472..45e502c37aead9055ff721859e83c44bdbd1d2d8 100644 --- a/library/ZendAfi/View/Helper/Notice/ArticlesPeriodiques.php +++ b/library/ZendAfi/View/Helper/Notice/ArticlesPeriodiques.php @@ -41,17 +41,11 @@ class ZendAfi_View_Helper_Notice_ArticlesPeriodiques extends ZendAfi_View_Helper } - protected function _renderLinkToParent($notice) { - $clef_oeuvre_parent = explode('-', $notice->getClefOeuvre()); - array_pop($clef_oeuvre_parent); - $clef_oeuvre_parent[] = ''; - - if ($parent = Class_Notice::findFirstBy(['clef_oeuvre' => implode('-', $clef_oeuvre_parent), - 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE])) - return $this->_tag('a', - $this->view->_('Voir la revue %s', $parent->getRecordTitle()), - ['href' => $this->view->urlNotice($parent)]); - - return ''; + protected function _renderLinkToParent($record) { + return ($parent = $record->getSerialTitleParentRecord()) + ? $this->_tag('a', + $this->_('Voir la revue %s', $parent->getRecordTitle()), + ['href' => $this->view->urlNotice($parent)]) + : ''; } } diff --git a/scripts/update_serial_items_facets.php b/scripts/update_serial_items_facets.php new file mode 100644 index 0000000000000000000000000000000000000000..44a9b1662d567c3d50522caae2bd27c6b54e2216 --- /dev/null +++ b/scripts/update_serial_items_facets.php @@ -0,0 +1,17 @@ +<?php +require('console.php'); + +$page = 1; +while ($records = Class_Notice::findAllBy(['type_doc' => [ Class_TypeDoc::PERIODIQUE_TITLE, Class_TypeDoc::PERIODIQUE_ARTICLE ], + 'limitPage' => [$page, 100]])) { + echo "\n"; + foreach($records as $record) { + echo '.'; + $record->updateFacetsFromExemplaires()->save(); + } + $page ++; +} + +echo "\n\nDONE\n\n"; + +?> \ No newline at end of file diff --git a/tests/library/Class/NoticeTest.php b/tests/library/Class/NoticeTest.php index 3f6b16f41a667928f63606149a509825822d1693..534146a253cdb4293d92f16be8421064a6db67f5 100644 --- a/tests/library/Class/NoticeTest.php +++ b/tests/library/Class/NoticeTest.php @@ -968,7 +968,7 @@ class NoticeUpdateFacetsFromItemsTest extends ModelTestCase { /** @test */ public function recordFacetsShouldContainsNoveltyForRoubaixAndNoveltyForLille() { - $this->assertEquals('T0 B10 YROUB HNNNN0001 HNANA0001 B11 HNNNN0002 2016-05', Class_Notice::find(5)->getFacettes()); + $this->assertEquals('T0 B10 YROUB HNNNN0001 HNANA0001 B11 HNNNN0002', Class_Notice::find(5)->getFacettes()); } }