| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Element_Input_TimeRange extends HC3_Ui_Abstract_Input |
| 3 |
{ |
| 4 |
protected $el = 'select'; |
| 5 |
protected $uiType = 'input/timerange'; |
| 6 |
protected $timeFormatOptions = array(); |
| 7 |
|
| 8 |
public function __construct( $htmlFactory, $name, $label = NULL, $timeFormatOptions = array(), $value = array() ) |
| 9 |
{ |
| 10 |
parent::__construct( $htmlFactory, $name, $label, $value ); |
| 11 |
$this->timeFormatOptions = $timeFormatOptions; |
| 12 |
} |
| 13 |
|
| 14 |
public function setValue( $value ) |
| 15 |
{ |
| 16 |
if( ! is_array($value) ){ |
| 17 |
$value = explode( '-', $value ); |
| 18 |
} |
| 19 |
$this->value = $value; |
| 20 |
return $this; |
| 21 |
} |
| 22 |
|
| 23 |
public function render() |
| 24 |
{ |
| 25 |
$input_value = NULL; |
| 26 |
if( $this->value && is_array($this->value) ){ |
| 27 |
$input_value = array(); |
| 28 |
foreach( $this->value as $v ){ |
| 29 |
$input_value[] = $v; |
| 30 |
} |
| 31 |
$input_value = join('-', $input_value); |
| 32 |
} |
| 33 |
$hidden = $this->htmlFactory->makeInputHidden( $this->name(), $input_value ); |
| 34 |
|
| 35 |
$display = $this->htmlFactory->makeBlock() |
| 36 |
->addAttr('class', 'hcj-display') |
| 37 |
; |
| 38 |
|
| 39 |
$out = $this->htmlFactory->makeCollection( array($hidden, $display) ); |
| 40 |
$out = $this->htmlFactory->makeBlock( $out ) |
| 41 |
->addAttr('class', 'hcj-timerange-input') |
| 42 |
; |
| 43 |
|
| 44 |
// time options |
| 45 |
$data_atts = array( |
| 46 |
'time-format' => $this->timeFormatOptions, |
| 47 |
); |
| 48 |
|
| 49 |
foreach( $data_atts as $k => $v ){ |
| 50 |
$out->addAttr('data-' . $k, htmlentities(json_encode($v))); |
| 51 |
} |
| 52 |
|
| 53 |
if( strlen($this->label) ){ |
| 54 |
$out = $this->htmlFactory->makeLabelled( $this->label, $out, $this->htmlId() ); |
| 55 |
} |
| 56 |
|
| 57 |
return $out; |
| 58 |
} |
| 59 |
} |
| 60 |
|