@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | $this->temp_return_type = $this->return_type; |
| 302 | 302 | |
| 303 | 303 | // Make sure our database is loaded |
| 304 | - if (!is_null($db)) { |
|
| 304 | + if ( ! is_null($db)) { |
|
| 305 | 305 | $this->db = $db; |
| 306 | 306 | } |
| 307 | 307 | else { |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // Do we have a form_validation library? |
| 313 | - if (! is_null($form_validation)) { |
|
| 313 | + if ( ! is_null($form_validation)) { |
|
| 314 | 314 | $this->form_validation = $form_validation; |
| 315 | 315 | } |
| 316 | 316 | else { |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | |
| 481 | 481 | if (is_array($rows)) { |
| 482 | 482 | foreach ($rows as $key => &$row) { |
| 483 | - $row = $this->trigger('after_find', ['method' => 'find_all', 'fields' => $row] ); |
|
| 483 | + $row = $this->trigger('after_find', ['method' => 'find_all', 'fields' => $row]); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | if ($data !== FALSE) { |
| 511 | 511 | $data = $this->trigger('before_insert', ['method' => 'insert', 'fields' => $data]); |
| 512 | 512 | |
| 513 | - $this->db->insert($this->table_name, $this->prep_data($data) ); |
|
| 513 | + $this->db->insert($this->table_name, $this->prep_data($data)); |
|
| 514 | 514 | |
| 515 | 515 | if ($this->return_insert_id) { |
| 516 | 516 | $id = $this->db->insert_id(); |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | if ($data !== FALSE) { |
| 557 | 557 | $data['batch'] = true; |
| 558 | - $data = $this->trigger('before_insert', ['method' => 'insert_batch', 'fields' => $data] ); |
|
| 558 | + $data = $this->trigger('before_insert', ['method' => 'insert_batch', 'fields' => $data]); |
|
| 559 | 559 | unset($data['batch']); |
| 560 | 560 | |
| 561 | 561 | return $this->db->insert_batch($this->table_name, $data); |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | * @param null $skip_validation |
| 578 | 578 | * @return bool |
| 579 | 579 | */ |
| 580 | - public function replace($data, $skip_validation=null) |
|
| 580 | + public function replace($data, $skip_validation = null) |
|
| 581 | 581 | { |
| 582 | 582 | $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
| 583 | 583 | |
@@ -624,10 +624,10 @@ discard block |
||
| 624 | 624 | // Will be false if it didn't validate. |
| 625 | 625 | if ($data !== FALSE) { |
| 626 | 626 | |
| 627 | - $data = $this->trigger('before_update', ['id' => $id, 'method' =>'update', 'fields' => $data] ); |
|
| 627 | + $data = $this->trigger('before_update', ['id' => $id, 'method' =>'update', 'fields' => $data]); |
|
| 628 | 628 | |
| 629 | 629 | $this->db->where($this->primary_key, $id); |
| 630 | - $this->db->set( $this->prep_data($data) ); |
|
| 630 | + $this->db->set($this->prep_data($data)); |
|
| 631 | 631 | $result = $this->db->update($this->table_name); |
| 632 | 632 | |
| 633 | 633 | $this->trigger('after_update', ['id' => $id, 'fields' => $data, 'result' => $result, 'method' => 'update']); |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | public function update_batch($data, $where_key) |
| 667 | 667 | { |
| 668 | 668 | foreach ($data as &$row) { |
| 669 | - $row = $this->trigger('before_update', ['method' => 'update_batch', 'fields' => $row] ); |
|
| 669 | + $row = $this->trigger('before_update', ['method' => 'update_batch', 'fields' => $row]); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | $result = $this->db->update_batch($this->table_name, $data, $where_key); |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | */ |
| 701 | 701 | public function update_many($ids, $data, $skip_validation = null) |
| 702 | 702 | { |
| 703 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 703 | + if ( ! is_array($ids) || count($ids) == 0) return NULL; |
|
| 704 | 704 | |
| 705 | 705 | $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
| 706 | 706 | |
@@ -754,10 +754,10 @@ discard block |
||
| 754 | 754 | |
| 755 | 755 | // Will be false if it didn't validate. |
| 756 | 756 | if ($this->validate($data) !== FALSE) { |
| 757 | - $this->db->set( $this->prep_data($data) ); |
|
| 757 | + $this->db->set($this->prep_data($data)); |
|
| 758 | 758 | $result = $this->db->update($this->table_name); |
| 759 | 759 | |
| 760 | - $this->trigger('after_update', ['method' => 'update_by', 'fields' => $data, 'result' => $result] ); |
|
| 760 | + $this->trigger('after_update', ['method' => 'update_by', 'fields' => $data, 'result' => $result]); |
|
| 761 | 761 | |
| 762 | 762 | return $result; |
| 763 | 763 | } else { |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | */ |
| 777 | 777 | public function update_all($data, $skip_validation = FALSE) |
| 778 | 778 | { |
| 779 | - $data = $this->trigger('before_update', ['method' => 'update_all', 'fields' => $data] ); |
|
| 779 | + $data = $this->trigger('before_update', ['method' => 'update_all', 'fields' => $data]); |
|
| 780 | 780 | |
| 781 | 781 | $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
| 782 | 782 | |
@@ -786,10 +786,10 @@ discard block |
||
| 786 | 786 | |
| 787 | 787 | // Will be false if it didn't validate. |
| 788 | 788 | if ($data !== FALSE) { |
| 789 | - $this->db->set( $this->prep_data($data) ); |
|
| 789 | + $this->db->set($this->prep_data($data)); |
|
| 790 | 790 | $result = $this->db->update($this->table_name); |
| 791 | 791 | |
| 792 | - $this->trigger('after_update', ['method' => 'update_all', 'fields' => $data, 'result' => $result] ); |
|
| 792 | + $this->trigger('after_update', ['method' => 'update_all', 'fields' => $data, 'result' => $result]); |
|
| 793 | 793 | |
| 794 | 794 | return $result; |
| 795 | 795 | } else { |
@@ -808,9 +808,9 @@ discard block |
||
| 808 | 808 | * @param int $value |
| 809 | 809 | * @return mixed |
| 810 | 810 | */ |
| 811 | - public function increment($id, $field, $value=1) |
|
| 811 | + public function increment($id, $field, $value = 1) |
|
| 812 | 812 | { |
| 813 | - $value = (int)abs($value); |
|
| 813 | + $value = (int) abs($value); |
|
| 814 | 814 | |
| 815 | 815 | $this->db->where($this->primary_key, $id); |
| 816 | 816 | $this->db->set($field, "{$field}+{$value}", false); |
@@ -829,9 +829,9 @@ discard block |
||
| 829 | 829 | * @param int $value |
| 830 | 830 | * @return mixed |
| 831 | 831 | */ |
| 832 | - public function decrement($id, $field, $value=1) |
|
| 832 | + public function decrement($id, $field, $value = 1) |
|
| 833 | 833 | { |
| 834 | - $value = (int)abs($value); |
|
| 834 | + $value = (int) abs($value); |
|
| 835 | 835 | |
| 836 | 836 | $this->db->where($this->primary_key, $id); |
| 837 | 837 | $this->db->set($field, "{$field}-{$value}", false); |
@@ -849,7 +849,7 @@ discard block |
||
| 849 | 849 | */ |
| 850 | 850 | public function delete($id) |
| 851 | 851 | { |
| 852 | - $this->trigger('before_delete', ['id' => $id, 'method' => 'delete'] ); |
|
| 852 | + $this->trigger('before_delete', ['id' => $id, 'method' => 'delete']); |
|
| 853 | 853 | |
| 854 | 854 | $this->db->where($this->primary_key, $id); |
| 855 | 855 | |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | $result = $this->db->delete($this->table_name); |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | - $this->trigger('after_delete', ['id' => $id, 'method' => 'delete', 'result' => $result] ); |
|
| 867 | + $this->trigger('after_delete', ['id' => $id, 'method' => 'delete', 'result' => $result]); |
|
| 868 | 868 | |
| 869 | 869 | return $result; |
| 870 | 870 | } |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | $result = $this->db->delete($this->table_name); |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - $this->trigger('after_delete', ['method' => 'delete_by', 'fields' => $where, 'result' => $result] ); |
|
| 891 | + $this->trigger('after_delete', ['method' => 'delete_by', 'fields' => $where, 'result' => $result]); |
|
| 892 | 892 | |
| 893 | 893 | return $result; |
| 894 | 894 | } |
@@ -897,9 +897,9 @@ discard block |
||
| 897 | 897 | |
| 898 | 898 | public function delete_many($ids) |
| 899 | 899 | { |
| 900 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 900 | + if ( ! is_array($ids) || count($ids) == 0) return NULL; |
|
| 901 | 901 | |
| 902 | - $ids = $this->trigger('before_delete', ['ids' => $ids, 'method' => 'delete_many'] ); |
|
| 902 | + $ids = $this->trigger('before_delete', ['ids' => $ids, 'method' => 'delete_many']); |
|
| 903 | 903 | |
| 904 | 904 | $this->db->where_in($this->primary_key, $ids); |
| 905 | 905 | |
@@ -960,7 +960,7 @@ discard block |
||
| 960 | 960 | * @param string $class |
| 961 | 961 | * @return $this |
| 962 | 962 | */ |
| 963 | - public function as_object($class=null) |
|
| 963 | + public function as_object($class = null) |
|
| 964 | 964 | { |
| 965 | 965 | $this->temp_return_type = ! empty($class) ? $class : 'object'; |
| 966 | 966 | |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | */ |
| 1061 | 1061 | public function return_insert_id($return = true) |
| 1062 | 1062 | { |
| 1063 | - $this->return_insert_id = (bool)$return; |
|
| 1063 | + $this->return_insert_id = (bool) $return; |
|
| 1064 | 1064 | |
| 1065 | 1065 | return $this; |
| 1066 | 1066 | } |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | |
| 1171 | 1171 | // Though the model doesn't support multiple keys well, $this->key |
| 1172 | 1172 | // could be an array or a string... |
| 1173 | - $skippedFields = array_merge($skippedFields, (array)$this->primary_key); |
|
| 1173 | + $skippedFields = array_merge($skippedFields, (array) $this->primary_key); |
|
| 1174 | 1174 | |
| 1175 | 1175 | // Remove any protected attributes |
| 1176 | 1176 | $skippedFields = array_merge($skippedFields, $this->protected_attributes); |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | * |
| 1201 | 1201 | * @return string |
| 1202 | 1202 | */ |
| 1203 | - public function last_query () |
|
| 1203 | + public function last_query() |
|
| 1204 | 1204 | { |
| 1205 | 1205 | return $this->db->last_query(); |
| 1206 | 1206 | } |
@@ -1213,11 +1213,11 @@ discard block |
||
| 1213 | 1213 | * |
| 1214 | 1214 | * @return mixed |
| 1215 | 1215 | */ |
| 1216 | - public function last_query_time () |
|
| 1216 | + public function last_query_time() |
|
| 1217 | 1217 | { |
| 1218 | 1218 | $times = $this->db->query_times; |
| 1219 | 1219 | |
| 1220 | - if (! is_array($this->db->query_times) || ! count($this->db->query_times)) |
|
| 1220 | + if ( ! is_array($this->db->query_times) || ! count($this->db->query_times)) |
|
| 1221 | 1221 | { |
| 1222 | 1222 | return null; |
| 1223 | 1223 | } |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | $row = $row['fields']; |
| 1250 | 1250 | |
| 1251 | 1251 | // Created_on |
| 1252 | - if (! array_key_exists($this->created_field, $row)) |
|
| 1252 | + if ( ! array_key_exists($this->created_field, $row)) |
|
| 1253 | 1253 | { |
| 1254 | 1254 | $row[$this->created_field] = $this->set_date(); |
| 1255 | 1255 | } |
@@ -1260,7 +1260,7 @@ discard block |
||
| 1260 | 1260 | // If you're here because of an error with $this->authenticate |
| 1261 | 1261 | // not being available, it's likely due to you not using |
| 1262 | 1262 | // the AuthTrait and/or setting log_user after model is instantiated. |
| 1263 | - $row[$this->created_by_field] = (int)$this->authenticate->id(); |
|
| 1263 | + $row[$this->created_by_field] = (int) $this->authenticate->id(); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | return $row; |
@@ -1332,7 +1332,7 @@ discard block |
||
| 1332 | 1332 | */ |
| 1333 | 1333 | public function trigger($event, $data = false) |
| 1334 | 1334 | { |
| 1335 | - if (! isset($this->$event) || ! is_array($this->$event)) |
|
| 1335 | + if ( ! isset($this->$event) || ! is_array($this->$event)) |
|
| 1336 | 1336 | { |
| 1337 | 1337 | if (isset($data['fields'])) |
| 1338 | 1338 | { |
@@ -1397,18 +1397,18 @@ discard block |
||
| 1397 | 1397 | $this->load->database(); |
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | - if (!empty($this->validation_rules)) { |
|
| 1400 | + if ( ! empty($this->validation_rules)) { |
|
| 1401 | 1401 | $this->form_validation->set_data($data); |
| 1402 | 1402 | |
| 1403 | 1403 | if (is_array($this->validation_rules)) { |
| 1404 | 1404 | // Any insert additions? |
| 1405 | 1405 | if ($type == 'insert' |
| 1406 | - && !empty($this->insert_validate_rules) |
|
| 1406 | + && ! empty($this->insert_validate_rules) |
|
| 1407 | 1407 | && is_array($this->insert_validate_rules) |
| 1408 | 1408 | ) { |
| 1409 | 1409 | foreach ($this->validation_rules as &$row) { |
| 1410 | 1410 | if (isset($this->insert_validate_rules[$row['field']])) { |
| 1411 | - $row ['rules'] .= '|' . $this->insert_validate_rules[$row['field']]; |
|
| 1411 | + $row ['rules'] .= '|'.$this->insert_validate_rules[$row['field']]; |
|
| 1412 | 1412 | } |
| 1413 | 1413 | } |
| 1414 | 1414 | } |
@@ -1475,7 +1475,7 @@ discard block |
||
| 1475 | 1475 | */ |
| 1476 | 1476 | protected function set_date($user_date = NULL) |
| 1477 | 1477 | { |
| 1478 | - $curr_date = !empty($user_date) ? $user_date : time(); |
|
| 1478 | + $curr_date = ! empty($user_date) ? $user_date : time(); |
|
| 1479 | 1479 | |
| 1480 | 1480 | switch ($this->date_format) { |
| 1481 | 1481 | case 'int': |
@@ -1499,7 +1499,7 @@ discard block |
||
| 1499 | 1499 | * |
| 1500 | 1500 | * @return mixed |
| 1501 | 1501 | */ |
| 1502 | - public function error($db_array_only=false) |
|
| 1502 | + public function error($db_array_only = false) |
|
| 1503 | 1503 | { |
| 1504 | 1504 | // Send any validation errors if we have any. |
| 1505 | 1505 | if (function_exists('validation_errors') && validation_errors() && ! $db_array_only) |
@@ -1515,7 +1515,7 @@ discard block |
||
| 1515 | 1515 | return $error; |
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | - if (! empty($error['code'])) |
|
| 1518 | + if ( ! empty($error['code'])) |
|
| 1519 | 1519 | { |
| 1520 | 1520 | return "Database Error {$error['code']}: {$error['message']}."; |
| 1521 | 1521 | } |