UserDateField::getCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class UserTextField
5
 *
6
 * @author Bram de Leeuw
7
 * @package UserTextField
8
 *
9
 * @property string MinDate
10
 * @property string MaxDate
11
 */
12
class UserDateField extends Broarm\EventTickets\UserField
13
{
14
    /**
15
     * @var DateField
16
     */
17
    protected $fieldType = 'DateField';
18
19
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
20
        'MinDate' => 'Date',
21
        'MaxDate' => 'Date'
22
    );
23
24
    public function getCMSFields()
25
    {
26
        $fields = parent::getCMSFields();
27
        $fields->addFieldsToTab('Root.Validation', array(
28
            DateField::create('MinDate', _t('UserDateField.MinDate', 'Minimum required date'))->setConfig('showcalendar', true),
29
            DateField::create('MaxDate', _t('UserDateField.MaxDate', 'Maximum required date'))->setConfig('showcalendar', true)
30
        ));
31
32
        return $fields;
33
    }
34
35
    /**
36
     * Create a default text field
37
     *
38
     * @param string  $fieldName
39
     * @param null    $defaultValue
40
     * @param boolean $main check if the field is for the main attendee
41
     *
42
     * @return DateField
43
     */
44
    public function createField($fieldName, $defaultValue = null, $main = false)
45
    {
46
        /** @var DateField $dateField */
47
        $dateField = parent::createField($fieldName, $defaultValue, $main);
48
49
        if ($this->MinDate) {
50
            $dateField->setConfig('min', $this->dbObject('MinDate')->Format('Y-m-d'));
51
        }
52
53
        if ($this->MaxDate) {
54
            $dateField->setConfig('max', $this->dbObject('MaxDate')->Format('Y-m-d'));
55
        }
56
57
        return $dateField;
58
    }
59
}
60