LocalizedNumeric.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ YiS2qE8mFFUB1lpn9ufd2/gZfLszl9WpY+Szb5+Qd34=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2016 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.8
  11. */
  12. /**
  13. * localized number input element
  14. * the format and decimals are set automatically by the locale format instance
  15. * - highly recommended to use the localized numeric filter together with this element
  16. * OR
  17. * - when saving in the database, the value from the field needs to be
  18. * formatted with the Cube\Locale\Format::localizedToNumeric() method
  19. */
  20. namespace Ppb\Form\Element;
  21. use Cube\Form\Element,
  22. Cube\Locale\Format as LocaleFormat;
  23. class LocalizedNumeric extends Element
  24. {
  25. /**
  26. *
  27. * type of element - override the variable from the parent class
  28. *
  29. * @var string
  30. */
  31. protected $_element = 'text';
  32. /**
  33. *
  34. * class constructor
  35. *
  36. * @param string $name
  37. */
  38. public function __construct($name)
  39. {
  40. parent::__construct($this->_element, $name);
  41. }
  42. /**
  43. *
  44. * renders the html form element
  45. *
  46. * @return string the html code of the element
  47. */
  48. public function render()
  49. {
  50. $value = $this->getValue();
  51. $localizedValue = LocaleFormat::getInstance()->numericToLocalized($value, true);
  52. $multiple = ($this->getMultiple() === true) ? $this->_brackets : '';
  53. return $this->getPrefix() . ' '
  54. . '<input type="' . $this->_type . '" '
  55. . 'name="' . $this->_name . $multiple . '" '
  56. . $this->renderAttributes()
  57. . 'value="' . $localizedValue . '" '
  58. . $this->_endTag . ' '
  59. . $this->getSuffix();
  60. }
  61. }