Completed
Pull Request — master (#119)
by Franco
02:26
created

DateRangeField::isComposite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class DateRangeField Custom DateRangeField which can be used
5
 *
6
 * @package dms
7
 *
8
 */
9
10
class DateRangeField extends FieldGroup
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    public $minDate, $maxDate;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
13
    protected $template = "DateRangeField";
14
15
    public function __construct($name, $minTitle = '', $maxTitle = '', $min = null, $max = null, $minPlaceHolder = null, $maxPlaceHolder = null)
16
    {
17
18
        $minDate = new DateField($name.'[min]', $minTitle, $min);
19
        $maxDate = new DateField($name.'[max]', $maxTitle, $max);
20
21
        $minDate->setConfig("showcalendar", true);
22
        $minDate->setConfig("dateformat", 'yyyy-MM-dd');
23
        if ($minPlaceHolder) {
24
            $minDate->setAttribute('placeholder', $minPlaceHolder);
25
        } else {
26
            $minDate->setAttribute('placeholder', "yyyy-mm-dd");
27
        }
28
29
        $maxDate->setconfig("showcalendar", true);
30
        $maxDate->setConfig("dateformat", 'yyyy-MM-dd');
31
        if ($maxPlaceHolder) {
32
            $maxDate->setAttribute('placeholder', $maxPlaceHolder);
33
        } else {
34
            $maxDate->setAttribute('placeholder', "yyyy-mm-dd");
35
        }
36
37
        $this->minDate = $minDate;
38
        $this->maxDate = $maxDate;
39
        $this->setName($name);
40
        Requirements::css(DMS_DIR . '/css/DateRangeField.css');
41
        parent::__construct($name, new FieldList($this->minDate, $this->maxDate));
42
    }
43
44
    public function FieldMin()
45
    {
46
        return $this->minDate;
47
    }
48
49
    public function FieldMax()
50
    {
51
        return $this->maxDate;
52
    }
53
54
    public function setName($name)
55
    {
56
        $this->minDate->setName($name.'[min]');
57
        $this->maxDate->setName($name.'[max]');
58
        parent::setName($name);
59
    }
60
61
    public function isComposite()
62
    {
63
        return true;
64
    }
65
66
    public function setValue($value)
67
    {
68
        if (isset($value['min'])) {
69
            $this->minDate->setValue($value['min']);
70
        }
71
        if (isset($value['max'])) {
72
            $this->maxDate->setValue($value['max']);
73
        }
74
    }
75
76
    public function Field($properties = array())
77
    {
78
        Requirements::css(DMS_DIR . '/css/DateRangeField.css');
79
        return parent::Field($properties);
80
    }
81
}
82