| @@ -7,19 +7,20 @@ | ||
| 7 | 7 | /** |
| 8 | 8 | * Undocumented class |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -class FormEntryLogModel extends Model { | |
| 11 | +class FormEntryLogModel extends Model | |
| 12 | +{ | |
| 12 | 13 | protected static $table = 'bitforms_form_log_details'; |
| 13 | 14 | |
| 14 | - public function geLogHistory($form_id, $entry_id) { | |
| 15 | - $sql = "SELECT * FROM `{$this->app_db->prefix}bitforms_form_entry_log` where form_entry_id=$entry_id AND form_id=$form_id order By created_at DESC"; | |
| 16 | - | |
| 17 | - $logs = $this->execute($sql)->getResult(); | |
| 15 | + public function geLogHistory($form_id, $entry_id) | |
| 16 | + { | |
| 17 | + $sql = "SELECT * FROM `{$this->app_db->prefix}bitforms_form_entry_log` where form_entry_id=%d AND form_id=%d order By created_at DESC"; | |
| 18 | + $logs = $this->execute($sql, [$entry_id, $form_id])->getResult(); | |
| 18 | 19 | $response = ['success' => true, 'data' => [], 'integrations' => []]; |
| 19 | 20 | $ids = []; |
| 20 | 21 | foreach ($logs as $log) { |
| 21 | - $ids[] = $log->id; | |
| 22 | + $ids[] = (int) $log->id; | |
| 22 | 23 | } |
| 23 | 24 | if (isset($logs->errors['result_empty'])) { |
| 24 | 25 | wp_send_json($response); |
| 25 | 26 | } else { |
| @@ -25,23 +26,27 @@ | ||
| 25 | 26 | } else { |
| 26 | 27 | $allLogId = preg_replace('/"/', '', implode(',', $ids)); |
| 27 | 28 | $sql2 = "SELECT * FROM `{$this->app_db->prefix}bitforms_form_log_details` WHERE `log_id` IN ($allLogId)"; |
| 28 | 29 | $integrations = $this->execute($sql2)->getResult(); |
| 29 | - foreach ($logs as $key => $log) { | |
| 30 | - foreach ($integrations as $integration) { | |
| 31 | - if ($integration->log_id === $log->id) { | |
| 32 | - $logs[$key]->integration = true; | |
| 30 | + | |
| 31 | + if (isset($integrations->errors['result_empty'])) { | |
| 32 | + $integrations = []; | |
| 33 | + } else { | |
| 34 | + foreach ($logs as $key => $log) { | |
| 35 | + foreach ($integrations as $integration) { | |
| 36 | + if ($integration->log_id === $log->id) { | |
| 37 | + $logs[$key]->integration = true; | |
| 38 | + } | |
| 33 | 39 | } |
| 34 | 40 | } |
| 35 | 41 | } |
| 36 | - if (isset($integrations->errors['result_empty'])) { | |
| 37 | - $integrations = []; | |
| 38 | - } | |
| 42 | + | |
| 39 | 43 | wp_send_json(['success' => true, 'data' => $logs, 'integrations' => $integrations]); |
| 40 | 44 | } |
| 41 | 45 | } |
| 42 | 46 | |
| 43 | - public function entryLogCheck($entry_id, $integ_id) { | |
| 47 | + public function entryLogCheck($entry_id, $integ_id) | |
| 48 | + { | |
| 44 | 49 | if (is_null($entry_id)) { |
| 45 | 50 | return new WP_Error('empty_data', __('Form data is empty', 'bit-form')); |
| 46 | 51 | } |
| 47 | 52 | $sql = "SELECT api_type, response_obj FROM `{$this->app_db->prefix}bitforms_form_entry_log` as el JOIN `{$this->app_db->prefix}bitforms_form_log_details` as ld ON ld.log_id = el.id WHERE form_entry_id = {$entry_id} AND integration_id = {$integ_id} AND ld.response_type = 'success' ORDER BY el.id DESC LIMIT 1"; |
| @@ -48,9 +53,10 @@ | ||
| 48 | 53 | |
| 49 | 54 | return $this->app_db->get_results($sql); |
| 50 | 55 | } |
| 51 | 56 | |
| 52 | - public function form_log_insert($data = []) { | |
| 57 | + public function form_log_insert($data = []) | |
| 58 | + { | |
| 53 | 59 | if (is_null($data)) { |
| 54 | 60 | return new WP_Error('empty_data', __('Form data is empty', 'bit-form')); |
| 55 | 61 | } |
| 56 | 62 | $result = $this->app_db->insert( |
| @@ -59,9 +65,10 @@ | ||
| 59 | 65 | ); |
| 60 | 66 | return $this->getResult($result); |
| 61 | 67 | } |
| 62 | 68 | |
| 63 | - public function log_history_insert($data = []) { | |
| 69 | + public function log_history_insert($data = []) | |
| 70 | + { | |
| 64 | 71 | if (is_null($data)) { |
| 65 | 72 | return new WP_Error('empty_data', __('Form data is empty', 'bit-form')); |
| 66 | 73 | } |
| 67 | 74 | $result = $this->app_db->insert( |
| @@ -70,14 +77,16 @@ | ||
| 70 | 77 | ); |
| 71 | 78 | return $this->getResult($result); |
| 72 | 79 | } |
| 73 | 80 | |
| 74 | - public function get_form_value($form_id = '') { | |
| 81 | + public function get_form_value($form_id = '') | |
| 82 | + { | |
| 75 | 83 | $sql = "SELECT `meta_key`,`meta_value` FROM `{$this->app_db->prefix}bitforms_form_entrymeta` where bitforms_form_entry_id=$form_id"; |
| 76 | 84 | return $this->execute($sql)->getResult(); |
| 77 | 85 | } |
| 78 | 86 | |
| 79 | - public function logUpdate($updateValue, $logID) { | |
| 87 | + public function logUpdate($updateValue, $logID) | |
| 88 | + { | |
| 80 | 89 | if (empty($logID)) { |
| 81 | 90 | return false; |
| 82 | 91 | } |
| 83 | 92 | $sql = "UPDATE `{$this->app_db->prefix}bitforms_form_entry_log` SET content='$updateValue' WHERE id=$logID"; |