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 / GlobalNotificationService.php

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

109 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\Services\Integrations;
4
5 use FluentForm\App\Models\EntryDetails;
6 use FluentForm\App\Models\FormMeta;
7 use FluentForm\App\Modules\Form\FormDataParser;
8 use FluentForm\App\Modules\Form\FormFieldsParser;
9 use FluentForm\App\Services\ConditionAssesor;
10 use FluentForm\Framework\Helpers\ArrayHelper;
11 use FluentForm\App\Models\Submission;
12
13
14 class GlobalNotificationService
15 {
16 public function checkCondition($parsedValue, $formData, $insertId)
17 {
18 $conditionSettings = ArrayHelper::get($parsedValue, 'conditionals');
19 if (
20 !$conditionSettings ||
21 !ArrayHelper::isTrue($conditionSettings, 'status')
22 ) {
23 return true;
24 }
25
26 return ConditionAssesor::evaluate($parsedValue, $formData);
27 }
28
29 public function getEntry($id, $form)
30 {
31 $submission = Submission::find($id);
32 $formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']);
33 return FormDataParser::parseFormEntry($submission, $form, $formInputs);
34 }
35
36 public function cleanUpPassword($insertId, $form)
37 {
38 // Let's get the password fields
39 $inputs = FormFieldsParser::getInputsByElementTypes($form, ['input_password']);
40
41 if (!$inputs) {
42 return;
43 }
44 $passwordKeys = array_keys($inputs);
45
46 // Let's delete from entry details
47 EntryDetails::where('form_id', $form->id)->where('field_name', $passwordKeys)->where('submission_id',
48 $insertId)->delete();
49 // Let's alter from main submission data
50 $submission = Submission::find($insertId);
51
52 if (!$submission) {
53 return;
54 }
55
56 $responseInputs = \json_decode($submission->response, true);
57
58 $replaced = false;
59 foreach ($passwordKeys as $passwordKey) {
60 if (!empty($responseInputs[$passwordKey])) {
61 $responseInputs[$passwordKey] = str_repeat('*', 6) . ' ' . __('(truncated)', 'fluentform');
62 $replaced = true;
63 }
64 }
65
66 if ($replaced) {
67 Submission::where('id', $insertId)->update(['response' => \json_encode($responseInputs)]);
68 }
69 }
70
71 /**
72 * @param $feeds
73 * @param $formData
74 * @param $insertId
75 *
76 * @return array
77 */
78 public function getEnabledFeeds($feeds, $formData, $insertId)
79 {
80 $enabledFeeds = [];
81 foreach ($feeds as $feed) {
82 $parsedValue = json_decode($feed->value, true);
83 if ($parsedValue && ArrayHelper::isTrue($parsedValue, 'enabled')) {
84 // Now check if conditions matched or not
85 $isConditionMatched = $this->checkCondition($parsedValue, $formData, $insertId);
86 if ($isConditionMatched) {
87 $item = [
88 'id' => $feed->id,
89 'meta_key' => $feed->meta_key,
90 'settings' => $parsedValue,
91 ];
92 if ('user_registration_feeds' == $feed->meta_key) {
93 array_unshift($enabledFeeds, $item);
94 } else {
95 $enabledFeeds[] = $item;
96 }
97 }
98 }
99 }
100 return $enabledFeeds;
101 }
102
103 public function getNotificationFeeds($form, $feedMetaKeys)
104 {
105 return FormMeta::where('form_id', $form->id)->whereIn('meta_key', $feedMetaKeys)->orderBy('id', 'ASC')->get();
106 }
107
108 }
109