PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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 2.21.13, at includes/Frontend/Form/View/Theme/Fields/RatingField.php

153 lines 4.3 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 $val,
109 $lbl,
110 $checked,
111 $req,
112 $fieldHelpers->getCustomAttributes('rating-input'),
113 $fieldHelpers->getAtomicCls('rating-img'),
114 $fieldHelpers->getCustomClasses('rating-img'),
115 $checkedCls,
116 $img,
117 $fieldHelpers->getCustomAttributes('rating-img')
118 );
119 }
120 }
121
122 return sprintf(
123 '<div
124 %1$s
125 class="%2$s %3$s"
126 >
127 <div
128 %4$s
129 class="%5$s %6$s"
130 tabindex="0"
131 >
132 %7$s
133 </div>
134 <span
135 class="%8$s %9$s"
136 %10$s
137 >
138 </span>
139 </div>',
140 $fieldHelpers->getCustomAttributes('inp-fld-wrp'),
141 $fieldHelpers->getAtomicCls('inp-fld-wrp'),
142 $fieldHelpers->getCustomClasses('inp-fld-wrp'),
143 $fieldHelpers->getCustomAttributes('rating-wrp'),
144 $fieldHelpers->getAtomicCls('rating-wrp'),
145 $fieldHelpers->getCustomClasses('rating-wrp'),
146 $ratingOption,
147 $fieldHelpers->getAtomicCls('rating-msg'),
148 $fieldHelpers->getCustomClasses('rating-msg'),
149 $fieldHelpers->getCustomAttributes('rating-msg')
150 );
151 }
152 }
153