PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.7
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.7
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 / Http / Controllers / ReportController.php

ReportController.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.7, at app/Http/Controllers/ReportController.php

288 lines 7.8 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\Http\Controllers;
4
5 use Exception;
6 use FluentForm\App\Modules\Acl\Acl;
7 use FluentForm\App\Services\Report\ReportService;
8
9 class ReportController extends Controller
10 {
11 private function sanitizeReportAttributes($formId = null)
12 {
13 $sanitizeMap = [
14 'period' => 'sanitize_text_field',
15 'group_by' => 'sanitize_text_field',
16 'status' => 'sanitize_text_field',
17 ];
18
19 $attributes = fluentform_backend_sanitizer($this->request->all(), $sanitizeMap);
20 $requestFormId = $this->request->get('form_id');
21
22 if (isset($attributes['date_range']) && is_array($attributes['date_range'])) {
23 $attributes['date_range'] = array_map('sanitize_text_field', $attributes['date_range']);
24 }
25
26 $resolvedFormId = Acl::normalizeFormId($formId);
27
28 if (!$resolvedFormId) {
29 $resolvedFormId = Acl::normalizeFormId($requestFormId);
30 }
31
32 if ($resolvedFormId) {
33 $attributes['form_id'] = $resolvedFormId;
34 } else {
35 unset($attributes['form_id']);
36 }
37
38 return $attributes;
39 }
40
41 public function form(ReportService $reportService, $formId)
42 {
43 try {
44 return $this->sendSuccess(
45 $reportService->form($this->sanitizeReportAttributes($formId))
46 );
47 } catch (Exception $e) {
48 return $this->sendError([
49 'message' => $e->getMessage(),
50 ]);
51 }
52 }
53
54 /**
55 * Get Submission Report
56 * @return \WP_REST_Response
57 */
58 public function submissions(ReportService $reportService)
59 {
60 try {
61 return $this->sendSuccess(
62 $reportService->submissions($this->sanitizeReportAttributes())
63 );
64 } catch (Exception $e) {
65 return $this->sendError([
66 'message' => $e->getMessage(),
67 ]);
68 }
69 }
70
71
72 /**
73 * Get Forms for Dropdown
74 * @return \WP_REST_Response
75 */
76 public function getFormsDropdown(ReportService $reportService)
77 {
78 try {
79 return $this->sendSuccess(
80 $reportService->getFormsDropdown()
81 );
82 } catch (Exception $e) {
83 return $this->sendError([
84 'message' => $e->getMessage(),
85 ]);
86 }
87 }
88
89 /**
90 * Get payment revenue grouped by different criteria
91 * @return \WP_REST_Response
92 */
93 public function netRevenue(ReportService $reportService)
94 {
95 try {
96 $data = apply_filters('fluentform/reports/revenue_analysis', [], $this->sanitizeReportAttributes());
97 return $this->sendSuccess($data);
98
99 } catch (Exception $e) {
100 return $this->sendError([
101 'message' => $e->getMessage(),
102 ]);
103 }
104 }
105
106 /**
107 * Get submission analysis grouped by different criteria
108 * @return \WP_REST_Response
109 */
110 public function submissionsAnalysis()
111 {
112 try {
113 $data = apply_filters('fluentform/reports/submissions_analysis', [], $this->sanitizeReportAttributes());
114 return $this->sendSuccess($data);
115 } catch (Exception $e) {
116 return $this->sendError([
117 'message' => $e->getMessage(),
118 ]);
119 }
120 }
121
122 /**
123 * Get Overview Chart Data
124 * @return \WP_REST_Response
125 */
126 public function getOverviewChart(ReportService $reportService)
127 {
128 try {
129 return $this->sendSuccess(
130 $reportService->getOverviewChart($this->sanitizeReportAttributes())
131 );
132 } catch (Exception $e) {
133 return $this->sendError([
134 'message' => $e->getMessage(),
135 ]);
136 }
137 }
138
139 /**
140 * Get Revenue Chart Data
141 * @return \WP_REST_Response
142 */
143 public function getRevenueChart(ReportService $reportService)
144 {
145 try {
146 return $this->sendSuccess(
147 $reportService->getRevenueChart($this->sanitizeReportAttributes())
148 );
149 } catch (Exception $e) {
150 return $this->sendError([
151 'message' => $e->getMessage(),
152 ]);
153 }
154 }
155
156 /**
157 * Get Completion Rate Data
158 * @return \WP_REST_Response
159 */
160 public function getCompletionRate()
161 {
162 try {
163 $data = apply_filters('fluentform/reports/completion_rate', [], $this->sanitizeReportAttributes());
164 return $this->sendSuccess($data);
165 } catch (Exception $e) {
166 return $this->sendError([
167 'message' => $e->getMessage(),
168 ]);
169 }
170 }
171
172 /**
173 * Get Form Stats Data
174 * @return \WP_REST_Response
175 */
176 public function getFormStats(ReportService $reportService)
177 {
178 try {
179 return $this->sendSuccess(
180 $reportService->getFormStats($this->sanitizeReportAttributes())
181 );
182 } catch (Exception $e) {
183 return $this->sendError([
184 'message' => $e->getMessage(),
185 ]);
186 }
187 }
188
189 /**
190 * Get Heatmap Data
191 * @return \WP_REST_Response
192 */
193 public function getHeatmapData()
194 {
195 try {
196 $data = apply_filters('fluentform/reports/heatmap_data', [], $this->sanitizeReportAttributes());
197 return $this->sendSuccess($data);
198 } catch (Exception $e) {
199 return $this->sendError([
200 'message' => $e->getMessage(),
201 ]);
202 }
203 }
204
205 /**
206 * Get Country Heatmap Data
207 * @return \WP_REST_Response
208 */
209 public function getCountryHeatmap(ReportService $reportService)
210 {
211 try {
212 $data = apply_filters('fluentform/reports/country_heatmap', [], $this->sanitizeReportAttributes());
213 return $this->sendSuccess($data);
214 } catch (Exception $e) {
215 return $this->sendError([
216 'message' => $e->getMessage(),
217 ]);
218 }
219 }
220
221 /**
222 * Get API Logs Data
223 * @return \WP_REST_Response
224 */
225 public function getApiLogs(ReportService $reportService)
226 {
227 try {
228 return $this->sendSuccess(
229 $reportService->getApiLogs($this->sanitizeReportAttributes())
230 );
231 } catch (Exception $e) {
232 return $this->sendError([
233 'message' => $e->getMessage(),
234 ]);
235 }
236 }
237
238 /**
239 * Get Top Performing Forms Data
240 * @return \WP_REST_Response
241 */
242 public function getTopPerformingForms(ReportService $reportService)
243 {
244 try {
245 return $this->sendSuccess(
246 $reportService->getTopPerformingForms($this->sanitizeReportAttributes())
247 );
248 } catch (Exception $e) {
249 return $this->sendError([
250 'message' => $e->getMessage(),
251 ]);
252 }
253 }
254
255 /**
256 * Get Subscriptions Data
257 * @return \WP_REST_Response
258 */
259 public function getSubscriptions()
260 {
261 try {
262 $data = apply_filters('fluentform/reports/subscriptions', [], $this->sanitizeReportAttributes());
263 return $this->sendSuccess($data);
264 } catch (Exception $e) {
265 return $this->sendError([
266 'message' => $e->getMessage(),
267 ]);
268 }
269 }
270
271 /**
272 * Get Payment Types Data
273 * @return \WP_REST_Response
274 */
275 public function getPaymentTypes(ReportService $reportService)
276 {
277 try {
278 return $this->sendSuccess(
279 $reportService->getPaymentTypes($this->sanitizeReportAttributes())
280 );
281 } catch (Exception $e) {
282 return $this->sendError([
283 'message' => $e->getMessage(),
284 ]);
285 }
286 }
287 }
288