PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.9.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.9.1
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Fallback / Report.php

Report.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.9.1, at includes/Core/Fallback/Report.php

102 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Fallback;
4
5 use BitCode\BitForm\Core\Database\FormModel;
6 use BitCode\BitForm\Core\Database\ReportsModel;
7 use BitCode\BitForm\Core\Util\IpTool;
8
9 class Report
10 {
11 public function report()
12 {
13 $reportMdl = new ReportsModel();
14 global $wpdb;
15 $tablename = $wpdb->prefix . 'bitforms_reports';
16
17 $latestIds = $wpdb->get_results("SELECT MAX(`id`) as latest_id FROM $tablename GROUP BY `context`");
18
19 $notDeletedIds = array_column($latestIds, 'latest_id');
20
21 if (!is_wp_error($latestIds) && count($notDeletedIds) > 0) {
22 $reportMdl->bulkDelete(['id' => $notDeletedIds], 'NOT IN');
23 }
24
25 $ipTool = new IpTool();
26 $user_details = $ipTool->getUserDetail();
27
28 $formModel = new FormModel();
29
30 $forms = $formModel->get(
31 ['id']
32 );
33
34 $details = [
35 'report_name' => 'All Entries',
36 'hiddenColumns' => [],
37 'pageSize' => 10,
38 'sortBy' => [],
39 'filters' => [],
40 'globalFilter' => '',
41 'order' => [],
42 ];
43
44 foreach ($forms as $form) {
45 $existReportId = $reportMdl->get(
46 [
47 'id',
48 ],
49 [
50 'context' => $form->id,
51 ]
52 );
53 if (is_wp_error($existReportId)) {
54 $defaultReport = [
55 'type' => 'table',
56 'category' => 'form',
57 'context' => $form->id,
58 'details' => wp_json_encode($details),
59 'isDefault' => (bool) 1,
60 'user_id' => $user_details['id'],
61 'user_ip' => $user_details['ip'],
62 'user_device' => $user_details['device'],
63 'created_at' => $user_details['time'],
64 'updated_at' => $user_details['time'],
65 ];
66
67 $reportMdl->insert($defaultReport);
68 }
69 }
70 }
71
72 public function addHiddenColumns()
73 {
74 $reportMdl = new ReportsModel();
75 $reports = $reportMdl->get(
76 [
77 'id',
78 'details',
79 ],
80 [
81 'category' => 'form',
82 'type' => 'table',
83 ]
84 );
85
86 foreach ($reports as $report) {
87 $reportDetails = json_decode($report->details);
88 if (is_object($reportDetails) && (!property_exists($reportDetails, 'hiddenColumns') || empty($reportDetails->hiddenColumns))) {
89 $reportDetails->hiddenColumns = ['__user_id', '__user_ip', '__referer', '__user_device', '__created_at', '__updated_at'];
90 $reportMdl->update(
91 [
92 'details' => wp_json_encode($reportDetails),
93 ],
94 [
95 'id' => $report->id,
96 ]
97 );
98 }
99 }
100 }
101 }
102