Commit e91c4200 authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'dev#81435_minsoc_navigation_dans_les_autorites_v75' into 'master'

dev #81435 : bibliographic / authority ling + view authority record

See merge request !2940
parents 3cf94313 79922904
Pipeline #5731 passed with stage
in 32 minutes and 53 seconds
- ticket #81435 : Catalogue : Affichage basique d'une notice autorité
\ No newline at end of file
......@@ -301,6 +301,9 @@ class RechercheController extends ZendAfi_Controller_Action {
public function viewnoticeAction() {
if ($authority_record = $this->_authorityFromParams())
return $this->_redirect('/opac/recherche/viewnotice/id/' . $authority_record->getId());
$id_notice = (int)$this->_getParam('id');
$clef_alpha = (string)$this->_getParam('clef');
......@@ -401,6 +404,29 @@ class RechercheController extends ZendAfi_Controller_Action {
}
protected function _authorityFromParams() {
if ((!$authority_id = $this->_getParam('authority_id'))
|| (!$thesaurus_id = $this->_getParam('thesaurus_id')))
return;
$items = Class_Exemplaire::findAllBy(['type' => Class_Notice::TYPE_AUTHORITY,
'id_origine' => $authority_id]);
foreach($items as $item)
if ($record = $this->_recordWithThesaurusFacet($thesaurus_id, $item))
return $record;
}
protected function _recordWithThesaurusFacet($thesaurus_id, $item) {
if (!$record = $item->getNotice())
return;
return in_array(Class_CodifThesaurus::CODE_FACETTE . $thesaurus_id, $record->getFacetCodes())
? $record
: null;
}
public function jsonRecordAction() {
$this->_helper->getHelper('viewRenderer')->setNoRender();
......
......@@ -24,4 +24,8 @@ sed -i "s/integration_pwd=root/integration_pwd=$DBPASS/g" config.php
sed -i "s/integration_base=opac3/integration_base=$DBNAME/g" config.php
cd ..
phpunit -c tests/phpunit.xml --exclude-group no-ci && phpunit -c tests/phpunit_db.xml --exclude-group no-ci && phpunit -c tests/phpunit_js.xml --exclude-group no-ci && cd cosmogramme/tests && phpunit --exclude-group no-ci && cd ../cosmozend/tests && phpunit --exclude-group no-ci
phpunit -c tests/phpunit.xml --list-suites && phpunit -c tests/phpunit.xml --exclude-group no-ci \
&& phpunit -c tests/phpunit_db.xml --list-suites && phpunit -c tests/phpunit_db.xml --exclude-group no-ci \
&& phpunit -c tests/phpunit_js.xml --list-suites && phpunit -c tests/phpunit_js.xml --exclude-group no-ci \
&& cd cosmogramme/tests && phpunit --list-suites && phpunit --exclude-group no-ci \
&& cd ../cosmozend/tests && phpunit --list-suites && phpunit --exclude-group no-ci
......@@ -20,93 +20,9 @@
*/
class Cosmo_FacetsController extends Zend_Controller_Action {
use Trait_Translator;
public function preDispatch() {
$this->cosmoPath = $this->view->cosmoPath = new CosmoPaths();
}
public function indexAction() {
$this->view->models = Class_CodifThesaurus::findAllBy(['rules not' => null,
'order' => 'libelle']);
$this->view->currentId = $this->_getParam('id');
}
public function addAction() {
$this->view->model = Class_CodifThesaurus::newInstance([
'libelle_facette' => '** nouvelle facette **',
'rules' => json_encode(['label' => $this->_getParam('rules')])]);
}
public function validateAction() {
if (!$this->_request->isPost()) {
$this->_gotoIndex();
return;
}
if (!$model = Class_CodifThesaurus::find($this->_getParam('id')))
$model = Class_CodifThesaurus::newInstance();
$model
->setLibelle($this->_getParam('libelle_facette'))
->setLibelleFacette($this->_getParam('libelle_facette'))
->setRules(json_encode(['label' => $this->_getParam('rules')]));
if (!$model->isValid()) {
$this->view->model = $model;
$this->view->errors = $model->getErrors();
$this->render('add');
return;
}
if (!$model->getIdThesaurus()) {
$libelle = preg_replace('/[^a-zA-Z0-9]/', '', $this->_getParam('libelle_facette'));
$id_thesaurus = $this->generateNewIdThesaurusForLabel($libelle);
$model->setIdThesaurus($id_thesaurus);
$model->setCode($id_thesaurus);
}
$model->save();
$this->_gotoIndex($model->getId());
}
protected function generateNewIdThesaurusForLabel($label) {
$id = substr(strtoupper($label), 0, 4);
if (strlen($id) == 4 && !Class_CodifThesaurus::findFirstBy(['id_thesaurus' => $id]))
return $id;
$label = substr(strtoupper($label), 0, 3);
$suffixes = array_merge(range(0, 9), range('a', 'z'));
while(!empty($suffixes)) {
$suffix = strtoupper(array_shift($suffixes));;
$id = sprintf("%'".$suffix."-4s", $label);
if (!Class_CodifThesaurus::findFirstBy(['id_thesaurus' => $id]))
return $id;
}
}
public function deleteAction() {
if ($model = Class_CodifThesaurus::find($this->_getParam('id')))
$model->delete();
$this->_gotoIndex();
}
protected function _gotoIndex($id=null) {
$this->_redirect($this->view->url([
'module' => 'cosmo',
'controller' => 'facets',
'action' => 'index',
'id' => $id
], null, true),
['prependBase' => false]);
}
class Cosmo_FacetsController extends ZendAfi_Controller_Action {
public function getPlugins() {
return ['ZendAfi_Controller_Plugin_ResourceDefinition_DynamicFacet',
'ZendAfi_Controller_Plugin_Manager_DynamicFacet'];
}
}
?>
<?php $model = $this->model; ?>
<h1>Codification des facettes dynamiques</h1>
<div class="liste">
<?php if ($this->errors) { ?>
<ul style="color:red;font-weight:bolder;">
<?php foreach ($this->errors as $error) { ?>
<li><?php echo $this->escape($error);?></li>
<?php } ?>
</ul>
<?php } ?>
<?php echo $this->cosmoFacets($this->model, true); ?>
</div>
<br/><br/>
<?php
echo $this->cosmoButton('Retour',
$this->url(['module' => 'cosmo', 'controller' => 'facets'],
null, true));
?>
echo $this->tag('h1', $this->titre);
echo $this->renderForm($this->form);
<?php
echo $this->tag('h1', $this->titre);
echo $this->renderForm($this->form);
<h1>Facettes dynamiques</h1>
<div class="liste">
<?php
foreach($this->models as $model) {
$img = 'plus.gif';
$display = false;
if ($model->getId() == $this->currentId) {
$img = 'moins.gif';
$display = true;
}
?>
<div class="liste_img">
<?php echo $this->tagImg($this->cosmoPath->getCosmoBaseUrl() . 'images/'.$img,
['id' => 'Ifacet' . $model->getId(),
'style' => 'cursor:pointer',
'onclick' => 'contracter_bloc(\'facet'.$model->getId().'\')']);?>
</div>
<div class="liste_titre"><?php echo $model->getLibelleFacette();?></div>
<?php echo $this->cosmoFacets($model, $display); ?>
<?php } ?>
</div>
<br/><br/>
<?php
echo $this->cosmoButton('Ajouter une facette dynamique',
$this->url(['module' => 'cosmo',
'controller' => 'facets',
'action' => 'add'], null, true));
?>
echo $this->tag('h1', $this->titre);
echo $this->Button_New((new Class_Entity())
->setText($this->_('Ajouter une facette dynamique')));
$description = (new Class_TableDescription('facets'))
->addColumn($this->_('Libellé'), 'libelle')
->addRowAction(function($batch)
{
return $this->renderPluginsActions($batch);
})
;
echo $this->renderTable($description, $this->thesauris);
......@@ -26,8 +26,9 @@ echo $this->render($this->actionScript);
$html = ob_get_contents();
ob_end_clean();
$cosmo_base_url = (new CosmoPaths())->getCosmoBaseUrl();
$cosmo_path = new CosmoPaths();
$base_url = $cosmo_path->getBaseUrl();
$cosmo_base_url = $cosmo_path->getCosmoBaseUrl();
$cosmo_image_url = $cosmo_base_url . 'images/';
$scripts = Class_ScriptLoader::newInstance()
......@@ -40,7 +41,8 @@ $scripts = Class_ScriptLoader::newInstance()
$cosmo_base_url . 'css/form.css',
$cosmo_base_url . 'css/notices.css',
$cosmo_base_url . 'css/nuage_tags.css'])
->addInlineScript('var sUrlImg = "' . $cosmo_image_url . '"')
->addInlineScript('var sUrlImg = "' . $cosmo_base_url . 'images/"')
->addInlineScript('var imagesUrl = "' . $base_url . '/public/admin/images/"')
->addScript($cosmo_base_url . 'java_script/main.js');
Class_Admin_Skin::current()->renderScriptsOn($scripts);
$script_loader = Class_ScriptLoader::getInstance();
......
......@@ -21,38 +21,38 @@
abstract class CosmoControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase {
use Storm_Test_THelpers;
use Storm_Test_THelpers;
public $bootstrap = 'bootstrap_frontcontroller.php';
public $bootstrap = 'bootstrap_frontcontroller.php';
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Storm_Model_Abstract::unsetLoaders();
Storm_Cache::setDefaultZendCache(null);
public function setUp() {
parent::setUp();
Storm_Model_Abstract::unsetLoaders();
Storm_Cache::setDefaultZendCache(null);
if ($this->_storm_default_to_volatile)
Storm_Model_Loader::defaultToVolatile();
$this->fixture('Class_Profil',
['id' => 1,
'libelle' => 'Home']);
}
}
public function tearDown() {
public function tearDown() {
if ($this->_storm_default_to_volatile)
Storm_Model_Loader::defaultToDb();
Storm_Model_Abstract::unsetLoaders();
}
Storm_Model_Abstract::unsetLoaders();
}
public function postDispatch($url, $data) {
$this->getRequest()
->setMethod('POST')
->setPost($data);
return $this->dispatch($url, true);
}
public function postDispatch($url, $data) {
$this->getRequest()
->setMethod('POST')
->setPost($data);
return $this->dispatch($url, true);
}
public function assertRedirectTo($url, $message = '') {
......@@ -66,27 +66,57 @@ abstract class CosmoControllerTestCase extends Zend_Test_PHPUnit_ControllerTestC
}
public function dispatch($url = null, $throw_exceptions = false) {
// redirector should not exit
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->setExit(false);
// json helper should not exit
$json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
$json->suppressExit = true;
$request = $this->getRequest();
if (null !== $url) {
$request->setRequestUri($url);
}
$request->setPathInfo(null);
$this->frontController
->setRequest($request)
->setResponse($this->getResponse())
->throwExceptions($throw_exceptions)
->returnResponse(false);
$this->frontController->dispatch();
}
public function dispatch($url = null, $throw_exceptions = false) {
// redirector should not exit
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->setExit(false);
// json helper should not exit
$json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
$json->suppressExit = true;
$request = $this->getRequest();
if (null !== $url) {
$request->setRequestUri($url);
}
$request->setPathInfo(null);
$this->frontController
->setRequest($request)
->setResponse($this->getResponse())
->throwExceptions($throw_exceptions)
->returnResponse(false);
$this->frontController->dispatch();
}
public function assertFlashMessengerContentContains($value, $message = '') {
$messages = $this->_getFlashMessengerNotifications();
foreach($messages as $flash_message) {
if (false!==strpos($flash_message[ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION]['message'],
$value))
return;
}
$content = print_r($messages, true);
$this->fail("Flash messenger does not contains: \n".$value."\nbut:\n".$content."\n".$message);
}
protected function _getFlashMessengerNotifications() {
$messages = $this->_getFlashMessengerMessages();
return array_filter($messages,
function($data)
{
return is_array($data)
&& isset($data[ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION]);
});
}
protected function _getFlashMessengerMessages() {
$session = new Zend_Session_Namespace('FlashMessenger');
$messages = $session->__get('default');
return $messages ? $messages : [];
}
}
?>
\ No newline at end of file
......@@ -1146,4 +1146,169 @@ class Cosmo_DataProfileControllerMultiValuesTest extends Cosmo_DataProfileContro
$this->assertXPathContentContains('//script', 'values:{"1_label":["am","bm","","em","mm","","","","","","",""],"1_zone":["BDA","BDJ","LFA","LFJ","LDA","LDJ","LCDA","LCDJ","PATIMP","PATMS","PERIP","PATINC"]}',
$this->_response->getBody());
}
}
abstract class Cosmo_DataProfileControllerAuthorityTestCase
extends Cosmo_DataProfileControllerTestCase {
public function setUp() {
parent::setUp();
$attributs = [[Class_IntProfilDonnees::PROFILE_INDEX_SYSTEMS_FIELDS
=> [['rule' => 'ISO',
'system' => 'rameau',
'default_type' => 'a',
'thesaurus' => '3']]]];
$this->fixture('Class_IntProfilDonnees',
['id' => 654,
'libelle' => 'Authorities',
'type_fichier' => Class_IntProfilDonnees::FT_AUTHORITY,
'format' => Class_IntProfilDonnees::FORMAT_UNIMARC,
'accents' => Class_IntProfilDonnees::ENCODING_UTF8,
'attributs' => serialize($attributs)]);
$this->fixture('Class_CodifThesaurus',
['id' => 5,
'libelle' => 'Mots-clés TESS',
'rule_zone' => '609',
'rule_label_field' => 'a',
'rule_id_field' => '9',
'id_thesaurus' => 'MOTS']);
}
}
class Cosmo_DataProfileControllerAuthorityEditTest
extends Cosmo_DataProfileControllerAuthorityTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('cosmo/data-profile/edit/id/654', true);
}
/** @test */
public function fieldsetIndexationShouldBePresent() {
$this->assertXPathContentContains('//fieldset//legend', 'Indexation');
}
/** @test */
public function indexSystemsMultiInputRootShouldBePresent() {
$this->assertXPath('//div[@id="multi_inputs_index_systems"]');
}
/** @test */
public function indexSystemsMultiInputShouldBeInitialized() {
$this->assertXPathContentContains('//script', '$("#multi_inputs_index_systems").multi_inputs(');
}
/** @test */
public function multiInputRuleShouldBePresent() {
$this->assertXPathContentContains('//script', '"name":"index_system_rule"');
}
/** @test */
public function ruleValueShouldBePresent() {
$this->assertXPathContentContains('//script', '"index_system_rule":["ISO"]');
}
/** @test */
public function multiInputSystemLabelShouldBePresent() {
$this->assertXPathContentContains('//script', '"name":"index_system_label"');
}
/** @test */
public function systemLabelValueShouldBePresent() {
$this->assertXPathContentContains('//script', '"index_system_label":["rameau"]');
}
/** @test */
public function multiInputDefaultTypeShouldBePresent() {
$this->assertXPathContentContains('//script', '"name":"index_system_default_type"');
}
/** @test */
public function defaultTypeValueShouldBePresent() {
$this->assertXPathContentContains('//script', '"index_system_default_type":["a"]');
}
/** @test */
public function multiInputThesaurusIdShouldBePresent() {
$this->assertXPathContentContains('//script', '"name":"index_system_thesaurus"');
}
/** @test */
public function systemThesaurusValueShouldBePresent() {
$this->assertXPathContentContains('//script', '"index_system_thesaurus":["3"]');
}
/** @test */
public function multiInputShouldContainsTESSThesaurusOption() {
$this->assertXPathContentContains('//script', '"5":"Mots-cl\\u00e9s TESS (609$9)"');
}
}
class Cosmo_DataProfileControllerAuthorityEditPostTest
extends Cosmo_DataProfileControllerAuthorityTestCase {
protected $_prefs;
public function setUp() {
parent::setUp();
$this->postDispatch('cosmo/data-profile/edit/id/654',
['libelle' => 'Authorities',
'type_fichier' => Class_IntProfilDonnees::FT_AUTHORITY,
'format' => Class_IntProfilDonnees::FORMAT_UNIMARC,
'accents' => Class_IntProfilDonnees::ENCODING_UTF8,
'index_system_rule' => ['AFNOR'],
'index_system_label' => ['TESS'],
'index_system_default_type' => ['j'],
'index_system_thesaurus' => ['5']]);
Class_IntProfilDonnees::clearCache();
$this->_prefs = Class_IntProfilDonnees::find(654)->getIndexSystemsPrefs()[0];
}
/** @test */
public function ruleShouldBeAFNOR() {
$this->assertEquals('AFNOR', $this->_prefs['rule']);
}
/** @test */
public function systemShouldBeTESS() {
$this->assertEquals('TESS', $this->_prefs['system']);
}
/** @test */
public function defaultTypeShouldBeJ() {
$this->assertEquals('j', $this->_prefs['default_type']);
}
/** @test */
public function thesaurusShouldBe5() {
$this->assertEquals('5', $this->_prefs['thesaurus']);
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
stopOnError="false"
>
<testsuites>
<testsuite name="ApplicationTestSuite">
<testsuite name="Cosmozend">
<directory>./</directory>
</testsuite>
</testsuites>
......
......@@ -112,7 +112,7 @@ class notice_integration {
switch($this->format) {
case Class_IntProfilDonnees::FORMAT_UNIMARC:
case Class_IntProfilDonnees::FORMAT_UNIMARC_XML:
$this->analyseur = new notice_unimarc();
$this->analyseur = new notice_unimarc($id_bib);
break;
case Class_IntProfilDonnees::FORMAT_CG68_ARCHIVES:
......@@ -510,7 +510,7 @@ class notice_integration {
'other_terms'=> $this->indexation->getfulltext($this->notice['other_terms']),
'editeur' => $this->indexation->getfullText($this->notice['editeur']),
'collection' => $this->indexation->getfullText($this->notice['collection']),
'matieres' => $this->indexation->getfullText($this->_getFulltextTopics()),
'matieres' => $this->indexation->getfullText($this->_getFulltextSubjects()),
'dewey' => $this->indexation->getfullText($this->notice['full_dewey']),
'facettes' => $this->notice['facettes'],
'isbn' => $this->notice['isbn'],
......@@ -551,21 +551,21 @@ class notice_integration {
}
protected function _getFulltextTopics() {
protected function _getFulltextSubjects() {
if (!$this->notice['matieres'])
return ;
return array_merge($this->notice["matieres"],
$this->notice["matieres_renvois"],
$this->_getCodifTopicsRenvois());
$this->_getCodifSubjectsRenvois());
}
protected function _getCodifTopicsRenvois() {
protected function _getCodifSubjectsRenvois() {
$see_also = [];
foreach($this->notice['matieres'] as $topic) {
if (($codif = $this->_getCodifTopic($topic))
foreach($this->notice['matieres'] as $subject) {
if (($codif = $this->_getCodifSubject($subject))
&& $codif->hasMotsRenvois())
$see_also[] = $codif->getMotsRenvois();
}
......@@ -856,7 +856,7 @@ class notice_integration {
// Matieres
if($this->notice["matieres"]) {
foreach($this->notice["matieres"] as $matiere) {
if (!$codif_matiere = $this->_getCodifTopic($matiere)) continue;
if (!$codif_matiere = $this->_getCodifSubject($matiere)) continue;
$facettes[]="M".$codif_matiere->getId();
}
}
......@@ -921,8 +921,8 @@ class notice_integration {
}
protected function _getCodifTopic($topic) {
return $this->getCodifProvider()->getTopic($topic);
protected function _getCodifSubject($subject) {
return $this->getCodifProvider()->getSubject($subject);
}
......
......@@ -37,21 +37,23 @@ class notice_unimarc extends iso2709_record {
'949', // Libermedia
];
private $id_profil; // Id du profil de données pour le fichier chargé
private $profil_unimarc; // Instance du profil unimarc pour optimiser
private $type_doc_force; // Type de document forcé dans maj_auto
private $indexation; // Instance de la classe d'indexation
protected $profil; // Structure des valeurs du profil en cours
private $copyright; // Mots clefs pour les notices non libres de droits (801$b)
private $sigb; // Pour traitements specifiques
private $champs_forces; // Liste des champs forcés
private $ean345; // Reconnaissance des ean par la zone 345$b
private $regles_sections_genres; // Règles de reconnaissance des sections et des genres
private $id_genre_documentaire; // Identifiant pour le genre "documentaire"
private $controle_codes_barres; // Exception de filtrage des codes-barres
public function __construct() {
private $id_profil; // Id du profil de données pour le fichier chargé
private $profil_unimarc; // Instance du profil unimarc pour optimiser
private $type_doc_force; // Type de document forcé dans maj_auto