SelectAddress.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ L2pnmX5+5Y8H28Ms2vGsX/CH9ZVJ/Uk72+QhRq3BGPg=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * address selector form element
  14. */
  15. namespace Ppb\Form\Element;
  16. use Cube\Form\Element\Radio;
  17. class SelectAddress extends Radio
  18. {
  19. /**
  20. *
  21. * render the form element
  22. *
  23. * @return string
  24. */
  25. public function render()
  26. {
  27. $output = null;
  28. $value = $this->getValue();
  29. foreach ((array)$this->_multiOptions as $key => $option) {
  30. $checked = ($value == $key) ? ' checked="checked" ' : '';
  31. if (is_array($option)) {
  32. $title = $this->_getData($option, 'title');
  33. $description = $this->_getData($option, 'description');
  34. $locationId = $this->_getData($option, 'locationId');
  35. $postCode = $this->_getData($option, 'postCode');
  36. }
  37. else {
  38. $title = $option;
  39. $description = null;
  40. }
  41. $output .= '<label class="radio">'
  42. . '<input type="' . $this->_element . '" name="' . $this->_name . '" value="' . $key . '" '
  43. . $this->renderAttributes()
  44. . (($locationId !== null) ? ' data-location-id="' . $locationId . '"' : '')
  45. . (($postCode !== null) ? ' data-post-code="' . $postCode . '"' : '')
  46. . $checked
  47. . $this->_endTag
  48. . ' ' . $title
  49. . (($description !== null) ? '<span class="help-block">' . $description . '</span>' : '')
  50. . '</label>'
  51. . "\n";
  52. }
  53. return $output;
  54. }
  55. protected function _getData($array, $key)
  56. {
  57. return (isset($array[$key])) ? $array[$key] : null;
  58. }
  59. }