forked from Wavyzz/dolibarr
Merge branch 'develop' of github.com:Dolibarr/dolibarr into develop
This commit is contained in:
@@ -1159,29 +1159,43 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a clone of instance of object (new instance with same value for properties)
|
||||
* With native = 0: Property that are reference are also new object (full isolation clone). This means $this->db of new object may not be valid.
|
||||
* Create a clone of instance of object (new instance with same value for each properties)
|
||||
* With native = 0: Property that are reference are different memory area in the new object (full isolation clone). This means $this->db of new object may not be valid.
|
||||
* With native = 1: Use PHP clone. Property that are reference are same pointer. This means $this->db of new object is still valid but point to same this->db than original object.
|
||||
* With native = 2: Property that are reference are different memory area in the new object (full isolation clone). Only scalar and array values are cloned. This means $this->db of new object is not valid.
|
||||
*
|
||||
* @param object $object Object to clone
|
||||
* @param int $native 0=Full isolation method, 1=Native PHP method, 2=Full isolation method+destroy non scalar or array properties (recommended)
|
||||
* @param int $native 0=Full isolation method, 1=Native PHP method, 2=Full isolation method keeping only scalar and array properties (recommended)
|
||||
* @return object Clone object
|
||||
* @see https://php.net/manual/language.oop5.cloning.php
|
||||
*/
|
||||
function dol_clone($object, $native = 0)
|
||||
{
|
||||
if ($native == 0) {
|
||||
// deprecated method, use the method with native = 2 instead
|
||||
$tmpsavdb = null;
|
||||
if (isset($object->db) && isset($object->db->db) && is_object($object->db->db) && get_class($object->db->db) == 'PgSql\Connection') {
|
||||
$tmpsavdb = $object->db;
|
||||
unset($object->db); // Such property can not be serialized with pgsl (when object->db->db = 'PgSql\Connection')
|
||||
}
|
||||
|
||||
$myclone = unserialize(serialize($object)); // serialize then unserialize is hack to be sure to have a new object for all fields
|
||||
$myclone = unserialize(serialize($object)); // serialize then unserialize is a hack to be sure to have a new object for all fields
|
||||
|
||||
if (!empty($tmpsavdb)) {
|
||||
$object->db = $tmpsavdb;
|
||||
}
|
||||
} elseif ($native == 2) {
|
||||
// recommended method to have a full isolated cloned object
|
||||
$myclone = new stdClass();
|
||||
$tmparray = get_object_vars($object); // return only public properties
|
||||
|
||||
if (is_array($tmparray)) {
|
||||
foreach ($tmparray as $propertykey => $propertyval) {
|
||||
if (is_scalar($propertyval) || is_array($propertyval)) {
|
||||
$myclone->$propertykey = $propertyval;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep the reference (refering to the same target/variable)
|
||||
}
|
||||
@@ -5657,8 +5671,8 @@ function vatrate($rate, $addpercent = false, $info_bits = 0, $usestarfornpr = 0,
|
||||
* @param integer $form Type of format, HTML or not (not by default)
|
||||
* @param Translate|string $outlangs Object langs for output. '' use default lang. 'none' use international separators.
|
||||
* @param int $trunc 1=Truncate if there is more decimals than MAIN_MAX_DECIMALS_SHOWN (default), 0=Does not truncate. Deprecated because amount are rounded (to unit or total amount accurancy) before beeing inserted into database or after a computation, so this parameter should be useless.
|
||||
* @param int $rounding Minimum number of decimal to show. If 0, no change, if -1, we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT)
|
||||
* @param int $forcerounding Force the number of decimal to forcerounding decimal (-1=do not force)
|
||||
* @param int $rounding MINIMUM number of decimal to show. 0=no change, -1=we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT)
|
||||
* @param int|string $forcerounding Force the MAXIMUM of decimal to forcerounding decimal (-1=no change, 'MU' or 'MT' or numeric to round to MU or MT or to a given number of decimal)
|
||||
* @param string $currency_code To add currency symbol (''=add nothing, 'auto'=Use default currency, 'XXX'=add currency symbols for XXX currency)
|
||||
* @return string String with formated amount
|
||||
*
|
||||
@@ -5729,8 +5743,14 @@ function price($amount, $form = 0, $outlangs = '', $trunc = 1, $rounding = -1, $
|
||||
}
|
||||
|
||||
// If force rounding
|
||||
if ($forcerounding >= 0) {
|
||||
$nbdecimal = $forcerounding;
|
||||
if ((string) $forcerounding != '-1') {
|
||||
if ($forcerounding == 'MU') {
|
||||
$nbdecimal = $conf->global->MAIN_MAX_DECIMALS_UNIT;
|
||||
} else if ($forcerounding == 'MT') {
|
||||
$nbdecimal = $conf->global->MAIN_MAX_DECIMALS_TOT;
|
||||
} elseif ($forcerounding >= 0) {
|
||||
$nbdecimal = $forcerounding;
|
||||
}
|
||||
}
|
||||
|
||||
// Format number
|
||||
|
||||
Reference in New Issue
Block a user