2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-04-17 04:26:40 +02:00
|
|
|
* EditableCheckboxGroup
|
|
|
|
*
|
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 EditableCheckboxGroupField extends EditableMultipleOptionField {
|
2008-09-29 05:18:23 +02:00
|
|
|
|
|
|
|
static $singular_name = "Checkbox group";
|
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
static $plural_name = "Checkbox groups";
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-28 06:59:23 +01:00
|
|
|
function createField($asFilter = false) {
|
2008-09-29 05:18:23 +02:00
|
|
|
$optionSet = $this->Options();
|
|
|
|
$options = array();
|
|
|
|
|
2009-01-28 06:59:23 +01:00
|
|
|
$optionMap = ($optionSet) ? $optionSet->map('ID', 'Title') : array();
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2009-01-28 06:59:23 +01:00
|
|
|
return new CheckboxSetField($this->Name, $this->Title, $optionMap);
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getValueFromData($data) {
|
|
|
|
if(empty($data[$this->Name])) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-01-28 06:59:23 +01:00
|
|
|
$result = '';
|
2008-09-29 05:18:23 +02:00
|
|
|
$entries = $data[$this->Name];
|
|
|
|
|
|
|
|
if(!is_array($data[$this->Name])) {
|
|
|
|
$entries = array($data[$this->Name]);
|
|
|
|
}
|
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
$selectedOptions = DataObject::get('EditableOption', "ParentID={$this->ID} AND ID IN (" . implode(',', $entries) . ")");
|
2008-09-29 05:18:23 +02:00
|
|
|
foreach($selectedOptions as $selected) {
|
|
|
|
if(!$result) {
|
|
|
|
$result = $selected->Title;
|
|
|
|
} else {
|
|
|
|
$result .= "," . $selected->Title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|