Skip to content
Snippets Groups Projects
Commit 7abea139 authored by Laurent's avatar Laurent
Browse files

hotline #28796 fix generation of unique id_thesaurus

parent b82f093b
Branches
Tags
4 merge requests!1046Master,!1045Hotline master,!1044Stable,!1043Hotline#28796 fix thesaurus integration
......@@ -64,10 +64,10 @@ class Cosmo_FacetsController extends Zend_Controller_Action {
if (!$model->getIdThesaurus()) {
$libelle = preg_replace('/[^a-zA-Z0-9]/', '', $this->_getParam('libelle_facette'));
$libelle = substr($libelle, 0, 4);
$id_thesaurus = $this->generateNewIdThesaurusForLabel($libelle);
$model->setIdThesaurus($id_thesaurus);
$model->setCode($libelle);
$model->setCode($id_thesaurus);
}
$model->save();
......@@ -76,10 +76,16 @@ class Cosmo_FacetsController extends Zend_Controller_Action {
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", strtoupper($label));
$id = sprintf("%'".$suffix."-4s", $label);
if (!Class_CodifThesaurus::findFirstBy(['id_thesaurus' => $id]))
return $id;
}
......
......@@ -189,6 +189,24 @@ class Cosmo_DynamicFacetsControllerValidateTest extends Cosmo_DynamicFacetsContr
}
/** @test */
public function withExistingIdThesaurusDOCUNewIdThesaurusShouldBeDOC0() {
$this->fixture('Class_CodifThesaurus',
['libelle' => 'doc that i love',
'id_thesaurus' => 'DOCU',
'rules' => '{"label":" 345$t "}']);
$this->postDispatch(
'/cosmo/facets/validate',
['libelle_facette' => 'docu',
'rules' => '33$2']);
$this->assertEquals('DOC0',
Class_CodifThesaurus::findFirstBy(['libelle'=>'docu'])->getIdThesaurus());
}
/** @test */
public function withSpecialCharsNewIdThesaurusShouldBeFourLetters() {
$this->postDispatch(
......
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