2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Single checkbox field.
|
2012-04-14 07:32:29 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class CheckboxField extends FormField {
|
2009-04-29 03:20:24 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setValue($value) {
|
2009-04-29 03:20:24 +02:00
|
|
|
$this->value = ($value) ? 1 : 0;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2009-04-29 03:20:24 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function dataValue() {
|
2011-05-23 10:36:20 +02:00
|
|
|
return ($this->value) ? 1 : NULL;
|
2009-04-29 03:20:24 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Value() {
|
2009-04-29 03:20:24 +02:00
|
|
|
return ($this->value) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2011-12-22 13:10:57 +01:00
|
|
|
$attrs = parent::getAttributes();
|
|
|
|
$attrs['value'] = 1;
|
|
|
|
return array_merge(
|
|
|
|
$attrs,
|
|
|
|
array(
|
|
|
|
'checked' => ($this->Value()) ? 'checked' : null,
|
|
|
|
'type' => 'checkbox',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a readonly version of this field
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performReadonlyTransformation() {
|
2012-03-24 01:17:48 +01:00
|
|
|
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
|
2007-07-19 12:40:28 +02:00
|
|
|
$field->setForm($this->form);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performDisabledTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
$clone->setDisabled(true);
|
|
|
|
return $clone;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-01-10 01:34:18 +01:00
|
|
|
/**
|
|
|
|
* Readonly version of a checkbox field - "Yes" or "No".
|
2012-04-14 07:32:29 +02:00
|
|
|
*
|
2008-01-10 01:34:18 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class CheckboxField_Readonly extends ReadonlyField {
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performReadonlyTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
return clone $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2012-03-24 01:17:48 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Value() {
|
2012-03-24 01:17:48 +01:00
|
|
|
return Convert::raw2xml($this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-10-16 15:44:05 +02:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|