Completed
Push — master ( 5776a0...605463 )
by Daniel
23s
created

CheckboxField_Readonly::getValueCast()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 1
f 0
1
<?php
2
/**
3
 * Single checkbox field.
4
 *
5
 * @package forms
6
 * @subpackage fields-basic
7
 */
8
class CheckboxField extends FormField {
9
10
	protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_SINGLESELECT;
11
12
	public function setValue($value) {
13
		$this->value = ($value) ? 1 : 0;
14
		return $this;
15
	}
16
17
	public function dataValue() {
18
		return ($this->value) ? 1 : NULL;
19
	}
20
21
	public function Value() {
22
		return ($this->value) ? 1 : 0;
23
	}
24
25
	public function getAttributes() {
26
		$attrs = parent::getAttributes();
27
		$attrs['value'] = 1;
28
		return array_merge(
29
			$attrs,
30
			array(
31
				'checked' => ($this->Value()) ? 'checked' : null,
32
				'type' => 'checkbox',
33
			)
34
		);
35
	}
36
37
	/**
38
	 * Returns a readonly version of this field
39
	 */
40
	public function performReadonlyTransformation() {
41
		$field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
42
		$field->setForm($this->form);
43
		return $field;
44
	}
45
46
}
47
48
/**
49
 * Readonly version of a checkbox field - "Yes" or "No".
50
 *
51
 * @package forms
52
 * @subpackage fields-basic
53
 */
54
class CheckboxField_Readonly extends ReadonlyField {
55
56
	public function performReadonlyTransformation() {
57
		return clone $this;
58
	}
59
60
	public function Value() {
61
		return $this->value ?
62
			_t('CheckboxField.YESANSWER', 'Yes') :
63
			_t('CheckboxField.NOANSWER', 'No');
64
	}
65
66
	public function getValueCast() {
67
		return 'Text';
68
	}
69
70
}
71