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 / Theme / 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/Theme/Fields/RatingField.php

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