| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Element_Input_RadioSet extends HC3_Ui_Abstract_Input |
| 3 |
{ |
| 4 |
protected $el = 'input'; |
| 5 |
protected $uiType = 'input/radio'; |
| 6 |
protected $options = array(); |
| 7 |
|
| 8 |
public function __construct( $htmlFactory, $name, $label = NULL, $options = array(), $value = NULL ) |
| 9 |
{ |
| 10 |
parent::__construct( $htmlFactory, $name, $label, $value ); |
| 11 |
$this->options = $options; |
| 12 |
} |
| 13 |
|
| 14 |
public function render() |
| 15 |
{ |
| 16 |
$options = array(); |
| 17 |
foreach( $this->options as $k => $v ){ |
| 18 |
if( ! strlen($k) ){ |
| 19 |
$k = ' '; |
| 20 |
} |
| 21 |
$checked = ( $k == $this->value ) ? TRUE : FALSE; |
| 22 |
$this_input = $this->htmlFactory->makeInputRadio( $this->name, $v, $k, $checked ); |
| 23 |
$options[] = $this_input; |
| 24 |
} |
| 25 |
|
| 26 |
$out = $this->htmlFactory->makeListInline( $options ); |
| 27 |
|
| 28 |
if( strlen($this->label) ){ |
| 29 |
$out = $this->htmlFactory->makeLabelled( $this->label, $out, $this->htmlId() ); |
| 30 |
} |
| 31 |
|
| 32 |
return $out; |
| 33 |
} |
| 34 |
} |