BootstrapDateRange   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 46
c 1
b 0
f 0
dl 0
loc 67
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 13 3
A setControlHtml() 0 47 1
1
<?php
2
3
namespace kalanis\kw_table\form_nette_bootstrap\Controls;
4
5
6
use kalanis\kw_table\form_nette\Controls\DateRange;
7
use Nette\Forms\Container;
8
use Nette\Utils\Html;
9
10
11
class BootstrapDateRange extends DateRange
12
{
13
    protected string $inputFormat = 'd.m.Y';
14
    protected string $searchFormat = 'Y-m-d 00:00:00';
15
16
    protected function setControlHtml(string $name)
17
    {
18
        $span = Html::el('span');
19
        $divSince = Html::el('div', ['class' => "input-group dateTimePickerRange"]);
20
        $divTo = clone $divSince;
21
22
//        $divGroup = Html::el('div', ['class' => "input-group-addon"]);
23
        $start = $this->start = Html::el('input', [
24
            'type'        => 'text',
25
            'name'        => $name . '[]',
26
            'placeholder' => _('From'),
27
            'id'          => $name . 'StartId',
28
            'class'       => 'form-control cleanable listingDateTimePicker',
29
            'aria-label'  => _('Time from')
30
        ]);
31
        $end = $this->end = Html::el('input', [
32
            'type'        => 'text',
33
            'name'        => $name . '[]',
34
            'placeholder' => _('To'),
35
            'id'          => $name . 'EndId',
36
            'class'       => 'form-control cleanable listingDateTimePicker',
37
            'aria-label'  => _('Time to')
38
        ]);
39
40
        $divGroupBtnSearch = Html::el('div', ['class' => "input-group-btn"]);
41
        $divGroupBtnClear = clone $divGroupBtnSearch;
42
        $buttonSearch = Html::el('button', ['type' => "button", 'class' => "btn btn-default listingSearch", 'aria-label' => "Search"]);
43
        $buttonClear = Html::el('button', ['type' => "button", 'class' => "btn btn-default listingClear", 'aria-label' => "Clear"]);
44
        $spanSearch = Html::el('span', ['class' => "glyphicon glyphicon-search"]);
45
        $spanClear = Html::el('span', ['class' => "glyphicon glyphicon-remove"]);
46
47
        $buttonSearch->add($spanSearch);
48
        $buttonClear->add($spanClear);
49
50
        $divGroupBtnSearch->add($buttonSearch);
51
        $divGroupBtnClear->add($buttonClear);
52
53
        $divSince->add($divGroupBtnSearch);
54
        $divSince->add($start);
55
        $divSince->add($divGroupBtnClear);
56
57
        $divTo->add($divGroupBtnSearch);
58
        $divTo->add($end);
59
        $divTo->add($divGroupBtnClear);
60
        $span->add($divSince);
61
        $span->add($divTo);
62
        $this->control = $span;
0 ignored issues
show
Bug introduced by
The property control is declared read-only in Nette\Forms\Controls\BaseControl.
Loading history...
63
    }
64
65
    public static function register(?string $inputFormat = null, ?string $searchFormat = null)
66
    {
67
        Container::extensionMethod('addBootstrapDateRange', function ($container, $name, $label = null, $maxLength = null) use ($inputFormat, $searchFormat) {
68
            $picker = $container[$name] = new BootstrapDateRange($name, $label, $maxLength);
69
70
            if (null !== $inputFormat) {
71
                $picker->setInputFormat($inputFormat);
72
            }
73
            if (null !== $searchFormat) {
74
                $picker->setSearchFormat($searchFormat);
75
            }
76
77
            return $picker;
78
        });
79
    }
80
}
81