PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.1
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Frontend / Form / View / Conversational / Fields / RatingField.php

RatingField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.1.1, at includes/Frontend/Form/View/Conversational/Fields/RatingField.php

160 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend\Form\View\Conversational\Fields;
4
5 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class RatingField
8 {
9 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
10 {
11 $inputWrapper = new ConversationalInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
12 $input = self::field($field, $rowID, $form_atomic_Cls_map, $formID, $value);
13 return $inputWrapper->wrapper($input);
14 }
15
16 private static function field($field, $rowID, $form_atomic_Cls_map, $formID, $value)
17 {
18 $fieldHelpers = new ConversationalFieldHelpers($formID, $field, $rowID, $form_atomic_Cls_map);
19
20 $name = $fieldHelpers->name();
21 $req = $fieldHelpers->required();
22 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
23 $ariaRequired = $fieldHelpers->ariaRequired();
24 $labelId = $fieldHelpers->getLabelId();
25
26 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
27 $contentCount = count($bfFrontendFormIds);
28
29 $ratingOption = '';
30
31 $checkedIndex = '';
32
33 if (isset($field->opt)) {
34 $defaultValue = isset($field->val) ? $field->val : '';
35 foreach ($field->opt as $key => $opt) {
36 if ($defaultValue && $defaultValue === $opt->val) {
37 $checkedIndex = $key;
38 } elseif (isset($opt->check) && true === $opt->check) {
39 $checkedIndex = $key;
40 }
41 }
42
43 $checkedCls = null;
44
45 foreach ($field->opt as $key => $opt) {
46 $val = $opt->val;
47 $img = $opt->img;
48 $lbl = $opt->lbl;
49 $checked = '';
50
51 // if ($defaultValue && $opt->val === $defaultValue) {
52 // $checked = "checked='checked'";
53 // } elseif (isset($opt->check) && true === $opt->check) {
54 // $checked = "checked='{$opt->check}'";
55 // } else {
56 // $checked = '';
57 // }
58
59 if ($defaultValue) {
60 if ($opt->val === $defaultValue) {
61 $checked = "checked='1'";
62 }
63 } else {
64 if (isset($opt->check) && true === $opt->check) {
65 $checked = "checked='{$opt->check}'";
66 } else {
67 $checked = '';
68 }
69 }
70
71 if (!empty($checkedIndex) && $key <= $checkedIndex) {
72 $checkedCls = $rowID . '-rating-selected';
73 } else {
74 $checkedCls = null;
75 }
76 // sprintf args order:
77 // 1: label class, 2: rowID, 3: contentCount, 4: key, 5: label attrs
78 // 6: input class, 7: name attr, 8: value, 9: label text, 10: checked, 11: required, 12: input attrs
79 // 13: img class, 14: img src, 15: img attrs
80 $ratingOption .= sprintf(
81 '<label
82 class="%1$s"
83 for="%2$s-%3$s-rating-%4$s"
84 %5$s
85 data-indx="%4$s"
86 >
87 <input
88 type="radio"
89 class="%6$s"
90 %7$s
91 value="%8$s"
92 aria-label="%9$s"
93 id="%2$s-%3$s-rating-%4$s"
94 %10$s
95 %11$s
96 %12$s
97 />
98 <img
99 class="%13$s"
100 src="%14$s"
101 alt="%9$s"
102 aria-label="%9$s"
103 %15$s
104 />
105 </label>
106 ',
107 $fieldHelpers->getConversationalMultiCls('rating-lbl') . ' ' . $fieldHelpers->getCustomClasses('rating-lbl'),
108 $rowID,
109 $contentCount,
110 $key,
111 $fieldHelpers->getCustomAttributes('rating-lbl'),
112 $fieldHelpers->getConversationalMultiCls('rating-input') . ' ' . $fieldHelpers->getCustomClasses('rating-input'),
113 $name,
114 $val,
115 $lbl,
116 $checked,
117 $req,
118 $fieldHelpers->getCustomAttributes('rating-input'),
119 $fieldHelpers->getConversationalMultiCls('rating-img') . ' ' . $fieldHelpers->getCustomClasses('rating-img') . ' ' . $checkedCls,
120 $img,
121 $fieldHelpers->getCustomAttributes('rating-img')
122 );
123 }
124 }
125
126 return sprintf(
127 '
128 <div
129 %1$s
130 class="%2$s"
131 >
132 <div
133 %3$s
134 class="%4$s"
135 role="radiogroup"
136 aria-labelledby="%5$s"
137 %6$s
138 tabindex="-1"
139 >
140 %7$s
141 </div>
142 <span
143 class="%8$s"
144 %9$s
145 >
146 </span>
147 </div>',
148 $fieldHelpers->getCustomAttributes('inp-fld-wrp'),
149 $fieldHelpers->getConversationalMultiCls('inp-fld-wrp') . ' ' . $fieldHelpers->getCustomClasses('inp-fld-wrp'),
150 $fieldHelpers->getCustomAttributes('rating-wrp'),
151 $fieldHelpers->getConversationalMultiCls('rating-wrp') . ' ' . $fieldHelpers->getCustomClasses('rating-wrp'),
152 $labelId,
153 $ariaDescribedBy,
154 $ratingOption,
155 $fieldHelpers->getConversationalMultiCls('rating-msg') . ' ' . $fieldHelpers->getCustomClasses('rating-msg'),
156 $fieldHelpers->getCustomAttributes('rating-msg')
157 );
158 }
159 }
160