These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * EditableCheckboxGroup |
||
4 | * |
||
5 | * Represents a set of selectable radio buttons |
||
6 | * |
||
7 | * @package userforms |
||
8 | */ |
||
9 | |||
10 | class EditableCheckboxGroupField extends EditableMultipleOptionField |
||
11 | { |
||
12 | |||
13 | private static $singular_name = "Checkbox Group"; |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
14 | |||
15 | private static $plural_name = "Checkbox Groups"; |
||
0 ignored issues
–
show
|
|||
16 | |||
17 | protected $jsEventHandler = 'click'; |
||
18 | |||
19 | public function getFormField() |
||
20 | { |
||
21 | $field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap()); |
||
22 | $field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder'); |
||
23 | |||
24 | // Set the default checked items |
||
25 | $defaultCheckedItems = $this->getDefaultOptions(); |
||
26 | if ($defaultCheckedItems->count()) { |
||
27 | $field->setDefaultItems($defaultCheckedItems->map('Value')->keys()); |
||
28 | } |
||
29 | |||
30 | $this->doUpdateFormField($field); |
||
31 | return $field; |
||
32 | } |
||
33 | |||
34 | public function getValueFromData($data) |
||
35 | { |
||
36 | $result = ''; |
||
37 | $entries = (isset($data[$this->Name])) ? $data[$this->Name] : false; |
||
38 | |||
39 | if ($entries) { |
||
40 | if (!is_array($data[$this->Name])) { |
||
41 | $entries = array($data[$this->Name]); |
||
42 | } |
||
43 | foreach ($entries as $selected => $value) { |
||
44 | if (!$result) { |
||
45 | $result = $value; |
||
46 | } else { |
||
47 | $result .= ", " . $value; |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | return $result; |
||
52 | } |
||
53 | |||
54 | public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) |
||
55 | { |
||
56 | // watch out for checkboxs as the inputs don't have values but are 'checked |
||
57 | // @todo - Test this |
||
58 | if ($rule->FieldValue) { |
||
59 | return "$(\"input[name='{$this->Name}[]'][value='{$rule->FieldValue}']\")"; |
||
60 | } else { |
||
61 | return "$(\"input[name='{$this->Name}[]']:first\")"; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | public function isCheckBoxField() { |
||
66 | return true; |
||
67 | } |
||
68 | |||
69 | public function getSelectorFieldOnly() |
||
70 | { |
||
71 | return "[name='{$this->Name}[]']"; |
||
72 | } |
||
73 | |||
74 | public function isCheckBoxGroupField() |
||
75 | { |
||
76 | return true; |
||
77 | } |
||
78 | } |
||
79 |