diff --git a/.gitattributes b/.gitattributes index 9a712a01308ec9138850406e41bff3dfbb6beba0..711a287d53e5e851a0e8c2bc1f670fff72d0aa02 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5094,6 +5094,7 @@ tests/library/Class/BatchTest.php -text tests/library/Class/BibTest.php -text tests/library/Class/CatalogueTest.php -text tests/library/Class/CmsUrlTransformerTest.php -text +tests/library/Class/CodifThesaurusTest.php -text tests/library/Class/CommSigbTest.php -text tests/library/Class/CompositeBuilderTest.php -text tests/library/Class/CompositeBuilderTreeTest.php -text diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index 5d030eecae6b95099fe339c37777be793744724f..6fef879cbc2dc945b0dedfcae92f2c3b50c2cdcd 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -34,15 +34,23 @@ class Class_CodifThesaurusLoader extends Storm_Model_Loader { } + public function getCodeSur4Chiffres($code) { + $length=strlen($code); + while (strlen($code) %4 != 0) + $code .='0'; + return $code; + } + + public function getIndices($pere) { if ($pere == "root") - return $this->findAllBy(['where' => 'code not like "catalogue" and LENGTH(id_thesaurus) in (1,2)', 'order' => 'id_thesaurus']); + return $this->findAllBy(['where' => 'code not like "catalogue" and LENGTH(id_thesaurus) in (1,4)', 'order' => 'id_thesaurus']); + + $pere = $this->getCodeSur4Chiffres($pere); $length=strlen($pere); - if ($length % 2 == 1) - $length++; - return $this->findAllBy(['where' => 'id_thesaurus like "'.$pere.'%" and LENGTH(id_thesaurus) in ('.($length+1).','.($length+2).')','order'=> 'id_thesaurus']); + return $this->findAllBy(['where' => 'id_thesaurus like "'.$pere.'%" and LENGTH(id_thesaurus) in ('.($length+1).','.($length+4).')','order'=> 'id_thesaurus']); } diff --git a/tests/library/Class/CodifThesaurusTest.php b/tests/library/Class/CodifThesaurusTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8865b0235596698c0289d9094679d8aa7a855308 --- /dev/null +++ b/tests/library/Class/CodifThesaurusTest.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class CodifThesaurusTest extends AbstractControllerTestCase { + /** @test */ + public function code01Sur4ChiffresShouldReturn0100() { + $this->assertEquals('0100',Class_CodifThesaurus::getCodeSur4Chiffres('01')); + + } + + + /** @test */ + public function codeASur4ChiffresShouldReturn0100() { + $this->assertEquals('A000',Class_CodifThesaurus::getCodeSur4Chiffres('A')); + + } + +} +