2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-04-17 04:26:40 +02:00
|
|
|
* EditableRadioField
|
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* Represents a set of selectable radio buttons
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-04-17 04:26:40 +02:00
|
|
|
class EditableRadioField extends EditableMultipleOptionField {
|
2008-09-29 05:18:23 +02:00
|
|
|
|
|
|
|
static $singular_name = 'Radio field';
|
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
static $plural_name = 'Radio fields';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
|
|
|
function DefaultOption() {
|
|
|
|
$defaultOption = 0;
|
|
|
|
|
|
|
|
foreach( $this->Options() as $option ) {
|
|
|
|
if( $option->getField('Default') )
|
|
|
|
return $defaultOption;
|
|
|
|
else
|
|
|
|
$defaultOption++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createField( $asFilter = false ) {
|
|
|
|
$optionSet = $this->Options();
|
|
|
|
$options = array();
|
|
|
|
$defaultOption = '';
|
|
|
|
|
|
|
|
if( $asFilter )
|
|
|
|
$options['-1'] = '(Any)';
|
|
|
|
|
|
|
|
// $defaultOption = '-1';
|
|
|
|
|
|
|
|
foreach( $optionSet as $option ) {
|
|
|
|
$options[$option->Title] = $option->Title;
|
|
|
|
if( $option->getField('Default') && !$asFilter ) $defaultOption = $option->Title;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return radiofields
|
|
|
|
return new OptionsetField($this->Name, $this->Title, $options, $defaultOption);
|
|
|
|
}
|
2009-04-17 04:26:40 +02:00
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
?>
|