PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.19
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.19
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 3.6.66 All 195 releases
fluentform / app / Api / FormProperties.php

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

168 lines 3.6 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 * @throws \WpFluent\Exception
66 */
67 public function emailNotifications()
68 {
69 $emailNotifications = wpFluent()
70 ->table('fluentform_form_meta')
71 ->where('form_id', $this->form->id)
72 ->where('meta_key', 'notifications')
73 ->get();
74
75 $formattedNotifications = [];
76
77 foreach ($emailNotifications as $notification) {
78 $value = \json_decode($notification->value, true);
79 $formattedNotifications[] = [
80 'id' => $notification->id,
81 'settings' => $value,
82 ];
83 }
84
85 return $formattedNotifications;
86 }
87
88 /**
89 * Get Form metas
90 *
91 * @param $metaName
92 * @param false $default
93 *
94 * @return mixed|string
95 */
96 public function meta($metaName, $default = false)
97 {
98 return Helper::getFormMeta($this->form->id, $metaName, $default);
99 }
100
101 /**
102 * Get form renerable pass settings as an array
103 *
104 * @return array
105 */
106 public function renderable()
107 {
108 return apply_filters('fluentform_is_form_renderable', [
109 'status' => true,
110 'message' => '',
111 ], $this->form);
112 }
113
114 public function conversionRate()
115 {
116 if (!$this->form->total_Submissions) {
117 return 0;
118 }
119
120 if (!$this->form->total_views) {
121 return 0;
122 }
123
124 return ceil(($this->form->total_Submissions / $this->form->total_views) * 100);
125 }
126
127 public function submissionCount()
128 {
129 return wpFluent()
130 ->table('fluentform_submissions')
131 ->where('form_id', $this->form->id)
132 ->where('status', '!=', 'trashed')
133 ->count();
134 }
135
136 public function viewCount()
137 {
138 $hasCount = wpFluent()
139 ->table('fluentform_form_meta')
140 ->where('meta_key', '_total_views')
141 ->where('form_id', $this->form->id)
142 ->first();
143
144 if ($hasCount) {
145 return intval($hasCount->value);
146 }
147
148 return 0;
149 }
150
151 public function unreadCount()
152 {
153 return wpFluent()->table('fluentform_submissions')
154 ->where('status', 'unread')
155 ->where('form_id', $this->form->id)
156 ->count();
157 }
158
159 public function __get($name)
160 {
161 if (property_exists($this->form, $name)) {
162 return $this->form->{$name};
163 }
164
165 return false;
166 }
167 }
168