Blame view

framework/forms/CheckboxField.php 1.2 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  <?php
  /**
   * Single checkbox field.
   *
   * @package forms
   * @subpackage fields-basic
   */
  class CheckboxField extends FormField {
  
  	public function setValue($value) {
  		$this->value = ($value) ? 1 : 0;
  		return $this;
  	}
  
  	public function dataValue() {
  		return ($this->value) ? 1 : NULL;
  	}
  
  	public function Value() {
  		return ($this->value) ? 1 : 0;
  	}
  
  	public function getAttributes() {
  		$attrs = parent::getAttributes();
  		$attrs['value'] = 1;
  		return array_merge(
  			$attrs,
  			array(
  				'checked' => ($this->Value()) ? 'checked' : null,
  				'type' => 'checkbox',
  			)
  		);
  	}
  
  	/**
  	 * Returns a readonly version of this field
  	 */
  	public function performReadonlyTransformation() {
  		$field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
  		$field->setForm($this->form);
  		return $field;	
  	}
  
  }
  
  /**
   * Readonly version of a checkbox field - "Yes" or "No".
   *
   * @package forms
   * @subpackage fields-basic
   */
  class CheckboxField_Readonly extends ReadonlyField {
  
  	public function performReadonlyTransformation() {
  		return clone $this;
  	}
  
  	public function Value() {
  		return Convert::raw2xml($this->value ?
  			_t('CheckboxField.YESANSWER', 'Yes') :
  			_t('CheckboxField.NOANSWER', 'No'));
  	}
  
  }