From 569150e763d9e06982f215f2ee98bebee3661653 Mon Sep 17 00:00:00 2001 From: Damien LASSERRE Date: Wed, 25 Jan 2012 13:58:07 +0000 Subject: [PATCH] correction code naf arbo --- library/Scores/Field.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/library/Scores/Field.php b/library/Scores/Field.php index 862ffae5..7aa383a3 100644 --- a/library/Scores/Field.php +++ b/library/Scores/Field.php @@ -654,7 +654,7 @@ Class Fields if(strlen($valeur) < 5){ if($valeur[0] == 'D') { $table = new Application_Model_Codepostaux(); - $sql = $table->select()->where('Codepos LIKE "'.$valeur.'%"'); + $sql = $table->select()->where('Codepos LIKE "'.substr($valeur, 1).'%"'); $codes = $table->fetchAll($sql)->toArray(); foreach($codes as $code) { $values[] = $code['Codepos']; @@ -679,19 +679,24 @@ Class Fields protected function nafArbo($key, $valeur) { - $value = array(); - $table = new Application_Model_Naf(); + $value = array(); + $table = new Application_Model_Naf(); - $sql = $table->select()->from('naf')->where('parent = ?', $valeur); - $result = $sql->query(); - $codes = $result->fetchAll(); - foreach ($codes as $code) { - $sql = $table->select()->from('naf')->where("code LIKE '".$code['code']."%' and niveau = 5"); - $result = $sql->query(); - $elements = $result->fetchAll(); - foreach($elements as $element) { - $value[] = $element['code']; - } + if(strlen($valeur) == 1) + { + $sql = $table->select()->where('parent = ?', $valeur); + $result =$table->fetchAll($sql)->toArray(); + foreach($result as $code) $where .= " code LIKE '".$code['code']."%' and niveau = 5 or "; + $where = substr($where, 0, (strlen($where)) - 3); + $sql = $table->select()->where($where); + $result = $table->fetchAll($sql)->toArray(); + foreach($result as $code) $value[] = $code['code']; + } else if(strlen($valeur) < 5){ + $sql = $table->select()->where("code LIKE '".$valeur."%' and niveau = 5"); + $result = $table->fetchAll($sql)->toArray(); + foreach($result as $code) $value[] = $code['code']; + } else if(strlen($valeur) == 5) { + $value[] = $valeur; } return ($value); }