PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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.21.13, at includes/Core/Fallback/Report.php

108 lines 2.7 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 $wpdb->query(
19 $wpdb->prepare(
20 "SELECT MAX(`id`) as latest_id FROM `{$tablename}` GROUP BY `context`"
21 )
22 );
23 $latestIds = $wpdb->last_result;
24
25 $notDeletedIds = array_column($latestIds, 'latest_id');
26
27 if (!is_wp_error($latestIds) && count($notDeletedIds) > 0) {
28 $reportMdl->bulkDelete(['id' => $notDeletedIds], 'NOT IN');
29 }
30
31 $ipTool = new IpTool();
32 $user_details = $ipTool->getUserDetail();
33
34 $formModel = new FormModel();
35
36 $forms = $formModel->get(
37 ['id']
38 );
39
40 $details = [
41 'report_name' => __('All Entries', 'bit-form'),
42 'hiddenColumns' => [],
43 'pageSize' => 10,
44 'sortBy' => [],
45 'filters' => [],
46 'globalFilter' => '',
47 'order' => [],
48 ];
49
50 foreach ($forms as $form) {
51 $existReportId = $reportMdl->get(
52 [
53 'id',
54 ],
55 [
56 'context' => $form->id,
57 ]
58 );
59 if (is_wp_error($existReportId)) {
60 $defaultReport = [
61 'type' => 'table',
62 'category' => 'form',
63 'context' => $form->id,
64 'details' => wp_json_encode($details),
65 'isDefault' => (bool) 1,
66 'user_id' => $user_details['id'],
67 'user_ip' => $user_details['ip'],
68 'user_device' => $user_details['device'],
69 'created_at' => $user_details['time'],
70 'updated_at' => $user_details['time'],
71 ];
72
73 $reportMdl->insert($defaultReport);
74 }
75 }
76 }
77
78 public function addHiddenColumns()
79 {
80 $reportMdl = new ReportsModel();
81 $reports = $reportMdl->get(
82 [
83 'id',
84 'details',
85 ],
86 [
87 'category' => 'form',
88 'type' => 'table',
89 ]
90 );
91
92 foreach ($reports as $report) {
93 $reportDetails = json_decode($report->details);
94 if (is_object($reportDetails) && (!property_exists($reportDetails, 'hiddenColumns') || empty($reportDetails->hiddenColumns))) {
95 $reportDetails->hiddenColumns = ['__user_id', '__user_ip', '__referer', '__user_device', '__created_at', '__updated_at'];
96 $reportMdl->update(
97 [
98 'details' => wp_json_encode($reportDetails),
99 ],
100 [
101 'id' => $report->id,
102 ]
103 );
104 }
105 }
106 }
107 }
108