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 {
|
|
|
|
|
|
|
|
protected $disabled;
|
2009-04-29 03:20:24 +02:00
|
|
|
|
|
|
|
function setValue($value) {
|
|
|
|
$this->value = ($value) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dataValue() {
|
|
|
|
return ($this->value) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Value() {
|
|
|
|
return ($this->value) ? 1 : 0;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
function Field() {
|
2008-04-06 06:08:45 +02:00
|
|
|
$attributes = array(
|
|
|
|
'type' => 'checkbox',
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => ($this->extraClass() ? $this->extraClass() : ''),
|
2008-04-06 06:08:45 +02:00
|
|
|
'id' => $this->id(),
|
2008-04-09 13:21:22 +02:00
|
|
|
'name' => $this->Name(),
|
2009-04-29 03:20:24 +02:00
|
|
|
'value' => 1,
|
2008-10-25 13:19:31 +02:00
|
|
|
'checked' => $this->value ? 'checked' : '',
|
2008-10-20 12:22:01 +02:00
|
|
|
'tabindex' => $this->getTabIndex()
|
2008-04-06 06:08:45 +02:00
|
|
|
);
|
|
|
|
|
2008-10-20 12:22:01 +02:00
|
|
|
if($this->disabled) $attributes['disabled'] = 'disabled';
|
|
|
|
|
2008-04-06 06:08:45 +02:00
|
|
|
return $this->createTag('input', $attributes);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-04-29 03:20:24 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Checkboxes use the RightLabelledFieldHolder template, to put the field on the left
|
|
|
|
* and the label on the right. See {@link FormField::FieldHolder} for more information about
|
|
|
|
* how FieldHolder works.
|
|
|
|
*/
|
|
|
|
function FieldHolder() {
|
|
|
|
if($this->labelLeft) {
|
|
|
|
return parent::FieldHolder();
|
|
|
|
} else {
|
2009-07-09 01:04:43 +02:00
|
|
|
extract($this->getXMLValues(array( 'Name', 'Field', 'Title', 'Message', 'MessageType' )),
|
|
|
|
EXTR_SKIP);
|
2007-07-19 12:40:28 +02:00
|
|
|
$messageBlock = isset($Message) ? "<span class=\"message $MessageType\">$Message</span>" : '';
|
|
|
|
$Type = $this->XML_val('Type');
|
2010-09-15 22:54:16 +02:00
|
|
|
$extraClass = $this->XML_val('extraClass');
|
2007-07-19 12:40:28 +02:00
|
|
|
return <<<HTML
|
2010-09-15 22:54:16 +02:00
|
|
|
<p id="$Name" class="field $Type $extraClass">
|
2007-07-19 12:40:28 +02:00
|
|
|
$Field
|
|
|
|
<label class="right" for="{$this->id()}">$Title</label>
|
|
|
|
$messageBlock
|
|
|
|
</p>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function useLabelLeft( $labelLeft = true ) {
|
|
|
|
$this->labelLeft = $labelLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
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-08-11 00:35:03 +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
|
|
|
|
|
|
|
/**
|
|
|
|
* Single checkbox field, disabled
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
|
|
|
*/
|
|
|
|
class CheckboxField_Disabled extends CheckboxField {
|
|
|
|
|
|
|
|
protected $disabled = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a single checkbox field - used by templates.
|
|
|
|
*/
|
|
|
|
function Field() {
|
|
|
|
$attributes = array(
|
|
|
|
'type' => 'checkbox',
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
|
2008-10-16 15:44:05 +02:00
|
|
|
'id' => $this->id(),
|
|
|
|
'name' => $this->Name(),
|
|
|
|
'tabindex' => $this->getTabIndex(),
|
|
|
|
'checked' => ($this->value) ? 'checked' : false,
|
|
|
|
'disabled' => 'disabled'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->createTag('input', $attributes);
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
?>
|