PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.19
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.19
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 / Entry.php

Entry.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.19, at app/Api/Entry.php

137 lines 4.1 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\Modules\Entries\Report;
6 use FluentForm\App\Modules\Form\FormDataParser;
7 use FluentForm\App\Modules\Form\FormFieldsParser;
8
9 class Entry
10 {
11 private $form;
12
13 public function __construct($form)
14 {
15 $this->form = $form;
16 }
17
18 public function entries($atts = [], $includeFormats = false)
19 {
20 if ($includeFormats) {
21 if (!defined('FLUENTFORM_RENDERING_ENTRIES')) {
22 define('FLUENTFORM_RENDERING_ENTRIES', true);
23 }
24 }
25
26 $atts = wp_parse_args($atts, [
27 'per_page' => 10,
28 'page' => 1,
29 'search' => '',
30 'sort_type' => 'DESC',
31 'entry_type' => 'all',
32 ]);
33
34 $offset = $atts['per_page'] * ($atts['page'] - 1);
35
36 $entryQuery = wpFluent()->table('fluentform_submissions')
37 ->where('form_id', $this->form->id)
38 ->orderBy('id', $atts['sort_type'])
39 ->limit($atts['per_page'])
40 ->offset($offset);
41
42 $type = $atts['entry_type'];
43
44 if ($type && 'all' != $type) {
45 $entryQuery->where('status', $type);
46 }
47
48 if ($searchString = $atts['search']) {
49 $entryQuery->where(function ($q) use ($searchString) {
50 $q->where('id', 'LIKE', "%{$searchString}%")
51 ->orWhere('response', 'LIKE', "%{$searchString}%")
52 ->orWhere('status', 'LIKE', "%{$searchString}%")
53 ->orWhere('created_at', 'LIKE', "%{$searchString}%");
54 });
55 }
56
57 $count = $entryQuery->count();
58
59 $data = $entryQuery->get();
60
61 $dataCount = count($data);
62
63 $from = $dataCount > 0 ? ($atts['page'] - 1) * $atts['per_page'] + 1 : null;
64
65 $to = $dataCount > 0 ? $from + $dataCount - 1 : null;
66 $lastPage = (int) ceil($count / $atts['per_page']);
67
68 if ($includeFormats) {
69 $data = FormDataParser::parseFormEntries($data, $this->form);
70 }
71
72 foreach ($data as $datum) {
73 $datum->response = json_decode($datum->response, true);
74 }
75
76 return [
77 'current_page' => $atts['page'],
78 'per_page' => $atts['per_page'],
79 'from' => $from,
80 'to' => $to,
81 'last_page' => $lastPage,
82 'total' => $count,
83 'data' => $data,
84 ];
85 }
86
87 public function entry($entryId, $includeFormats = false)
88 {
89 $submission = wpFluent()->table('fluentform_submissions')
90 ->where('form_id', $this->form->id)
91 ->where('id', $entryId)
92 ->first();
93
94 if (!$submission) {
95 return null;
96 }
97
98 $inputs = FormFieldsParser::getEntryInputs($this->form);
99 $submission = FormDataParser::parseFormEntry($submission, $this->form, $inputs, true);
100
101 if (!$includeFormats) {
102 $submission->response = json_decode($submission->response, true);
103 return [
104 'submission' => $submission,
105 ];
106 }
107
108 if ($submission->user_id) {
109 $user = get_user_by('ID', $submission->user_id);
110 $user_data = [
111 'name' => $user->display_name,
112 'email' => $user->user_email,
113 'ID' => $user->ID,
114 'permalink' => get_edit_user_link($user->ID),
115 ];
116 $submission->user = $user_data;
117 }
118
119 $submission = apply_filters('fluentform_single_response_data', $submission, $this->form->id);
120
121 $submission->response = json_decode($submission->response);
122
123 $inputLabels = FormFieldsParser::getAdminLabels($this->form, $inputs);
124
125 return [
126 'submission' => $submission,
127 'labels' => $inputLabels,
128 ];
129 }
130
131 public function report($statuses = [])
132 {
133 $reportClass = new Report(wpFluentForm());
134 return $reportClass->generateReport($this->form, $statuses);
135 }
136 }
137