Skip to content
Snippets Groups Projects
Commit 6f4f3e4a authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #128944 : add thesaurus facet to authority at import time

parent 7759c8c5
Branches
Tags
2 merge requests!3882Hotline,!3879hotline #128944 : add thesaurus facet to authority at import time
Pipeline #12601 passed with stage
in 50 minutes and 12 seconds
- ticket #128944 : Fichiers autorités : ajout de la liaison de l'autorité à sa facette dynamique dès l'import
\ No newline at end of file
......@@ -24,7 +24,10 @@ class Class_Cosmogramme_Integration_Record_AuthorityFacets {
protected
$_reader,
$_create_related_callback,
$_index_systems;
$_index_systems,
$_rule,
$_system,
$_id;
public function getFacets($reader, $create_related_callback, $index_systems) {
......@@ -32,6 +35,15 @@ class Class_Cosmogramme_Integration_Record_AuthorityFacets {
$this->_create_related_callback = $create_related_callback;
$this->_index_systems = $index_systems;
if ($rules = $this->_reader->get_subfield('152', 'a'))
$this->_rule = $rules[0];
if ($systems = $this->_reader->get_subfield('152', 'b'))
$this->_system = $systems[0];
if ($ids = $this->_reader->get_subfield('001'))
$this->_id = $ids[0];
return array_merge($this->_facetsFromFields(),
$this->_facetsFromIndexSystems());
}
......@@ -76,23 +88,25 @@ class Class_Cosmogramme_Integration_Record_AuthorityFacets {
protected function _facetsFromIndexSystems() {
$rule = ($rules = $this->_reader->get_subfield('152', 'a')) ? reset($rules) : null;
$system = ($systems = $this->_reader->get_subfield('152', 'b')) ? reset($systems) : null;
if (!$rule && !$system)
if (!$this->_rule && !$this->_system)
return [];
$facets = [];
foreach ($this->_index_systems as $index_system)
$facets[] = $this->_facetsFromIndexSystem($index_system, $rule, $system);
$facets = $this->_injectFacetsFromIndexSystem($index_system, $facets);
return array_filter($facets);
}
protected function _facetsFromIndexSystem($index_system, $rule, $system) {
return ($facet = $index_system->facetFor($rule, $system))
? $facet
: null;
protected function _injectFacetsFromIndexSystem($index_system, $facets) {
if ($facet = $index_system->facetFor($this->_rule, $this->_system))
$facets[] = $facet;
if ($this->_id
&& ($facet = $index_system->facetForId($this->_rule, $this->_system, $this->_id)))
$facets[] = $facet;
return $facets;
}
}
......@@ -33,7 +33,7 @@ class Class_Notice_AuthorityIndexSystem {
$_rule,
$_system,
$_default_type,
$_thesaurus;
$_thesaurus_id;
public static function collectionFromPrefs($prefs) {
return new Class_Notice_AuthorityIndexSystemCollection(array_map(['Class_Notice_AuthorityIndexSystem', 'newFromPref'],
......@@ -53,29 +53,38 @@ class Class_Notice_AuthorityIndexSystem {
$this->_rule = $rule;
$this->_system = $system;
$this->_default_type = $default_type;
$this->_thesaurus = $thesaurus;
$this->_thesaurus_id = $thesaurus;
}
public function facetFor($rule, $system) {
if (!$this->_thesaurus)
return;
return ($model = $this->_getThesaurus($rule, $system))
? $model->getFacetCode()
: null;
}
if (trim($rule) != trim($this->_rule))
return;
if (trim($system) != trim($this->_system))
public function facetForId($rule, $system, $id) {
if (!$id || !($root = $this->_getThesaurus($rule, $system)))
return;
return ($model = Class_CodifThesaurus::find($this->_thesaurus))
? $model->getFacetCode()
return ($child = $root->getChild($id))
? $child->getFacetCode()
: null;
}
protected function _getThesaurus($rule, $system) {
if ($this->_thesaurus_id
&& (trim($rule) === trim($this->_rule))
&& (trim($system) === trim($this->_system)))
return Class_CodifThesaurus::find($this->_thesaurus_id);
}
public function isLinkedToThesaurus($thesaurus) {
return $this->_thesaurus && $thesaurus
&& $this->_thesaurus == $thesaurus->getId();
return $this->_thesaurus_id && $thesaurus
&& $this->_thesaurus_id == $thesaurus->getId();
}
......@@ -126,7 +135,7 @@ class Class_Notice_AuthorityIndexSystem {
return [static::FIELD_RULE => $this->_rule,
static::FIELD_SYSTEM => $this->_system,
static::FIELD_DEFAULT_TYPE => $this->_default_type,
static::FIELD_THESAURUS => $this->_thesaurus];
static::FIELD_THESAURUS => $this->_thesaurus_id];
}
}
......
......@@ -756,3 +756,127 @@ class AuthoritiesBibliographicDynamicFacetsWithIndexSystemAlreadyExistingTest ex
->getNotice()->getFacetCodes());
}
}
abstract class AuthoritiesFacetsWithIndexSystemTestCase extends ModelTestCase {
protected $_facets;
public function setUp() {
parent::setUp();
$attributs = [[Class_IntProfilDonnees::PROFILE_INDEX_SYSTEMS_FIELDS
=> [['rule' => '',
'system' => 'TESS',
'default_type' => 'j',
'thesaurus' => '6']]]];
$profil = $this->fixture('Class_IntProfilDonnees',
['id' => 1004,
'libelle' => 'Authorities',
'type_fichier' => Class_IntProfilDonnees::FT_AUTHORITY,
'format' => Class_IntProfilDonnees::FORMAT_UNIMARC,
'accents' => Class_IntProfilDonnees::ENCODING_UTF8,
'attributs' => serialize($attributs),
]);
$marc = (new Class_NoticeUnimarc_Writer)
->setNotice(file_get_contents(__DIR__ . '/developpement_local.mrc'),
Class_IntProfilDonnees::ENCODING_UTF8);
$prefs = $profil->getIndexSystemsPrefs();
$index_systems = Class_Notice_AuthorityIndexSystem::collectionFromPrefs($prefs);
$this->_fixtures();
$this->_facets = (new Class_Cosmogramme_Integration_Record_AuthorityFacets)
->getFacets($marc, function() {}, $index_systems);
}
protected function _fixtures() {
$this->fixture('Class_CodifThesaurus',
['id' => 6,
'libelle' => 'Mots-clés TESS',
'id_thesaurus' => 'MOTS',
'id_origine' => null,
'code' => 'MOTS',
'rule_zone' => '619',
'rule_label_field' => 'a',
'rule_id_field' => '9']);
}
protected function assertFacet($facet) {
$this->assertContains($facet, $this->_facets,
json_encode($this->_facets, JSON_PRETTY_PRINT));
}
protected function assertNotFacet($facet) {
$this->assertNotContains($facet, $this->_facets,
json_encode($this->_facets, JSON_PRETTY_PRINT));
}
}
class AuthoritiesFacetsWithIndexSystemAlreadyExistingTest
extends AuthoritiesFacetsWithIndexSystemTestCase {
protected function _fixtures() {
parent::_fixtures();
$this->fixture('Class_CodifThesaurus',
['id' => 7,
'libelle' => 'Développement local',
'id_thesaurus' => 'MOTS0001',
'id_origine' => '185611',
'code' => 'MOTS']);
}
/** @test */
public function facetsShouldContainsRootThesaurusHMOTS() {
$this->assertFacet('HMOTS');
}
/** @test */
public function facetsShouldContainsExistingMatchingThesaurusHMOTS0001() {
$this->assertFacet('HMOTS0001');
}
}
class AuthoritiesFacetsWithIndexSystemThesaurusNotExistingTest
extends AuthoritiesFacetsWithIndexSystemTestCase {
protected $_thesaurus_loader;
protected function _fixtures() {
parent::_fixtures();
$this->_thesaurus_loader = $this->onLoaderOfModel('Class_CodifThesaurus');
}
/** @test */
public function facetsShouldContainsRootThesaurusHMOTS() {
$this->assertFacet('HMOTS');
}
/** @test */
public function facetsShouldNotContainsMatchingThesaurusHMOTS0001() {
$this->assertNotFacet('HMOTS0001');
}
/** @test */
public function newThesaurusShouldNotBeCreated() {
$this->assertFalse($this->_thesaurus_loader->methodHasBeenCalled('save'));
}
}
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