RETROTEC-AG/OpenXE#18 Number parser implementieren
This commit is contained in:
parent
a64345976e
commit
23d61dd5f4
|
|
@ -8,8 +8,11 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Xentral\Components\I18n;
|
namespace Xentral\Components\I18n;
|
||||||
|
|
||||||
|
use Xentral\Components\I18n\Formatter\CurrencyFormatter;
|
||||||
use Xentral\Components\I18n\Formatter\FloatFormatter;
|
use Xentral\Components\I18n\Formatter\FloatFormatter;
|
||||||
use Xentral\Components\I18n\Formatter\FormatterInterface;
|
use Xentral\Components\I18n\Formatter\FormatterInterface;
|
||||||
|
use Xentral\Components\I18n\Formatter\FormatterMode;
|
||||||
|
use Xentral\Components\I18n\Formatter\IntegerFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service creates formatters for localized input and output.
|
* This service creates formatters for localized input and output.
|
||||||
|
|
@ -80,4 +83,169 @@ class FormatterService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace callback function for \FormActionHandler.
|
||||||
|
* Parses and Formats an integer and allows an empty string.
|
||||||
|
*
|
||||||
|
* @param int $toDatabase
|
||||||
|
* @param mixed $value
|
||||||
|
* @param $fromForm
|
||||||
|
*
|
||||||
|
* @return mixed|string
|
||||||
|
* @see \FormActionHandler
|
||||||
|
*/
|
||||||
|
public function replaceIntegerOrEmpty(int $toDatabase, mixed $value, $fromForm)
|
||||||
|
{
|
||||||
|
$formatter = new IntegerFormatter($this->locale, FormatterMode::MODE_EMPTY);
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_numeric($value) || $fromForm) {
|
||||||
|
$formatter->parseUserInput(strval($value));
|
||||||
|
} else {
|
||||||
|
$formatter->setPhpVal($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($toDatabase) {
|
||||||
|
return $formatter->getPhpVal();
|
||||||
|
} else {
|
||||||
|
return $formatter->formatForUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace callback function for \FormActionHandler.
|
||||||
|
* Parses and Formats a float and allows an empty string.
|
||||||
|
* Output shows decimals, if present.
|
||||||
|
*
|
||||||
|
* @param int $toDatabase
|
||||||
|
* @param mixed $value
|
||||||
|
* @param $fromForm
|
||||||
|
*
|
||||||
|
* @return mixed|string
|
||||||
|
* @see \FormActionHandler
|
||||||
|
*/
|
||||||
|
public function replaceDecimalOrEmpty(int $toDatabase, mixed $value, $fromForm)
|
||||||
|
{
|
||||||
|
$formatter = new FloatFormatter($this->locale, FormatterMode::MODE_EMPTY);
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_numeric($value) || $fromForm) {
|
||||||
|
$formatter->parseUserInput(strval($value));
|
||||||
|
} else {
|
||||||
|
$formatter->setPhpVal(floatval($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($toDatabase) {
|
||||||
|
return $formatter->getPhpVal();
|
||||||
|
} else {
|
||||||
|
return $formatter->formatForUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace callback function for \FormActionHandler.
|
||||||
|
* Parses and Formats a float and allows an empty string.
|
||||||
|
* Output always shows at least 7 decimal.
|
||||||
|
*
|
||||||
|
* @param int $toDatabase
|
||||||
|
* @param mixed $value
|
||||||
|
* @param $fromForm
|
||||||
|
*
|
||||||
|
* @return mixed|string
|
||||||
|
* @see \FormActionHandler
|
||||||
|
*/
|
||||||
|
public function replaceDecimalGeoOrEmpty(int $toDatabase, mixed $value, $fromForm)
|
||||||
|
{
|
||||||
|
$formatter = new FloatFormatter($this->locale, FormatterMode::MODE_EMPTY);
|
||||||
|
$formatter->setMinDigits(7);
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_numeric($value) || $fromForm) {
|
||||||
|
$formatter->parseUserInput(strval($value));
|
||||||
|
} else {
|
||||||
|
$formatter->setPhpVal(floatval($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($toDatabase) {
|
||||||
|
return $formatter->getPhpVal();
|
||||||
|
} else {
|
||||||
|
return $formatter->formatForUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace callback function for \FormActionHandler.
|
||||||
|
* Parses and Formats a float and allows an empty string.
|
||||||
|
* Output always shows at least 1 decimal.
|
||||||
|
*
|
||||||
|
* @param int $toDatabase
|
||||||
|
* @param mixed $value
|
||||||
|
* @param $fromForm
|
||||||
|
*
|
||||||
|
* @return mixed|string
|
||||||
|
* @see \FormActionHandler
|
||||||
|
*/
|
||||||
|
public function replaceDecimalPercentOrEmpty(int $toDatabase, mixed $value, $fromForm)
|
||||||
|
{
|
||||||
|
$formatter = new FloatFormatter($this->locale, FormatterMode::MODE_EMPTY);
|
||||||
|
$formatter->setMinDigits(1);
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_numeric($value) || $fromForm) {
|
||||||
|
$formatter->parseUserInput(strval($value));
|
||||||
|
} else {
|
||||||
|
$formatter->setPhpVal(floatval($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($toDatabase) {
|
||||||
|
return $formatter->getPhpVal();
|
||||||
|
} else {
|
||||||
|
return $formatter->formatForUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace callback function for \FormActionHandler.
|
||||||
|
* Parses and Formats a float and allows an empty string.
|
||||||
|
*
|
||||||
|
* @param int $toDatabase
|
||||||
|
* @param mixed $value
|
||||||
|
* @param $fromForm
|
||||||
|
*
|
||||||
|
* @return mixed|string
|
||||||
|
* @see \FormActionHandler
|
||||||
|
*/
|
||||||
|
public function replaceCurrencyOrEmpty(int $toDatabase, mixed $value, $fromForm)
|
||||||
|
{
|
||||||
|
$formatter = (new FloatFormatter($this->locale, FormatterMode::MODE_EMPTY));
|
||||||
|
$formatter->setMinDigits(2);
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_numeric($value) || $fromForm) {
|
||||||
|
$formatter->parseUserInput(strval($value));
|
||||||
|
} else {
|
||||||
|
$formatter->setPhpVal(floatval($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($toDatabase) {
|
||||||
|
return $formatter->getPhpVal();
|
||||||
|
} else {
|
||||||
|
return $formatter->formatForUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -20,10 +20,12 @@ class WidgetGenadresse
|
||||||
private $app; //application object
|
private $app; //application object
|
||||||
public $form; //store form object
|
public $form; //store form object
|
||||||
protected $parsetarget; //target for content
|
protected $parsetarget; //target for content
|
||||||
|
protected \Xentral\Components\I18n\FormatterService $formatterService;
|
||||||
|
|
||||||
public function __construct($app,$parsetarget)
|
public function __construct($app,$parsetarget)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
$this->formatterService = $this->app->Container->get('FormatterService');
|
||||||
$this->parsetarget = $parsetarget;
|
$this->parsetarget = $parsetarget;
|
||||||
$this->Form();
|
$this->Form();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,21 @@ class WidgetAdresse extends WidgetGenAdresse
|
||||||
$this->form->ReplaceFunction("mandatsreferenzdatum",$this,"ReplaceDatum");
|
$this->form->ReplaceFunction("mandatsreferenzdatum",$this,"ReplaceDatum");
|
||||||
$this->form->ReplaceFunction("liefersperredatum",$this,"ReplaceDatum");
|
$this->form->ReplaceFunction("liefersperredatum",$this,"ReplaceDatum");
|
||||||
|
|
||||||
$this->form->ReplaceFunction("arbeitszeitprowoche",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("arbeitszeitprowoche", $this->formatterService, "replaceDecimalOrEmpty");
|
||||||
$this->form->ReplaceFunction("zahlungszielskonto",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("zahlungszieltage", $this->formatterService, "replaceIntegerOrEmpty");
|
||||||
$this->form->ReplaceFunction("zahlungszielskontolieferant",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("zahlungszieltagelieferant", $this->formatterService, "replaceIntegerOrEmpty");
|
||||||
$this->form->ReplaceFunction("provision",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("zahlungszieltageskonto", $this->formatterService, "replaceDecimalOrEmpty");
|
||||||
$this->form->ReplaceFunction("portofreiab",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("zahlungszieltageskontolieferant", $this->formatterService, "replaceDecimalOrEmpty");
|
||||||
$this->form->ReplaceFunction("portofreiablieferant",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("zahlungszielskonto", $this->formatterService, "replaceDecimalPercentOrEmpty");
|
||||||
$this->form->ReplaceFunction("kreditlimit",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("zahlungszielskontolieferant", $this->formatterService, "replaceDecimalPercentOrEmpty");
|
||||||
$this->form->ReplaceFunction("kreditlimiteinmalig",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("provision", $this->formatterService, "replaceDecimalPercentOrEmpty");
|
||||||
|
$this->form->ReplaceFunction("portofreiab", $this->formatterService, "replaceCurrencyOrEmpty");
|
||||||
|
$this->form->ReplaceFunction("portofreiablieferant", $this->formatterService, "replaceCurrencyOrEmpty");
|
||||||
|
$this->form->ReplaceFunction("kreditlimit", $this->formatterService, "replaceCurrencyOrEmpty");
|
||||||
|
$this->form->ReplaceFunction("kreditlimiteinmalig", $this->formatterService, "replaceCurrencyOrEmpty");
|
||||||
|
|
||||||
$this->form->ReplaceFunction("lat",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("lat", $this->formatterService, "replaceDecimalGeoOrEmpty");
|
||||||
$this->form->ReplaceFunction("lng",$this,"ReplaceBetrag");
|
$this->form->ReplaceFunction("lng", $this->formatterService, "replaceDecimalGeoOrEmpty");
|
||||||
$this->form->ReplaceFunction("name",$this,"ReplaceTrim");
|
$this->form->ReplaceFunction("name",$this,"ReplaceTrim");
|
||||||
|
|
||||||
$this->app->YUI->CkEditor("sonstiges","internal");
|
$this->app->YUI->CkEditor("sonstiges","internal");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue