| Total Complexity | 13 |
| Total Lines | 105 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | class Range extends TextInput |
||
| 18 | { |
||
| 19 | protected string $inputFormat = 'd.m.Y H:i:s'; |
||
| 20 | protected string $searchFormat = 'Y-m-d H:i:s'; |
||
| 21 | |||
| 22 | protected ?Html $start; |
||
| 23 | protected ?Html $end; |
||
| 24 | protected ?DateTime $startValue; |
||
| 25 | protected ?DateTime $endValue; |
||
| 26 | |||
| 27 | private $started = false; |
||
| 28 | |||
| 29 | public function __construct(string $name, $label = null, $maxLength = null) |
||
| 30 | { |
||
| 31 | parent::__construct($label, $maxLength); |
||
| 32 | |||
| 33 | $this->setControlHtml($name); |
||
| 34 | $this->started = true; |
||
| 35 | } |
||
| 36 | |||
| 37 | protected function setControlHtml(string $name) |
||
| 38 | { |
||
| 39 | $span = Html::el('span'); |
||
| 40 | $divSince = Html::el('div', ['class' => 'input-group dateTimePickerRange']); |
||
| 41 | |||
| 42 | $start = $this->start = Html::el('input', [ |
||
| 43 | 'type' => 'text', |
||
| 44 | 'name' => $name . '[]', |
||
| 45 | 'placeholder' => _('From'), |
||
| 46 | 'id' => $name . 'StartId', |
||
| 47 | 'class' => 'form-control cleanable', |
||
| 48 | 'aria-label' => _('Time from') |
||
| 49 | ]); |
||
| 50 | $end = $this->end = Html::el('input', [ |
||
| 51 | 'type' => 'text', |
||
| 52 | 'name' => $name . '[]', |
||
| 53 | 'placeholder' => _('To'), |
||
| 54 | 'id' => $name . 'StartId', |
||
| 55 | 'class' => 'form-control cleanable', |
||
| 56 | 'aria-label' => _('Time to') |
||
| 57 | ]); |
||
| 58 | |||
| 59 | $divTo = clone $divSince; |
||
| 60 | $divSince->add($start); |
||
| 61 | $divTo->add($end); |
||
| 62 | $span->add($divSince); |
||
| 63 | $span->add($divTo); |
||
| 64 | $this->control = $span; |
||
|
|
|||
| 65 | } |
||
| 66 | |||
| 67 | public function setInputFormat(string $format) |
||
| 68 | { |
||
| 69 | $this->inputFormat = $format; |
||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function setSearchFormat(string $format) |
||
| 77 | } |
||
| 78 | |||
| 79 | public function getValue() |
||
| 80 | { |
||
| 81 | return [ |
||
| 82 | 0 => $this->startValue, |
||
| 83 | 1 => $this->endValue |
||
| 84 | ]; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function setValue($value) |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | public static function register(?string $inputFormat = null, ?string $searchFormat = null) |
||
| 112 | { |
||
| 125 |