From eef5b0361c9e0fb85dbd14694ec17d00446435e4 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Thu, 7 Dec 2006 15:20:21 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20deux=20fonction=20pour=20g=E9rer=20la?= =?UTF-8?q?=20masse=20des=20produits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/functions.inc.php | 55 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index d353a52e0f9..f6759008846 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -2188,8 +2188,6 @@ function numero_semaine($time) return sprintf("%02d",$numeroSemaine); } - - /** * \brief Retourne le picto champ obligatoire * \return string Chaine avec picto obligatoire @@ -2198,5 +2196,58 @@ function picto_required() { return '*'; } +/** + * \brief Convertit une masse d'une unite vers une autre unite + * \param weight float Masse a convertir + * \param from_unit int Unite originale en puissance de 10 + * \param to_unit int Nouvelle unite en puissance de 10 + * \return float Masse convertie + */ +function weight_convert($weight,&$from_unit,$to_unit) +{ + /* Pour convertire 320 gr en Kg appeler + * $f = -3 + * weigh_convert(320, $f, 0) retournera 0.32 + * + */ + while ($from_unit <> $to_unit) + { + if ($from_unit > $to_unit) + { + $weight = $weight * 10; + $from_unit = $from_unit - 1; + $weight = weight_convert($weight,$from_unit, $to_unit); + } + if ($from_unit < $to_unit) + { + $weight = $weight / 10; + $from_unit = $from_unit + 1; + $weight = weight_convert($weight,$from_unit, $to_unit); + } + } + return $weight; +} +/** + * \brief Renvoi le texte d'une unite + * \param int Unit + * \return string Unite + * \todo gerer les autres unités de mesure comme la livre, le gallon, le litre, ... + */ +function weight_units_string($unit) +{ + /* Note Rodo aux dev :) + * Ne pas insérer dans la base de données ces valeurs + * cela surchagerait inutilement d'une requete supplémentaire + * pour quelque chose qui est somme toute peu variable + */ + + $weight_string[3] = 'Tonnes'; + $weight_string[0] = 'kg'; + $weight_string[-3] = 'g'; + $weight_string[-6] = 'mg'; + + + return $weight_string[$unit]; +} ?>