PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.9
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.9
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 / Helper.php

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

170 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BitCode\BitForm\Core\Database;
3
4 final class Helper {
5 // public static function getTableName($className)
6 // {
7 // $className = str_replace('\\', '', $className);
8 // $className = str_replace('Model', '', $className);
9 // return strtolower($className);
10 // }
11 public function arrValueModifyByLogic( $operator, $value ) {
12 $oprators = [
13 'equal' => '["' . implode( '","', $value ) . '"]',
14 'not_equal' => '["' . implode( '","', $value ) . '"]',
15 'start_with' => '["' . implode( '","', $value ) . '"%',
16 'not_start_with' => '["' . implode( '","', $value ) . '"%',
17 'end_with' => '%"' . implode( '","', $value ) . '"]',
18 'not_end_with' => '%"' . implode( '","', $value ) . '"]',
19 'contain' => '%"' . implode( '","', $value ) . '"%',
20 'not_contain' => '%"' . implode( '","', $value ) . '"%',
21 'empty' => '',
22 'not_empty' => '',
23 ];
24
25 if ( isset( $oprators[$operator] ) ) {
26 return $oprators[$operator];
27 }
28
29 return $value;
30 }
31
32 public function dateQueryList() {
33 return [
34 'today' => 'Y-m-d_+0 days_=',
35 'till_today' => 'Y-m-d_+0 days_<=',
36 'tomorrow' => 'Y-m-d_+1 days_=',
37 'till_tomorrow' => 'Y-m-d_+1 days_<=',
38 'yesterday' => 'Y-m-d_-1 days_=',
39 'till_yesterday' => 'Y-m-d_-1 days_<=',
40 'last_7_days' => 'Y-m-d_-7 days_>=',
41 'last_30_days' => 'Y-m-d_-30 days_>=',
42 'last_60_days' => 'Y-m-d_-60 days_>=',
43 'last_90_days' => 'Y-m-d_-90 days_>=',
44 'last_120_days' => 'Y-m-d_-120 days_>=',
45 'next_7_days' => 'Y-m-d_+7 days_>=',
46 'next_30_days' => 'Y-m-d_+30 days_>=',
47 'next_60_days' => 'Y-m-d_+60 days_>=',
48 'next_90_days' => 'Y-m-d_+90 days_>=',
49 'next_120_days' => 'Y-m-d_+120 days_>=',
50 'current_month' => 'm_+0 month_=',
51 'next_month' => 'm_first day of next month_=',
52 'last_month' => 'm_first day of last month_=',
53 'current_week' => 'W_0 week_=',
54 'next_week' => 'W_+1 week_=',
55 'last_week' => 'W_-1 week_=',
56 'current_year' => 'Y_+0 year_=',
57 'next_year' => 'Y_+1 year_=',
58 'last_year' => 'Y_-1 year_=',
59 ];
60 }
61
62 public function strValueModifyByLogic( $operator, $value ) {
63 $timeInterval = $this->dateQueryList();
64
65 if ( isset( $timeInterval[$operator] ) ) {
66 $data = explode( '_', $timeInterval[$operator] );
67 if ( is_array( $data ) && count( $data ) > 0 ) {
68 $value = date( $data[0], strtotime( $data[1] ) );
69 }
70 }
71
72 $oprators = [
73 'greater_than' => (int) $value,
74 'less_than' => (int) $value,
75 'greater_than_equal' => (int) $value,
76 'less_than_equal' => (int) $value,
77 'start_with' => $value . '%',
78 'end_with' => '%' . $value,
79 'contain' => '%' . $value . '%',
80 'empty' => '',
81 'not_empty' => '',
82 'not_start_with' => $value . '%',
83 'not_end_with' => '%' . $value,
84 'not_contain' => '%' . $value . '%',
85 ];
86
87 if ( isset( $oprators[$operator] ) ) {
88 $value = $oprators[$operator];
89 }
90
91 if ( is_array( $value ) ) {
92 $value = implode( ',', $value );
93 }
94
95 return $value;
96
97 }
98
99 public function convertToSqlOperator( $operator ) {
100
101 $timeInterval = $this->dateQueryList();
102
103 if ( isset( $timeInterval[$operator] ) ) {
104 $data = explode( '_', $timeInterval[$operator] );
105 return $data[2];
106 }
107
108 $oprators = [
109 'greater_than' => '>',
110 'less_than' => '<',
111 'greater_than_equal' => '>=',
112 'less_than_equal' => '<=',
113 'equal' => '=',
114 'not_equal' => '!=',
115 'empty' => '=',
116 'not_empty' => '!=',
117 'start_with' => 'LIKE',
118 'not_start_with' => 'NOT LIKE',
119 'end_with' => 'LIKE',
120 'not_end_with' => 'NOT LIKE',
121 'contain' => 'LIKE',
122 'not_contain' => 'NOT LIKE',
123 ];
124
125 if ( isset( $oprators[$operator] ) ) {
126 return $oprators[$operator];
127 }
128
129 return $operator;
130 }
131
132 public function fieldQueryByDate( $fld, $operator, $value, $logic ) {
133
134 $currentYear = date( 'Y' );
135
136 $sql = '';
137
138 $daysInterval = [
139 'today',
140 'till_today',
141 'tomorrow',
142 'till_tomorrow',
143 'yesterday',
144 'till_yesterday',
145 'last_7_days',
146 'last_30_days',
147 'last_60_days',
148 'last_90_days',
149 'last_120_days',
150 'next_7_days',
151 'next_30_days',
152 'next_60_days',
153 'next_90_days',
154 'next_120_days',
155 ];
156 if ( in_array( $logic, $daysInterval ) ) {
157 $sql = "`$fld` $operator '$value'";
158 }
159
160 if ( in_array( $logic, ['current_month', 'next_month', 'last_month'] ) ) {
161 $sql = "MONTH(`$fld`) $operator '$value' AND YEAR(`$fld`) = '$currentYear'";
162 }
163
164 if ( in_array( $logic, ['current_week', 'next_week', 'last_week'] ) ) {
165 $sql = "WEEK(`$fld`) $operator '$value' AND YEAR(`$fld`) = $currentYear";
166 }
167 return $sql;
168 }
169 }
170