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-12-07 03:04:20 +01:00
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = "Checkbox Group";
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $plural_name = "Checkbox Groups";
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getFormField() {
|
2015-08-10 07:03:36 +02:00
|
|
|
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
2013-05-08 09:08:21 +02:00
|
|
|
|
2015-07-24 04:37:48 +02:00
|
|
|
// Set the default checked items
|
2015-08-10 07:03:36 +02:00
|
|
|
$defaultCheckedItems = $this->getDefaultOptions();
|
2015-07-24 04:37:48 +02:00
|
|
|
if ($defaultCheckedItems->count()) {
|
|
|
|
$field->setDefaultItems($defaultCheckedItems->map('EscapedTitle')->keys());
|
|
|
|
}
|
|
|
|
|
2015-08-10 07:03:36 +02:00
|
|
|
$this->doUpdateFormField($field);
|
2015-07-24 04:37:48 +02:00
|
|
|
return $field;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getValueFromData($data) {
|
2009-01-28 06:59:23 +01:00
|
|
|
$result = '';
|
2009-04-28 04:03:13 +02:00
|
|
|
$entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2009-04-27 08:00:05 +02:00
|
|
|
if($entries) {
|
2009-04-28 04:03:13 +02:00
|
|
|
if(!is_array($data[$this->Name])) {
|
|
|
|
$entries = array($data[$this->Name]);
|
|
|
|
}
|
2009-04-27 08:00:05 +02:00
|
|
|
foreach($entries as $selected => $value) {
|
|
|
|
if(!$result) {
|
|
|
|
$result = $value;
|
|
|
|
} else {
|
|
|
|
$result .= ", " . $value;
|
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2013-05-08 09:08:21 +02:00
|
|
|
}
|