silverstripe-userforms/code/editor/EditableCheckboxGroupField.php
2009-04-28 02:03:13 +00:00

44 lines
917 B
PHP
Executable File

<?php
/**
* EditableCheckboxGroup
*
* Represents a set of selectable radio buttons
*
* @package userforms
*/
class EditableCheckboxGroupField extends EditableMultipleOptionField {
static $singular_name = "Checkbox group";
static $plural_name = "Checkbox groups";
function getFormField() {
$optionSet = $this->Options();
$options = array();
$optionMap = ($optionSet) ? $optionSet->map('Title', 'Title') : array();
return new CheckboxSetField($this->Name, $this->Title, $optionMap);
}
function getValueFromData($data) {
$result = '';
$entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
if($entries) {
if(!is_array($data[$this->Name])) {
$entries = array($data[$this->Name]);
}
foreach($entries as $selected => $value) {
if(!$result) {
$result = $value;
} else {
$result .= ", " . $value;
}
}
}
return $result;
}
}
?>