diff --git a/ChangeLog b/ChangeLog index 2b29cf60bdc..f6530b59c1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ Following changes may create regressions for some external modules, but were nec * Old deprecated module "SimplePOS" has been completely removed. Use module "TakePOS" is you need a Point Of Sale. * The method static ActionComm::getActions($db, ...) is no more static. Use $actioncomm->getActions(...) instead (without $db param). * The 'action=delete&file=...' has been replaced with 'action=deletefile&file=...' to avoid confusion with deletion of object lines. +* Method getDictvalue has been renamed into getDictionaryValue to match camel case rule. + ***** ChangeLog for 14.0.3 compared to 14.0.2 ***** diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 229193d6da8..775e2cd2093 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -1974,7 +1974,7 @@ if ($id) { } } } elseif ($value == 'fk_c_exp_tax_cat') { - $valuetoshow = getDictvalue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $valuetoshow); + $valuetoshow = getDictionaryValue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $valuetoshow); $valuetoshow = $langs->trans($valuetoshow); } elseif ($tabname[$id] == MAIN_DB_PREFIX.'c_exp_tax_cat') { $valuetoshow = $langs->trans($valuetoshow); diff --git a/htdocs/admin/expensereport_rules.php b/htdocs/admin/expensereport_rules.php index 67627a94af8..bddaf58475a 100644 --- a/htdocs/admin/expensereport_rules.php +++ b/htdocs/admin/expensereport_rules.php @@ -257,11 +257,12 @@ foreach ($rules as $rule) { if ($rule->fk_c_type_fees == -1) { echo $langs->trans('AllExpenseReport'); } else { - $key = getDictvalue(MAIN_DB_PREFIX.'c_type_fees', 'code', $rule->fk_c_type_fees, false, 'id'); - if ($key != $langs->trans($key)) { + $key = getDictionaryValue(MAIN_DB_PREFIX.'c_type_fees', 'code', $rule->fk_c_type_fees, false, 'id'); + if ($key && $key != $langs->trans($key)) { echo $langs->trans($key); } else { - echo $langs->trans(getDictvalue(MAIN_DB_PREFIX.'c_type_fees', 'label', $rule->fk_c_type_fees, false, 'id')); // TODO check to return trans of 'code' + $value = getDictionaryValue(MAIN_DB_PREFIX.'c_type_fees', 'label', $rule->fk_c_type_fees, false, 'id'); + echo $langs->trans($value ? $value : 'Undefined'); // TODO check to return trans of 'code' } } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b08d8e55686..98a879410b0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9563,21 +9563,24 @@ function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0) } /** - * Return value from dictionary + * Return the value of a filed into a dictionary for the record $id. + * This also set all the values into a cache for a next search. * - * @param string $tablename name of dictionary - * @param string $field the value to return - * @param int $id id of line - * @param bool $checkentity add filter on entity - * @param string $rowidfield name of the column rowid - * @return string + * @param string $tablename Name of dictionary + * @param string $field The name of field where to find the value to return + * @param int $id Id of line record + * @param bool $checkentity Add filter on entity + * @param string $rowidfield Name of the column rowid (to use for the filter on $id) + * @return string The value of field $field. This also set $dictvalues cache. */ -function getDictvalue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid') +function getDictionaryValue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid') { - global $dictvalues, $db, $langs; + global $conf, $db; - if (!isset($dictvalues[$tablename])) { - $dictvalues[$tablename] = array(); + $dictvalues = (isset($conf->cache['dictvalues_'.$tablename]) ? $conf->cache['dictvalues_'.$tablename] : null); + + if (is_null($dictvalues)) { + $dictvalues = array(); $sql = "SELECT * FROM ".$tablename." WHERE 1 = 1"; // Here select * is allowed as it is generic code and we don't have list of fields if ($checkentity) { @@ -9587,20 +9590,20 @@ function getDictvalue($tablename, $field, $id, $checkentity = false, $rowidfield $resql = $db->query($sql); if ($resql) { while ($obj = $db->fetch_object($resql)) { - $dictvalues[$tablename][$obj->{$rowidfield}] = $obj; + $dictvalues[$obj->{$rowidfield}] = $obj; } } else { dol_print_error($db); } + + $conf->cache['dictvalues_'.$tablename] = $dictvalues; } - if (!empty($dictvalues[$tablename][$id])) { - return $dictvalues[$tablename][$id]->{$field}; // Found - } else // Not found - { - if ($id > 0) { - return $id; - } + if (!empty($dictvalues[$id])) { + // Found + return $dictvalues[$id]->{$field}; + } else { + // Not found return ''; } }