PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.9
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.9
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 / Api / FormProperties.php

FormProperties.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.9, at app/Api/FormProperties.php

166 lines 3.7 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\Api;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\App\Modules\Form\FormFieldsParser;
7
8 class FormProperties
9 {
10 private $form;
11
12 public function __construct($form)
13 {
14 $this->form = $form;
15 }
16
17 /**
18 * Get Form formatted inputs
19 *
20 * @param string[] $with
21 *
22 * @return array
23 */
24 public function inputs($with = ['admin_label', 'raw'])
25 {
26 return FormFieldsParser::getEntryInputs($this->form, $with);
27 }
28
29 /**
30 * Get Form Input labels
31 *
32 * @return array
33 */
34 public function labels()
35 {
36 $inputs = $this->inputs();
37 return FormFieldsParser::getAdminLabels($this->form, $inputs);
38 }
39
40 /**
41 * Get Form Fields
42 *
43 * @return array
44 */
45 public function fields()
46 {
47 return json_decode($this->form->form_fields, true);
48 }
49
50 /**
51 * Get Form Settings
52 *
53 * @return array
54 */
55 public function settings()
56 {
57 return (array) Helper::getFormMeta($this->form->id, 'formSettings', []);
58 }
59
60 /**
61 * Get Email Notifications as an array
62 *
63 * @return array
64 */
65 public function emailNotifications()
66 {
67 $emailNotifications = wpFluent()
68 ->table('fluentform_form_meta')
69 ->where('form_id', $this->form->id)
70 ->where('meta_key', 'notifications')
71 ->get();
72
73 $formattedNotifications = [];
74
75 foreach ($emailNotifications as $notification) {
76 $value = \json_decode($notification->value, true);
77 $formattedNotifications[] = [
78 'id' => $notification->id,
79 'settings' => $value,
80 ];
81 }
82
83 return $formattedNotifications;
84 }
85
86 /**
87 * Get Form metas
88 *
89 * @param $metaName
90 * @param false $default
91 *
92 * @return mixed|string
93 */
94 public function meta($metaName, $default = false)
95 {
96 return Helper::getFormMeta($this->form->id, $metaName, $default);
97 }
98
99 /**
100 * Get form renerable pass settings as an array
101 *
102 * @return array
103 */
104 public function renderable()
105 {
106 $isRenderable = [
107 'status' => true,
108 'message' => '',
109 ];
110 /* This filter is deprecated and will be removed soon */
111 $isRenderable = apply_filters('fluentform_is_form_renderable', $isRenderable, $this->form);
112
113 return apply_filters('fluentform/is_form_renderable', $isRenderable, $this->form);
114 }
115
116 public function conversionRate()
117 {
118 if (!$this->form->total_Submissions) {
119 return 0;
120 }
121
122 if (!$this->form->total_views) {
123 return 0;
124 }
125
126 return ceil(($this->form->total_Submissions / $this->form->total_views) * 100);
127 }
128
129 public function submissionCount()
130 {
131 return wpFluent()
132 ->table('fluentform_submissions')
133 ->where('form_id', $this->form->id)
134 ->where('status', '!=', 'trashed')
135 ->count();
136 }
137
138 public function viewCount()
139 {
140 $hasCount = wpFluent()
141 ->table('fluentform_form_meta')
142 ->where('meta_key', '_total_views')
143 ->where('form_id', $this->form->id)
144 ->first();
145
146 if ($hasCount) {
147 return intval($hasCount->value);
148 }
149
150 return 0;
151 }
152
153 public function unreadCount()
154 {
155 return wpFluent()->table('fluentform_submissions')
156 ->where('status', 'unread')
157 ->where('form_id', $this->form->id)
158 ->count();
159 }
160
161 public function __get($name)
162 {
163 return $this->form->{$name} ?? null;
164 }
165 }
166