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

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