PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.6
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.6
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 / Models / Form.php

Form.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.6, at app/Models/Form.php

289 lines 9.4 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\Models;
4
5 use FluentForm\App\Modules\Payments\PaymentHelper;
6 use FluentForm\Framework\Support\Arr;
7 use FluentForm\App\Models\Traits\PredefinedForms;
8
9 class Form extends Model
10 {
11 use PredefinedForms;
12
13 /**
14 * The table associated with the model.
15 *
16 * @var string
17 */
18 protected $table = 'fluentform_forms';
19
20 /**
21 * A form has many form meta.
22 *
23 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
24 */
25 public function formMeta()
26 {
27 return $this->hasMany(FormMeta::class, 'form_id', 'id');
28 }
29
30 /**
31 * A form may have one form meta to determine if
32 * the form is a regular or conversational one.
33 *
34 * @return \FluentForm\Framework\Database\Orm\Relations\HasOne
35 */
36 public function conversationalMeta()
37 {
38 return $this->hasOne(FormMeta::class, 'form_id', 'id')->where('meta_key', 'is_conversion_form');
39 }
40
41 /**
42 * A form has many submissions.
43 *
44 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
45 */
46 public function submissions()
47 {
48 return $this->hasMany(Submission::class, 'form_id', 'id');
49 }
50
51 /**
52 * A form has many submission meta.
53 *
54 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
55 */
56 public function submissionMeta()
57 {
58 return $this->hasMany(SubmissionMeta::class, 'form_id', 'id');
59 }
60
61 /**
62 * A form has many entry details.
63 *
64 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
65 */
66 public function entryDetails()
67 {
68 return $this->hasMany(EntryDetails::class, 'form_id', 'id');
69 }
70
71 /**
72 * A form has many form analytics.
73 *
74 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
75 */
76 public function formAnalytics()
77 {
78 return $this->hasMany(FormAnalytics::class, 'form_id', 'id');
79 }
80
81 /**
82 * A form has many logs.
83 *
84 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
85 */
86 public function logs()
87 {
88 return $this->hasMany(Log::class, 'parent_source_id', 'id');
89 }
90
91 /**
92 * A form has many transactions.
93 *
94 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
95 */
96 public function transactions()
97 {
98 return $this->hasMany(Transaction::class, 'form_id', 'id');
99 }
100
101 /**
102 * A form has many order items.
103 *
104 * @return \FluentForm\Framework\Database\Orm\Relations\HasMany
105 */
106 public function orderItems()
107 {
108 return $this->hasMany(OrderItem::class, 'form_id', 'id');
109 }
110
111 public static function prepare($attributes = [])
112 {
113 $now = current_time('mysql');
114
115 $data = [
116 'title' => Arr::get($attributes, 'title', 'My New Form'),
117 'status' => Arr::get($attributes, 'status', 'published'),
118 'appearance_settings' => Arr::get($attributes, 'appearance_settings'),
119 'form_fields' => Arr::get($attributes, 'form_fields'),
120 'has_payment' => Arr::get($attributes, 'has_payment', 0),
121 'type' => Arr::get($attributes, 'type', 'form'),
122 'conditions' => Arr::get($attributes, 'conditions'),
123 'created_by' => get_current_user_id(),
124 'created_at' => $now,
125 'updated_at' => $now,
126 ];
127
128 return apply_filters(
129 'fluentform/form_store_attributes',
130 array_filter($data)
131 );
132 }
133
134 public static function getFormMeta($metaKey, $formId = null)
135 {
136 return FormMeta::retrieve($metaKey, $formId);
137 }
138
139 public static function getFormsDefaultSettings($formId = false)
140 {
141 $defaultSettings = [
142 'confirmation' => [
143 'redirectTo' => 'samePage',
144 'messageToShow' => __('Thank you for your message. We will get in touch with you shortly', 'fluentform'),
145 'customPage' => null,
146 'samePageFormBehavior' => 'hide_form',
147 'customUrl' => null,
148 ],
149 'restrictions' => [
150 'limitNumberOfEntries' => [
151 'enabled' => false,
152 'numberOfEntries' => null,
153 'period' => 'total',
154 'limitReachedMsg' => __('Maximum number of entries exceeded.', 'fluentform'),
155 ],
156 'scheduleForm' => [
157 'enabled' => false,
158 'start' => null,
159 'end' => null,
160 'selectedDays' => null,
161 'pendingMsg' => __('Form submission is not started yet.', 'fluentform'),
162 'expiredMsg' => __('Form submission is now closed.', 'fluentform'),
163 ],
164 'requireLogin' => [
165 'enabled' => false,
166 'requireLoginMsg' => __('You must be logged in to submit the form.', 'fluentform'),
167 ],
168 'denyEmptySubmission' => [
169 'enabled' => false,
170 'message' => __('Sorry, you cannot submit an empty form. Let\'s hear what you wanna say.', 'fluentform'),
171 ],
172 'restrictForm' => [
173 'enabled' => false,
174 'fields' => [
175 'ip' => [
176 'status' => false,
177 'values' => '',
178 'message' => __('Sorry! You can\'t submit a form from your IP address.', 'fluentform'),
179 'validation_type' => 'fail_on_condition_met'
180 ],
181 'country' => [
182 'status' => false,
183 'values' => [],
184 'message' => __('Sorry! You can\'t submit a form the country you are residing.', 'fluentform'),
185 'validation_type' => 'fail_on_condition_met'
186 ],
187 'keywords' => [
188 'status' => false,
189 'values' => '',
190 'message' => __('Sorry! Your submission contains some restricted keywords.', 'fluentform')
191 ],
192 ]
193 ]
194 ],
195 'layout' => [
196 'labelPlacement' => 'top',
197 'helpMessagePlacement' => 'with_label',
198 'errorMessagePlacement' => 'inline',
199 'cssClassName' => '',
200 'asteriskPlacement' => 'asterisk-right',
201 ],
202 'delete_entry_on_submission' => 'no',
203 'conv_form_per_step_save' => false,
204 'conv_form_resume_from_last_step' => false
205 ];
206
207 if ($formId) {
208 $value = static::getFormMeta('formSettings', $formId);
209
210 if ($value) {
211 $defaultSettings = wp_parse_args($value, $defaultSettings);
212 }
213 } else {
214 $globalSettings = get_option('_fluentform_global_form_settings');
215
216 if (isset($globalSettings['layout'])) {
217 $defaultSettings['layout'] = $globalSettings['layout'];
218 }
219 }
220
221 $defaultSettings = apply_filters(
222 'fluentform/forms_default_settings',
223 $defaultSettings
224 );
225
226
227 return apply_filters(
228 'fluentform/create_default_settings',
229 $defaultSettings
230 );
231 }
232
233 public static function getAdvancedValidationSettings($formId)
234 {
235 $settings = [
236 'status' => false,
237 'type' => 'all',
238 'conditions' => [
239 [
240 'field' => '',
241 'operator' => '=',
242 'value' => '',
243 ],
244 ],
245 'error_message' => '',
246 'validation_type' => 'fail_on_condition_met',
247 ];
248
249 $metaSettings = static::getFormMeta('advancedValidationSettings', $formId);
250
251 if ($metaSettings && is_array($metaSettings)) {
252 $settings = wp_parse_args($metaSettings, $settings);
253 }
254
255 return apply_filters(
256 'fluentform/advanced_validation_settings',
257 $settings
258 );
259 }
260
261 public static function remove($formId)
262 {
263 do_action('fluentform/before_form_delete', $formId);
264
265 static::where('id', $formId)->delete();
266 Submission::where('form_id', $formId)->delete();
267 SubmissionMeta::where('form_id', $formId)->delete();
268 EntryDetails::where('form_id', $formId)->delete();
269 FormMeta::where('form_id', $formId)->delete();
270 FormAnalytics::where('form_id', $formId)->delete();
271 Log::where('parent_source_id', $formId)
272 ->whereIn('source_type', [
273 'submission_item', 'form_item', 'draft_submission_meta',
274 ])
275 ->delete();
276
277 if (PaymentHelper::hasPaymentSettings()) {
278 try {
279 OrderItem::where('form_id', $formId)->delete();
280 Transaction::where('form_id', $formId)->delete();
281 Subscription::where('form_id', $formId)->delete();
282 } catch (\Exception $e) {
283 }
284 }
285
286 do_action('fluentform/after_form_delete', $formId);
287 }
288 }
289