From 38a88ee456c96f42bd0560e7f5a870d489c5659b Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@git-test.afi-sa.fr> Date: Tue, 23 Apr 2013 13:43:10 +0000 Subject: [PATCH] Lecture du Thesaurus sur 4 chiffres --- .gitattributes | 1 + library/Class/CodifThesaurus.php | 16 +++++++--- tests/library/Class/CodifThesaurusTest.php | 37 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/library/Class/CodifThesaurusTest.php diff --git a/.gitattributes b/.gitattributes index 9a712a01308..711a287d53e 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 5d030eecae6..6fef879cbc2 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 00000000000..8865b023559 --- /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')); + + } + +} + -- GitLab