From 0f7ac92767ab74fa19e005cccd2ccbd2c452de3b Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 16 May 2018 19:29:08 +0200 Subject: [PATCH] Add LSattr_html :: labeledValue --- doc/conf/LSattribute/LSattr_html.docbook | 1 + .../LSattr_html/LSattr_html.entities.xml | 1 + .../LSattr_html_labeledValue.docbook | 33 +++++ .../class/class.LSattr_html_labeledValue.php | 32 +++++ .../class.LSformElement_labeledValue.php | 128 ++++++++++++++++++ public_html/lang/generate_lang_file.php | 7 + .../default/LSformElement_labeledValue.tpl | 7 + .../LSformElement_labeledValue_field.tpl | 21 +++ 8 files changed, 230 insertions(+) create mode 100644 doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook create mode 100644 public_html/includes/class/class.LSattr_html_labeledValue.php create mode 100644 public_html/includes/class/class.LSformElement_labeledValue.php create mode 100644 public_html/templates/default/LSformElement_labeledValue.tpl create mode 100644 public_html/templates/default/LSformElement_labeledValue_field.tpl diff --git a/doc/conf/LSattribute/LSattr_html.docbook b/doc/conf/LSattribute/LSattr_html.docbook index 4a9df3c0..827b0bc0 100644 --- a/doc/conf/LSattribute/LSattr_html.docbook +++ b/doc/conf/LSattribute/LSattr_html.docbook @@ -7,6 +7,7 @@ &conf-LSattr_html_date; &conf-LSattr_html_image; &conf-LSattr_html_jsonCompositeAttribute; + &conf-LSattr_html_labeledValue; &conf-LSattr_html_mail; &conf-LSattr_html_maildir; &conf-LSattr_html_mailQuota; diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml b/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml index 158a6ac7..55440ae3 100644 --- a/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml @@ -3,6 +3,7 @@ + diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook b/doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook new file mode 100644 index 00000000..bcd7ea62 --- /dev/null +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook @@ -0,0 +1,33 @@ + + LSattr_html_labeledValue + Ce type est utilisé pour la gestion des attributs dont la valeur est + prefixé d'un label et qui respecte le format suivant : + [label]valeur. + + +Structure... + array( + 'labels' => array ( // Liste des labels possible + 'label1' => 'Libellé label1', + 'label2' => 'Libellé label2', + [...] + ), +),]]> +... + + + +Paramètres de configuration + + + labels + + Tableau associatif obligatoire contenant en valeur clé, le + label utilisé dans la valeur stockée et en valeur + associée, le valeur d'affichage du label. + + + + + + diff --git a/public_html/includes/class/class.LSattr_html_labeledValue.php b/public_html/includes/class/class.LSattr_html_labeledValue.php new file mode 100644 index 00000000..a0b36e76 --- /dev/null +++ b/public_html/includes/class/class.LSattr_html_labeledValue.php @@ -0,0 +1,32 @@ + + */ +class LSattr_html_labeledValue extends LSattr_html { + + var $LSformElement_type = 'labeledValue'; + +} diff --git a/public_html/includes/class/class.LSformElement_labeledValue.php b/public_html/includes/class/class.LSformElement_labeledValue.php new file mode 100644 index 00000000..47333205 --- /dev/null +++ b/public_html/includes/class/class.LSformElement_labeledValue.php @@ -0,0 +1,128 @@ + + */ + +class LSformElement_labeledValue extends LSformElement { + + var $template = 'LSformElement_labeledValue.tpl'; + var $fieldTemplate = 'LSformElement_labeledValue_field.tpl'; + + /** + * Retourne les infos d'affichage de l'élément + * + * Cette méthode retourne les informations d'affichage de l'élement + * + * @retval array + */ + function getDisplay(){ + $return = $this -> getLabelInfos(); + + $parseValues=array(); + foreach($this -> values as $val) { + $parseValues[]=$this -> parseValue($val); + } + $return['html'] = $this -> fetchTemplate(NULL,array( + 'labels' => $this -> params['html_options']['labels'], + 'parseValues' => $parseValues, + 'unrecognizedValueTxt' => __('(unrecognized value)'), + 'unrecognizedLabelTxt' => __('(unrecognized label)'), + )); + return $return; + } + + /** + * Retourne le code HTML d'un champ vide + * + * @retval string Code HTML d'un champ vide. + */ + function getEmptyField() { + return $this -> fetchTemplate($this -> fieldTemplate,array( + 'labels' => $this -> params['html_options']['labels'], + )); + } + + + /** + * Parse une valeur + * + * @param[in] $value La valeur + * + * @retval array Un tableau cle->valeur contenant value et label + **/ + function parseValue($value) { + $ret=array('raw_value' => $value); + if (preg_match('/^\[([^\]]*)\](.*)$/',$value,$m)) { + $ret['label'] = $m[1]; + if (isset($this -> params['html_options']['labels'][$ret['label']])) + $ret['translated_label'] = $this -> params['html_options']['labels'][$ret['label']]; + $ret['value'] = $m[2]; + } + return $ret; + } + + /** + * Recupère la valeur de l'élement passée en POST + * + * Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère + * pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément + * + * @param[] array Pointeur sur le tableau qui recupèrera la valeur. + * + * @retval boolean true si la valeur est présente en POST, false sinon + */ + function getPostData(&$return) { + if($this -> isFreeze()) { + return true; + } + if (isset($_POST[$this -> name."_labels"]) && isset($_POST[$this -> name."_values"])) { + $return[$this -> name]=array(); + if(!is_array($_POST[$this -> name."_labels"])) { + $_POST[$this -> name."_labels"] = array($_POST[$this -> name."_labels"]); + } + if(!is_array($_POST[$this -> name."_values"])) { + $_POST[$this -> name."_values"] = array($_POST[$this -> name."_values"]); + } + foreach($_POST[$this -> name."_labels"] as $key => $label) { + $val=$_POST[$this -> name."_values"][$key]; + if (!empty($label) && (!empty($val)||(is_string($val)&&($val=="0")))) { + $return[$this -> name][$key] = "[$label]$val"; + } + } + return true; + } + else { + $return[$this -> name] = array(); + return true; + } + } + +} diff --git a/public_html/lang/generate_lang_file.php b/public_html/lang/generate_lang_file.php index 9c255e19..b5a1cb65 100755 --- a/public_html/lang/generate_lang_file.php +++ b/public_html/lang/generate_lang_file.php @@ -253,6 +253,13 @@ if (loadDir(LS_OBJECTS_DIR) && loadDir(LS_LOCAL_DIR.LS_OBJECTS_DIR)) { } } + // LSattr_html_labeledValue + if (is_array($attr['html_options']['labels'])) { + foreach($attr['html_options']['labels'] as $klabel => $plabel) { + add($plabel); + } + } + // LSattr_html_jsonCompositeAttribute if (is_array($attr['html_options']['components'])) { foreach($attr['html_options']['components'] as $c => $cconfig) { diff --git a/public_html/templates/default/LSformElement_labeledValue.tpl b/public_html/templates/default/LSformElement_labeledValue.tpl new file mode 100644 index 00000000..40a75c60 --- /dev/null +++ b/public_html/templates/default/LSformElement_labeledValue.tpl @@ -0,0 +1,7 @@ + diff --git a/public_html/templates/default/LSformElement_labeledValue_field.tpl b/public_html/templates/default/LSformElement_labeledValue_field.tpl new file mode 100644 index 00000000..e920c708 --- /dev/null +++ b/public_html/templates/default/LSformElement_labeledValue_field.tpl @@ -0,0 +1,21 @@ +{if $freeze} + {if isset($parseValue)} + {if $parseValue.label} + {if $parseValue.translated_label} + {$parseValue.translated_label} + {else} + {$parseValue.label} {$unrecognizedLabelTxt} + {/if} + : {$parseValue.value} + {else} + {$parseValue.raw_value} {$unrecognizedValueTxt} + {/if} + {else} + {$noValueTxt} + {/if} +{else} + + +{/if}