Range.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ ZxGQoh7b7qzwicMG9D91VmSXWZC22ynkIdTVuWwygb8=
  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.7
  11. */
  12. /**
  13. * range form element
  14. */
  15. namespace Ppb\Form\Element;
  16. use Cube\Form\Element;
  17. class Range extends Element
  18. {
  19. const RANGE_FROM = '0';
  20. const RANGE_TO = '1';
  21. /**
  22. *
  23. * type of element - override the variable from the parent class
  24. *
  25. * @var string
  26. */
  27. protected $_element = 'range';
  28. /**
  29. *
  30. * class constructor
  31. *
  32. * @param string $name
  33. */
  34. public function __construct($name)
  35. {
  36. parent::__construct('text', $name);
  37. $this->setMultiple(true);
  38. }
  39. /**
  40. *
  41. * return the value(s) of the element, either the element's data or default value(s)
  42. *
  43. * @param string $key
  44. *
  45. * @return mixed
  46. */
  47. public function getValue($key = null)
  48. {
  49. $value = parent::getValue();
  50. if ($key !== null) {
  51. if (array_key_exists($key, (array)$value)) {
  52. return $value[$key];
  53. }
  54. else {
  55. return null;
  56. }
  57. }
  58. return $value;
  59. }
  60. /**
  61. *
  62. * render composite element
  63. *
  64. * @return string
  65. */
  66. public function render()
  67. {
  68. return $this->getPrefix() . ' '
  69. . '<input type="' . $this->_type . '" '
  70. . 'name="' . $this->_name . '[' . self::RANGE_FROM . ']' . '" '
  71. . $this->renderAttributes()
  72. . 'value="' . $this->getValue(self::RANGE_FROM) . '" '
  73. . $this->_endTag . ' '
  74. . $this->getSuffix()
  75. . ' - '
  76. . $this->getPrefix() . ' '
  77. . '<input type="' . $this->_type . '" '
  78. . 'name="' . $this->_name . '[' . self::RANGE_TO . ']' . '" '
  79. . $this->renderAttributes()
  80. . 'value="' . $this->getValue(self::RANGE_TO) . '" '
  81. . $this->_endTag . ' '
  82. . $this->getSuffix();
  83. }
  84. }