PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.7.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.7.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
← All changes | includes/Core/Database/Model.php +28 -46 3.1.22.7.0 View file →
@@ -37,9 +37,9 @@
37 37 */
38 38 public function insert($data = [])
39 39 {
40 40 if (is_null($data)) {
41 - return new WP_Error('empty_data', 'Form data is empty');
41 + return new WP_Error('empty_data', __('Form data is empty', 'bit-form'));
42 42 }
43 43 $result = $this->app_db->insert(
44 44 $this->table_name,
45 45 $data
@@ -56,17 +56,15 @@
56 56 * @return mixed
57 57 */
58 58 public function get($item = '*', $condition = [], $limit = null, $offset = null, $order_by = null, $order_follow = null)
59 59 {
60 - static $tableExistsCache = [];
61 - if (!isset($tableExistsCache[$this->table_name])) {
62 - $tableExistsCache[$this->table_name] = !is_null(
63 - $this->app_db->get_var(
64 - $this->app_db->prepare('SHOW TABLES LIKE %s', $this->table_name)
65 - )
66 - );
67 - }
68 - if (!$tableExistsCache[$this->table_name]) {
60 + $checkIfTableExists = $this->app_db->get_var(
61 + $this->app_db->prepare(
62 + 'SHOW TABLES LIKE %s',
63 + $this->table_name
64 + )
65 + );
66 + if (is_null($checkIfTableExists)) {
69 67 return [];
70 68 }
71 69 if (\is_array($item)) {
72 70 $column_to_select = implode(',', $item);
@@ -137,9 +135,9 @@
137 135 $all_values = null;
138 136 }
139 137 $result = $this->app_db->query(
140 138 $this->app_db->prepare(
141 - "SELECT COUNT(*) as count FROM `{$this->table_name}`"
139 + "SELECT COUNT(*) as count FROM `$this->table_name`"
142 140 . $condition_to_check,
143 141 $all_values
144 142 )
145 143 );
@@ -147,9 +145,9 @@
147 145 if (!$result) {
148 146 if ($this->app_db->last_error) {
149 147 return new WP_Error('db_error', $this->app_db->last_error);
150 148 }
151 - return new WP_Error('db_error', 'Result is empty');
149 + return new WP_Error('db_error', __('Result is empty', 'bit-form'));
152 150 } else {
153 151 return $this->app_db->last_result;
154 152 }
155 153 }
@@ -172,9 +170,9 @@
172 170 $data_to_update = $data;
173 171 } else {
174 172 return new WP_Error(
175 173 'update_error',
176 - 'Nothing to update'
174 + __('Nothing to update', 'bit-form')
177 175 );
178 176 }
179 177 $update_condition = (!\is_null($condition) &&
180 178 array_keys($condition) !== range(0, count($condition) - 1)) ? $condition : null;
@@ -204,9 +202,9 @@
204 202 $data_to_update = $data;
205 203 } else {
206 204 return new WP_Error(
207 205 'update_error',
208 - 'Nothing to update'
206 + __('Nothing to update', 'bit-form')
209 207 );
210 208 }
211 209
212 210 $update_fields = '';
@@ -231,9 +229,9 @@
231 229 $condition_to_check = null;
232 230 }
233 231 $result = $this->app_db->query(
234 232 $this->app_db->prepare(
235 - "UPDATE `{$this->table_name}` SET $update_fields $condition_to_check",
233 + "UPDATE $this->table_name SET $update_fields $condition_to_check",
236 234 $all_values
237 235 )
238 236 );
239 237 return $this->getResult($result);
@@ -256,9 +254,9 @@
256 254 && \is_array($duplicate)
257 255 && array_keys($duplicate) === range(0, count($duplicate) - 1))) {
258 256 return new WP_Error(
259 257 'duplicate_error',
260 - 'Nothing to duplicate'
258 + __('Nothing to duplicate', 'bit-form')
261 259 );
262 260 }
263 261
264 262 $dupCol = '';
@@ -283,10 +281,10 @@
283 281 if ($formatted_conditions) {
284 282 $condition_to_check = $formatted_conditions['conditions'];
285 283 $all_values = array_merge($all_values, $formatted_conditions['values']);
286 284 }
287 - $query = "INSERT INTO `{$this->table_name}` ($insCol)
288 - SELECT $dupCol FROM `{$this->table_name}` $condition_to_check";
285 + $query = "INSERT INTO $this->table_name ($insCol)
286 + SELECT $dupCol FROM $this->table_name $condition_to_check";
289 287 $this->execute($query, $all_values);
290 288 return $this->getResult();
291 289 }
292 290
@@ -300,9 +298,9 @@
300 298 $delete_condition = $condition;
301 299 } else {
302 300 return new WP_Error(
303 301 'deletion_error',
304 - 'At least 1 condition needed'
302 + __('At least 1 condition needed', 'bit-form')
305 303 );
306 304 }
307 305 $update_condition = (!\is_null($condition) &&
308 306 array_keys($condition) !== range(0, count($condition) - 1)) ? $condition : null;
@@ -324,9 +322,9 @@
324 322 $delete_condition = $condition;
325 323 } else {
326 324 return new WP_Error(
327 325 'deletion_error',
328 - 'At least 1 condition needed'
326 + __('At least 1 condition needed', 'bit-form')
329 327 );
330 328 }
331 329 $result = $this->app_db->delete(
332 330 $this->table_name,
@@ -345,9 +343,9 @@
345 343 $delete_condition = $condition;
346 344 } else {
347 345 return new WP_Error(
348 346 'deletion_error',
349 - 'At least 1 condition needed'
347 + __('At least 1 condition needed', 'bit-form')
350 348 );
351 349 }
352 350 // $formatted_conditions = $this->getFormatedCondition($delete_condition, $check_operator);
353 351 $formatted_conditions = $this->getFormatedCondition($delete_condition);
@@ -357,14 +355,14 @@
357 355 } else {
358 356 $condition_to_check = null;
359 357 return new WP_Error(
360 358 'deletion_error',
361 - 'At least 1 condition needed'
359 + __('At least 1 condition needed', 'bit-form')
362 360 );
363 361 }
364 362 $result = $this->app_db->query(
365 363 $this->app_db->prepare(
366 - "DELETE FROM `{$this->table_name}` $condition_to_check",
364 + "DELETE FROM $this->table_name $condition_to_check",
367 365 $all_values
368 366 )
369 367 );
370 368 return $this->getResult($result);
@@ -387,21 +385,13 @@
387 385 $all_values = [];
388 386 foreach ($condition as $key => $value) {
389 387 $value_type = '';
390 388 if (is_array($value)) {
391 - // Check for raw SQL values first
392 - if (isset($value['raw'])) {
393 - // Handle raw SQL - don't format or add to prepared values
394 - $set_check_operator = isset($value['operator']) ? $value['operator'] : '=';
395 - $value_type = $value['raw']; // Use raw SQL directly
396 - // Don't add to $all_values since it's raw SQL
397 - } elseif (isset($value['operator'])) {
398 - // logic for operator arrays
389 + if (isset($value['operator'])) {
399 390 $set_check_operator = $value['operator'];
400 391 $value_type .= $this->getFieldFormat($value['value']);
401 392 $all_values[] = $value['value'];
402 393 } else {
403 - // logic for IN conditions
404 394 $set_check_operator = \is_null($check_operator) ? 'in' : $check_operator;
405 395 $value_type .= ' ( ';
406 396 $value_index_checker = 0;
407 397 $value_count = count($value) - 1;
@@ -415,9 +405,8 @@
415 405 }
416 406 $value_type .= ' )';
417 407 }
418 408 } else {
419 - // logic for simple values
420 409 $set_check_operator = \is_null($check_operator) ? '=' : $check_operator;
421 410 $value_type .= $this->getFieldFormat($value);
422 411 $all_values[] = $value;
423 412 }
@@ -452,9 +441,9 @@
452 441 $preparedQuery = $this->app_db->prepare($sql, $values);
453 442 }
454 443 // echo " Q S " . $preparedQuery . " Q EE";
455 444 if (empty($preparedQuery)) {
456 - $this->db_response = new WP_Error('null_query', 'prepared query is empty');
445 + $this->db_response = new WP_Error('null_query', __('prepared query is empty', 'bit-form'));
457 446 } else {
458 447 $this->db_response = false !== stripos($preparedQuery, 'DELETE') ? $this->app_db->query($preparedQuery)
459 448 : $this->app_db->get_results($preparedQuery, OBJECT_K);
460 449 }
@@ -474,9 +463,9 @@
474 463 }
475 464 if (is_wp_error($db_response)) {
476 465 $response = $db_response;
477 466 }
478 - $response = new WP_Error('result_empty', 'Result is empty');
467 + $response = new WP_Error('result_empty', __('Result is empty', 'bit-form'));
479 468 } elseif (is_array($this->app_db->last_result) && !empty($this->app_db->last_result)) {
480 469 $response = $this->app_db->last_result;
481 470 } elseif ($this->app_db->insert_id) {
482 471 $response = $this->app_db->insert_id;
@@ -486,20 +475,13 @@
486 475 $this->app_db->flush();
487 476 return $response;
488 477 }
489 478
490 - /**
491 - * Get last inserted id
492 - *
493 - * @return int
494 - */
479 + // get last entry id
495 480 public function lastId()
496 481 {
497 - $sql = "SELECT id FROM `{$this->table_name}`
482 + $sql = "SELECT id FROM {$this->table_name}
498 483 ORDER BY id DESC LIMIT 1";
499 - $result = $this->execute($sql)->getResult();
500 - if (is_wp_error($result)) {
501 - return 0;
502 - }
503 - return $result[0]->id;
484 + $result = $this->execute($sql)->getResult()[0];
485 + return $result->id;
504 486 }
505 487 }