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 / Helper.php

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

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