Commit fd08cb7a authored by Laurent's avatar Laurent

Merge branch…

Merge branch 'dev#109170_import_des_periodiques_koha_rendre_accessibles_articles_et_titres_de_periodiques_a_tous_les_sites' into 'master'

Dev#109170 import des periodiques koha rendre accessibles articles et titres de periodiques a tous les sites

See merge request !3572
parents ebbd5650 37970dcf
Pipeline #10636 passed with stage
in 45 minutes and 52 seconds
- 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
......@@ -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());
}
}
......
......@@ -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';
......
......@@ -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
......@@ -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,58 @@ 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();
return array_filter($this->getFacetCodes(),
function($code) use ($filtered)
{
return !in_array(substr($code, 0, 1),
$filtered);
});
}
if ($genre = trim((string)$exemplaire->getGenre()))
$facettes []= Class_CodifGenre::CODE_FACETTE.$genre;
if ($section = trim((string)$exemplaire->getSection()))
$facettes []= Class_CodifSection::CODE_FACETTE.$section;
protected function _fetchItemsToInjectInFacets() {
if ($this->isPeriodiqueArticle() && ($linked_record = $this->getLinkedSerialRecord()))
return $linked_record->getExemplaires();
if ($emplacement = trim((string)$exemplaire->getEmplacement()))
$facettes []= Class_CodifEmplacement::CODE_FACETTE.$emplacement;
if (!$this->isPeriodiqueTitle())
return $this->getExemplaires();
if ($annexe = trim((string)$exemplaire->getAnnexe()))
$facettes []= Class_CodifAnnexe::CODE_FACETTE.$annexe;
$clef_chapeau = Class_Indexation::getInstance()->codeAlphaTitre($this->getTitrePrincipal());
$records = $this->getLoader()->getAllNoticesByClefChapeau($clef_chapeau);
$record_ids = (new Storm_Model_Collection($records))->collect('id');
if ($exemplaire->isDisponible(true))
$facettes []= Class_Codification::CODE_AVAILABILITY.$exemplaire->getIdBib();
if ($record_ids->isEmpty())
return [];
$date_exemplaire = $exemplaire->getDateNouveaute();
if ($date_exemplaire > $date_nouveaute)
$date_nouveaute = $date_exemplaire;
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 +1940,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
......@@ -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)])
: '';
}
}
<?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
......@@ -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());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment