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 / Services / Integrations / BaseIntegration.php

BaseIntegration.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.14, at app/Services/Integrations/BaseIntegration.php

135 lines 3.9 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\Services\Integrations;
4
5 /**
6 * @deprecated deprecated use FluentForm\App\Http\Controllers\IntegrationManagerHelper;
7 */
8
9
10 class BaseIntegration
11 {
12 private $setting_key = '';
13 private $isMultiple = false;
14 private $formId = false;
15 private $isJsonValue = true;
16
17 public function __construct($settings_key = '', $form_id = false, $isMultiple = false)
18 {
19 $this->setting_key = $settings_key;
20 $this->isMultiple = $isMultiple;
21 $this->formId = $form_id;
22 }
23
24 public function setSettingsKey($key)
25 {
26 $this->setting_key = $key;
27 }
28
29 public function setIsMultiple($isMultiple)
30 {
31 $this->isMultiple = $isMultiple;
32 }
33
34 public function setFormId($formId)
35 {
36 $this->formId = $formId;
37 }
38
39 public function setJasonType($type)
40 {
41 $this->isJsonValue = $type;
42 }
43
44 public function save($settings)
45 {
46 return wpFluent()->table('fluentform_form_meta')
47 ->insertGetId([
48 'meta_key' => $this->setting_key,
49 'form_id' => $this->formId,
50 'value' => json_encode($settings),
51 ]);
52 }
53
54 public function update($settingsId, $settings)
55 {
56 return wpFluent()->table('fluentform_form_meta')
57 ->where('id', $settingsId)
58 ->update([
59 'value' => json_encode($settings),
60 ]);
61 }
62
63 public function get($settingsId)
64 {
65 $settings = wpFluent()->table('fluentform_form_meta')
66 ->where('form_id', $this->formId)
67 ->where('meta_key', $this->setting_key)
68 ->find($settingsId);
69 $settings->formattedValue = $this->getFormattedValue($settings);
70 return $settings;
71 }
72
73 public function getAll()
74 {
75 $settingsQuery = wpFluent()->table('fluentform_form_meta')
76 ->where('form_id', $this->formId)
77 ->where('meta_key', $this->setting_key);
78
79 if ($this->isMultiple) {
80 $settings = $settingsQuery->get();
81 foreach ($settings as $setting) {
82 $setting->formattedValue = $this->getFormattedValue($setting);
83 }
84 } else {
85 $settings = $settingsQuery->first();
86 $settings->formattedValue = $this->getFormattedValue($settings);
87 }
88 return $settings;
89 }
90
91 public function delete($settingsId)
92 {
93 return wpFluent()->table('fluentform_form_meta')
94 ->where('meta_key', $this->setting_key)
95 ->where('form_id', $this->formId)
96 ->where('id', $settingsId)
97 ->delete();
98 }
99
100 protected function validate($notification)
101 {
102 $validate = fluentValidator($notification, [
103 'name' => 'required',
104 'list_id' => 'required',
105 'fieldEmailAddress' => 'required',
106 ], [
107 'name.required' => __('Feed Name is required', 'fluentform'),
108 'list.required' => __(' List is required', 'fluentform'),
109 'fieldEmailAddress.required' => __('Email Address is required', 'fluentform')
110 ])->validate();
111
112 if ($validate->fails()) {
113 wp_send_json_error([
114 'errors' => $validate->errors(),
115 'message' => __('Please fix the errors', 'fluentform'),
116 ], 400);
117 }
118 return true;
119 }
120
121 private function getFormattedValue($setting)
122 {
123 if ($this->isJsonValue) {
124 return json_decode($setting->value, true);
125 }
126
127 return $setting->value;
128 }
129
130 public function deleteAll()
131 {
132 // ...
133 }
134 }
135