PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
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.14, at app/Models/Form.php

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