1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SKien\Formgenerator; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Input field for currency value. |
8
|
|
|
* Special variant of FormFloat with |
9
|
|
|
* - fixed two decimalpoints. |
10
|
|
|
* - Separators can be specified alternating to the definition for the FormFloat |
11
|
|
|
* - Currency symbol can be appended |
12
|
|
|
* |
13
|
|
|
* @package Formgenerator |
14
|
|
|
* @author Stefanius <[email protected]> |
15
|
|
|
* @copyright MIT License - see the LICENSE file for details |
16
|
|
|
*/ |
17
|
|
|
class FormCur extends FormFloat |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Creates input field for currency values. |
21
|
|
|
* @param string $strName Name (if no ID specified, name is used also as ID) |
22
|
|
|
* @param int|string $size number set the size-attribute, a string is used for the width attribute |
23
|
|
|
* @param int $wFlags any combination of FormFlag constants |
24
|
|
|
*/ |
25
|
|
|
public function __construct(string $strName, $size, int $wFlags = 0) |
26
|
|
|
{ |
27
|
|
|
parent::__construct($strName, $size, 2, $wFlags); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
* @see \SKien\Formgenerator\FormElement::fromXML() |
33
|
|
|
* @internal |
34
|
|
|
*/ |
35
|
|
|
static public function fromXML(\DOMElement $oXMLElement, FormCollection $oFormParent) : ?FormElement |
36
|
|
|
{ |
37
|
|
|
$strName = self::getAttribString($oXMLElement, 'name'); |
38
|
|
|
$strSize = self::getAttribString($oXMLElement, 'size'); |
39
|
|
|
$wFlags = self::getAttribFlags($oXMLElement); |
40
|
|
|
$oFormElement = new self($strName, $strSize, $wFlags); |
41
|
|
|
$oFormParent->add($oFormElement); |
42
|
|
|
$oFormElement->readAdditionalXML($oXMLElement); |
43
|
|
|
return $oFormElement; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* get format from configuration: <ul> |
48
|
|
|
* <li> currency symbol (default: from locale settings) </li></ul> |
49
|
|
|
*/ |
50
|
|
|
protected function onParentSet() : void |
51
|
|
|
{ |
52
|
|
|
parent::onParentSet(); |
53
|
|
|
|
54
|
|
|
$li = localeconv(); |
55
|
|
|
|
56
|
|
|
$this->strDP = $this->oFG->getConfig()->getString('Currency.DecimalPoint', $this->strDP); |
57
|
|
|
$this->strTS = $this->oFG->getConfig()->getString('Currency.ThousandsSep', $this->strTS); |
58
|
|
|
|
59
|
|
|
$this->addAttribute('data-validation', 'float:' . ($this->bEmptyAllowed ? 'e' : 'x') . $this->iDec . $this->strDP . $this->strTS); |
60
|
|
|
$this->setPlaceholder($this->oFG->getConfig()->getString('Currency.Placeholder')); |
61
|
|
|
|
62
|
|
|
if ($this->oFlags->isSet(FormFlags::ADD_CUR)) { |
63
|
|
|
$this->strSuffix = $this->oFG->getConfig()->getString('Currency.Symbol', ($li['currency_symbol'] ?: 'USD')); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|