2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Single checkbox field.
|
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
|
|
|
|
|
|
|
function setValue($value) {
|
|
|
|
$this->value = ($value) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-04-29 03:20:24 +02:00
|
|
|
function Value() {
|
|
|
|
return ($this->value) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2011-03-23 05:12:25 +01:00
|
|
|
function Field($properties = array()) {
|
|
|
|
return $this->customise($properties)->renderWith('CheckboxField');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2011-03-23 05:12:25 +01:00
|
|
|
function FieldHolder() {
|
|
|
|
$this->setFieldHolderTemplate(($this->fieldHolderTemplate) ? $this->fieldHolderTemplate : 'CheckboxFieldHolder');
|
|
|
|
return parent::FieldHolder();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a restricted field holder used within things like FieldGroups
|
|
|
|
*/
|
|
|
|
function SmallFieldHolder() {
|
|
|
|
$result = $this->Field();
|
|
|
|
if($t = $this->Title()) {
|
|
|
|
$result .= "<label for=\"" . $this->id() ."\">$t</label> ";
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a readonly version of this field
|
|
|
|
*/
|
|
|
|
function performReadonlyTransformation() {
|
2009-04-29 03:20:24 +02:00
|
|
|
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
|
2007-07-19 12:40:28 +02:00
|
|
|
$field->setForm($this->form);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
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".
|
|
|
|
* @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
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function performReadonlyTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
return clone $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setValue($val) {
|
2010-10-19 03:21:45 +02:00
|
|
|
$this->value = (int)($val) ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-10-16 15:44:05 +02:00
|
|
|
|
2011-03-23 05:12:25 +01:00
|
|
|
}
|