PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.18
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.18
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / FormBuilder / Components / Rating.php

Rating.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.18, at app/Services/FormBuilder/Components/Rating.php

63 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\FormBuilder\Components;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\Framework\Helpers\ArrayHelper;
7
8 class Rating extends BaseComponent
9 {
10 /**
11 * Compile and echo the html element
12 *
13 * @param array $data [element data]
14 * @param \stdClass $form [Form Object]
15 *
16 * @return void
17 */
18 public function compile($data, $form)
19 {
20 $elementName = $data['element'];
21 $data = apply_filters('fluentform_rendering_field_data_' . $elementName, $data, $form);
22
23 $data['attributes']['type'] = 'radio';
24
25 $defaultValues = (array) $this->extractValueFromAttributes($data);
26
27 $elMarkup = "<div class='ff-el-ratings jss-ff-el-ratings'>";
28 $ratingText = '';
29
30 foreach ($data['options'] as $value => $label) {
31 $starred = '';
32 if (in_array($value, $defaultValues)) {
33 $data['attributes']['checked'] = true;
34 $starred = 'active';
35 } else {
36 $data['attributes']['checked'] = false;
37 }
38
39 if ($tabIndex = Helper::getNextTabIndex()) {
40 $data['attributes']['tabindex'] = $tabIndex;
41 }
42
43 $atts = $this->buildAttributes($data['attributes']);
44 $id = esc_attr($this->getUniqueid(str_replace(['[', ']'], ['', ''], $data['attributes']['name'])));
45
46 $elMarkup .= "<label class='{$starred}'><input {$atts} id={$id} value='{" . esc_attr($value) . "}'>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $starred, $atts, $id are escaped before being passed in.
47 $elMarkup .= '<?xml version="1.0" encoding="iso-8859-1"?><svg class="jss-ff-svg ff-svg" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 53.867 53.867" style="enable-background:new 0 0 53.867 53.867;" xml:space="preserve"><polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g></svg>';
48 $elMarkup .= '</label>';
49
50 if ('yes' == ArrayHelper::get($data, 'settings.show_text')) {
51 $displayDefaultText = in_array($value, $defaultValues) ? 'display: inline-block' : 'display: none';
52 $ratingText .= "<span style='{$displayDefaultText}' class='ff-el-rating-text' data-id='{$id}'>" . fluentform_sanitize_html($label, false) . '</span>';
53 }
54 };
55
56 $elMarkup .= '</div>' . $ratingText;
57
58 $html = $this->buildElementMarkup($elMarkup, $data, $form);
59
60 $this->printContent('fluentform_rendering_field_html_' . $elementName, $html, $data, $form);
61 }
62 }
63