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