LSattr_html::valueWithUnit : add translate_labels, store_integer and round_down parameters

This commit is contained in:
Benjamin Renard 2018-02-19 11:18:55 +01:00
parent 3659031ed2
commit 1fe65e0d6b
2 changed files with 40 additions and 4 deletions

View file

@ -11,9 +11,12 @@
'[facteur2]' => '[label unit2]', '[facteur2]' => '[label unit2]',
[...] [...]
), ),
'translate_labels' => [booléen],
'nb_decimals' => [number of decimals], 'nb_decimals' => [number of decimals],
'dec_point' => '[decimals point]', 'dec_point' => '[decimals point]',
'thousands_sep' => '[thousands separator]' 'thousands_sep' => '[thousands separator]',
'store_integer' => [booléen],
'round_down' => [booléen],
) )
),]]> ),]]>
... ...
@ -29,6 +32,13 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>translate_labels</term>
<listitem>
<simpara>Booléen permettant d'activer/désactiver la traduction des labels (Par defaut : <literal>Vrai</literal>).</simpara>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>nb_decimals</term> <term>nb_decimals</term>
<listitem> <listitem>
@ -50,6 +60,22 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>store_integer</term>
<listitem>
<simpara>Booléen permettant d'activer/désactiver le stockage de valeurs entières (Par defaut :
<literal>Vrai</literal>).</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>round_down</term>
<listitem>
<simpara>Booléen permettant d'arrondir à l'entier inférieur (et non à l'entier supérieur
par défaut) en cas de stockage de valeurs entières.</simpara>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</sect4> </sect4>

View file

@ -44,7 +44,7 @@ class LSformElement_valueWithUnit extends LSformElement {
if (isset($this -> params['html_options']['units']) && is_array($this -> params['html_options']['units'])) { if (isset($this -> params['html_options']['units']) && is_array($this -> params['html_options']['units'])) {
$units=array(); $units=array();
foreach($this -> params['html_options']['units'] as $sill => $label) { foreach($this -> params['html_options']['units'] as $sill => $label) {
$units[$sill]=__($label); $units[$sill]=((!isset($this -> params['html_options']['translate_labels']) || $this -> params['html_options']['translate_labels'])?__($label):$label);
} }
krsort($units); krsort($units);
return $units; return $units;
@ -162,8 +162,18 @@ class LSformElement_valueWithUnit extends LSformElement {
$f = 1; $f = 1;
if (isset($_POST[$this -> name.'_unitFact'][$key]) && ($_POST[$this -> name.'_unitFact'][$key]!=1)) { if (isset($_POST[$this -> name.'_unitFact'][$key]) && ($_POST[$this -> name.'_unitFact'][$key]!=1)) {
$f = $_POST[$this -> name.'_unitFact'][$key]; $f = $_POST[$this -> name.'_unitFact'][$key];
} }
$return[$this -> name][$key] = ($val*$f); if (isset($this -> params['html_options']['store_integer']) && $this -> params['html_options']['store_integer']) {
if (isset($this -> params['html_options']['round_down']) && $this -> params['html_options']['round_down']) {
$return[$this -> name][$key] = floor($val*$f);
}
else {
$return[$this -> name][$key] = ceil($val*$f);
}
}
else {
$return[$this -> name][$key] = ($val*$f);
}
} }
} }
} }