PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.6
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.6
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.6, at app/Api/FormProperties.php

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