UserNumericField::createField()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 4
nop 3
1
<?php
2
3
/**
4
 * Class UserNumericField
5
 *
6
 * @property int Min
7
 * @property int Max
8
 *
9
 * @author Bram de Leeuw
10
 * @package UserTextField
11
 */
12
class UserNumericField extends Broarm\EventTickets\UserField
13
{
14
    /**
15
     * @var NumericField
16
     */
17
    protected $fieldType = 'NumericField';
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
        'Min' => 'Int',
21
        'Max' => 'Int'
22
    );
23
24
    public function getCMSFields()
25
    {
26
        $fields = parent::getCMSFields();
27
        $fields->addFieldsToTab('Root.Validation', array(
28
            NumericField::create('Min', _t('UserNumericField.Min', 'Minimum required number')),
29
            NumericField::create('Max', _t('UserNumericField.Max', 'Maximum required number'))
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 NumericField|FormField
43
     */
44
    public function createField($fieldName, $defaultValue = null, $main = false)
45
    {
46
        $numericField = parent::createField($fieldName, $defaultValue, $main);
47
48
        if (!empty($this->Min)) {
49
            $numericField->setAttribute('min', $this->Min);
50
        }
51
52
        if (!empty($this->Max)) {
53
            $numericField->setAttribute('max', $this->Max);
54
        }
55
56
        return $numericField;
57
    }
58
}
59