added a wrapper for the bcmath functions, so there will be a (basic) fall back if those functions are not on the server

This commit is contained in:
2018-04-08 23:20:33 +02:00
parent 10fdac5d60
commit 6d4c823ea6
9 changed files with 61 additions and 18 deletions

View File

@ -548,7 +548,7 @@ class Compiler extends Infusion
$lineBites[$lineNumber] = (int) mb_strlen($lineContent, '8bit');
if (!$found)
{
$bites = (int) bcadd($lineBites[$lineNumber], $bites);
$bites = (int) $this->bcmath('add', $lineBites[$lineNumber], $bites);
}
if ($found && !$foundEnd)
{
@ -684,12 +684,12 @@ class Compiler extends Infusion
// Add the data
fwrite($fpFile, $data);
// truncate file at the end of the data that was added
$remove = bcadd($position, mb_strlen($data, '8bit'));
$remove = $this->bcmath('add', $position, mb_strlen($data, '8bit'));
ftruncate($fpFile, $remove);
// check if this was a replacement of data
if ($replace)
{
$position = bcadd($position, $replace);
$position = $this->bcmath('add', $position, $replace);
}
// move to the position of the data that should remain below the new data
fseek($fpTemp, $position);

View File

@ -5710,4 +5710,46 @@ class Get
return false;
}
/**
* bc math wrapper (very basic not for accounting)
*
* @param string $type The type bc math
* @param int $val1 The first value
* @param int $val2 The second value
*
* @return int
*
*/
public function bcmath($type, $val1, $val2)
{
// build function name
$function = 'bc'.$type;
// use the bcmath function of available
if (function_exists($function))
{
return $function($val1, $val2);
}
// if function does not exist we use +-*/ operators (since it realy not that serious)
switch($type)
{
// Multiply two numbers
case 'mul':
return round($val1 * $val2);
break;
// Divide of two numbers
case 'div':
return round($val1 / $val2);
break;
// Adding two numbers
case 'add':
return round($val1 + $val2);
break;
// Subtract one number from the other
case 'add':
return round($val1 - $val2);
break;
}
return false;
}
}

View File

@ -1217,8 +1217,8 @@ class Infusion extends Interpretation
if ('en-GB' !== $tag)
{
$langStringNr = count($languageStrings);
$langStringSum = bcmul($langStringNr, 100);
$percentage = bcdiv($langStringSum, $mainLangLoader[$area]);
$langStringSum = $this->bcmath('mul', $langStringNr, 100);
$percentage = $this->bcmath('div', $langStringSum, $mainLangLoader[$area]);
$stringNAme = ($langStringNr == 1) ? '(string ' . $tag . ' translated)' : '(strings ' . $tag . ' translated)';
// force load if debug lines are added
if (!$this->debugLinenr)
@ -1304,5 +1304,4 @@ class Infusion extends Interpretation
}
}
}
}

View File

@ -1660,7 +1660,8 @@ abstract class ComponentbuilderHelper
}
return $klaar;
}
public static function getFieldOptions($value, $type, $settings = array())
{
// Get a db connection.

View File

@ -277,13 +277,13 @@ class Builder extends Mapping
protected function setFieldXML(&$field, $fieldId)
{
// load the field settings
$settings = array();
$settings['name'] = $field['name'];
$settings['description'] = 'The '.strtolower($field['label']) . ' is set here.';
$settings['message'] = "Error! Please add some ".strtolower($field['label'])." here.";
$settings['label'] = $field['label'];
$settings['default'] = ($field['default'] == 'Other') ? $field['defaultOther'] : $field['default'];
$settings['hint'] = $field['label'] .' Here!';
$settings = array();
$settings['name'] = $field['name'];
$settings['description'] = 'The '.strtolower($field['label']) . ' is set here.';
$settings['message'] = "Error! Please add some ".strtolower($field['label'])." here.";
$settings['label'] = $field['label'];
$settings['default'] = ($field['default'] == 'Other') ? $field['defaultOther'] : $field['default'];
$settings['hint'] = $field['label'] .' Here!';
// okay set the xml field values
if ($fieldOptions = ComponentbuilderHelper::getFieldOptions($fieldId, 'id', $settings))
{