From 1c523abbd838cbd454f83e8015e8a2d49364e716 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Sat, 12 Sep 2020 08:51:58 +0200 Subject: [PATCH 1/3] Fix: getLabelOfUnit() for Product, CommonObjectline to print long label Also add $type = 'code' for return unit code in form 'unitXX' (where XX is the code of unit). for get return like unitXX where XX is the code of unit --- htdocs/core/class/commonobjectline.class.php | 17 ++++++++--------- htdocs/product/class/product.class.php | 12 ++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 4874dded08d..5d03c91ca4b 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -54,7 +54,7 @@ abstract class CommonObjectLine extends CommonObject * Returns the translation key from units dictionary. * A langs->trans() must be called on result to get translated value. * - * @param string $type Label type (long or short). This can be a translation key. + * @param string $type Label type (long, short or code). This can be a translation key. * @return string|int <0 if ko, label if ok */ public function getLabelOfUnit($type = 'long') @@ -69,17 +69,16 @@ abstract class CommonObjectLine extends CommonObject $label_type = 'label'; - if ($type == 'short') - { - $label_type = 'short_label'; - } + $label_type = 'label'; + if ($type == 'short') $label_type = 'short_label'; + elseif ($type == 'code') $label_type = 'code'; - $sql = 'select '.$label_type.',code from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit; + $sql = 'select '.$label_type.', code from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit; $resql = $this->db->query($sql); - if ($resql && $this->db->num_rows($resql) > 0) - { + if ($resql && $this->db->num_rows($resql) > 0) { $res = $this->db->fetch_array($resql); - $label = ($label_type == 'short' ? $res[$label_type] : 'unit'.$res['code']); + if ($label_type == 'code') $label = 'unit'.$res['code']; + else $label = $res[$label_type]; $this->db->free($resql); return $label; } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index d1f36ca055d..b5f278bcf61 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5368,8 +5368,9 @@ class Product extends CommonObject /** * Returns the text label from units dictionary + * A langs->trans() must be called on result to get translated value. * - * @param string $type Label type (long or short) + * @param string $type Label type (long, short or code) * @return string|int <0 if ko, label if ok */ public function getLabelOfUnit($type = 'long') @@ -5383,16 +5384,15 @@ class Product extends CommonObject $langs->load('products'); $label_type = 'label'; - - if ($type == 'short') { - $label_type = 'short_label'; - } + if ($type == 'short') $label_type = 'short_label'; + elseif ($type == 'code') $label_type = 'code'; $sql = 'select '.$label_type.', code from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { $res = $this->db->fetch_array($resql); - $label = ($label_type == 'short_label' ? $res[$label_type] : 'unit'.$res['code']); + if ($label_type == 'code') $label = 'unit'.$res['code']; + else $label = $res[$label_type]; $this->db->free($resql); return $label; } From 0d9d9498e2623e2d850767d109c071dbdaae02fe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 14 Sep 2020 00:13:12 +0200 Subject: [PATCH 2/3] Update commonobjectline.class.php --- htdocs/core/class/commonobjectline.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 5d03c91ca4b..a68d5c22002 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -51,7 +51,7 @@ abstract class CommonObjectLine extends CommonObject /** - * Returns the translation key from units dictionary. + * Returns the label, shot_label or code found in units dictionary from ->fk_unit. * A langs->trans() must be called on result to get translated value. * * @param string $type Label type (long, short or code). This can be a translation key. From d0698735d61969ce96474de6b78de5e5ed94c6f3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 14 Sep 2020 00:14:25 +0200 Subject: [PATCH 3/3] Update product.class.php --- htdocs/product/class/product.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b5f278bcf61..99590e27a36 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5367,11 +5367,12 @@ class Product extends CommonObject } /** - * Returns the text label from units dictionary - * A langs->trans() must be called on result to get translated value. + * Returns the label, shot_label or code found in units dictionary from ->fk_unit. + * A langs->trans() must be called on result to get translated value. * * @param string $type Label type (long, short or code) * @return string|int <0 if ko, label if ok + * @see getLabelOfUnit() in CommonObjectLine */ public function getLabelOfUnit($type = 'long') {