PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.4
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 / Database / ReportsModel.php

ReportsModel.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.4, at includes/Core/Database/ReportsModel.php

96 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Provides Report Model Class
5 */
6
7 namespace BitCode\BitForm\Core\Database;
8
9 use WP_Error;
10
11 /**
12 *
13 */
14 class ReportsModel extends Model
15 {
16 protected static $table = 'bitforms_reports';
17
18 public function validateReportFields($reportData, $fieldNames)
19 {
20 $reportDetails = [];
21 switch ($reportData->type) {
22 case 'table':
23 $tableAction = 'table_ac';
24 $reportDetails = !is_string($reportData->details) ? $reportData->details : json_decode($reportData->details);
25 if (!empty($reportDetails->order)) {
26 $initialOrder = $fieldNames;
27 $columnOrder = $reportDetails->order;
28 foreach ($reportDetails->order as $key => $value) {
29 if (isset($initialOrder[$value])) {
30 unset($initialOrder[$value]);
31 } elseif (!isset($initialOrder[$value])) {
32 unset($columnOrder[$key]);
33 }
34 }
35 $columnOrder = array_values($columnOrder);
36 if (!empty($initialOrder)) {
37 foreach ($initialOrder as $name => $label) {
38 $columnOrder[] = $name;
39 }
40 }
41 $columnOrder[] = $tableAction;
42 array_unshift($columnOrder, 'selection', 'sl');
43 $reportDetails->order = $columnOrder;
44 }
45 if (!empty($reportDetails->hiddenColumns)) {
46 $hiddenColumns = $reportDetails->hiddenColumns;
47 foreach ($reportDetails->hiddenColumns as $key => $value) {
48 if (!isset($fieldNames[$value]) && ('sl' !== $value && 'selection' !== $value && 'table_ac' !== $value)) {
49 unset($hiddenColumns[$key]);
50 }
51 }
52 $reportDetails->hiddenColumns = array_values($hiddenColumns);
53 }
54 break;
55
56 default:
57 break;
58 }
59 return $reportDetails;
60 }
61
62 public function bulkDelete(array $condition = null, $check_operator = null)
63 {
64 if (
65 !\is_null($condition)
66 && \is_array($condition)
67 && array_keys($condition) !== range(0, count($condition) - 1)
68 ) {
69 $delete_condition = $condition;
70 } else {
71 return new WP_Error(
72 'deletion_error',
73 __('At least 1 condition needed', 'bit-form')
74 );
75 }
76 $formatted_conditions = $this->getFormatedCondition($delete_condition, $check_operator);
77 if ($formatted_conditions) {
78 $condition_to_check = $formatted_conditions['conditions'];
79 $all_values = $formatted_conditions['values'];
80 } else {
81 $condition_to_check = null;
82 return new WP_Error(
83 'deletion_error',
84 __('At least 1 condition needed', 'bit-form')
85 );
86 }
87 $result = $this->app_db->query(
88 $this->app_db->prepare(
89 "DELETE FROM $this->table_name $condition_to_check",
90 $all_values
91 )
92 );
93 return $this->getResult($result);
94 }
95 }
96