| @@ -5,15 +5,23 @@ | ||
| 5 | 5 | use BitCode\BitForm\Core\Database\FormModel; |
| 6 | 6 | use BitCode\BitForm\Core\Database\ReportsModel; |
| 7 | 7 | use BitCode\BitForm\Core\Util\IpTool; |
| 8 | 8 | |
| 9 | -class Report { | |
| 10 | - public function report() { | |
| 9 | +class Report | |
| 10 | +{ | |
| 11 | + public function report() | |
| 12 | + { | |
| 11 | 13 | $reportMdl = new ReportsModel(); |
| 12 | 14 | global $wpdb; |
| 13 | 15 | $tablename = $wpdb->prefix . 'bitforms_reports'; |
| 14 | 16 | |
| 15 | - $latestIds = $wpdb->get_results("SELECT MAX(`id`) as latest_id FROM $tablename GROUP BY `context`"); | |
| 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; | |
| 16 | 24 | |
| 17 | 25 | $notDeletedIds = array_column($latestIds, 'latest_id'); |
| 18 | 26 | |
| 19 | 27 | if (!is_wp_error($latestIds) && count($notDeletedIds) > 0) { |
| @@ -29,9 +37,9 @@ | ||
| 29 | 37 | ['id'] |
| 30 | 38 | ); |
| 31 | 39 | |
| 32 | 40 | $details = [ |
| 33 | - 'report_name' => 'All Entries', | |
| 41 | + 'report_name' => __('All Entries', 'bit-form'), | |
| 34 | 42 | 'hiddenColumns' => [], |
| 35 | 43 | 'pageSize' => 10, |
| 36 | 44 | 'sortBy' => [], |
| 37 | 45 | 'filters' => [], |
| @@ -62,8 +70,38 @@ | ||
| 62 | 70 | 'updated_at' => $user_details['time'], |
| 63 | 71 | ]; |
| 64 | 72 | |
| 65 | 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 | + ); | |
| 66 | 104 | } |
| 67 | 105 | } |
| 68 | 106 | } |
| 69 | 107 | } |