mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
62 lines
1.2 KiB
PHP
Executable File
62 lines
1.2 KiB
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 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();
|
|
|
|
$optionMap = ($optionSet) ? $optionSet->map('ID', 'Title') : array();
|
|
|
|
return new CheckboxSetField($this->Name, $this->Title, $optionMap);
|
|
}
|
|
|
|
function getValueFromData($data) {
|
|
if(empty($data[$this->Name])) {
|
|
return "";
|
|
}
|
|
|
|
$result = '';
|
|
$entries = $data[$this->Name];
|
|
|
|
if(!is_array($data[$this->Name])) {
|
|
$entries = array($data[$this->Name]);
|
|
}
|
|
|
|
$selectedOptions = DataObject::get('EditableOption', "ParentID={$this->ID} AND ID IN (" . implode(',', $entries) . ")");
|
|
foreach($selectedOptions as $selected) {
|
|
if(!$result) {
|
|
$result = $selected->Title;
|
|
} else {
|
|
$result .= "," . $selected->Title;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
?>
|