@@ -143,8 +143,7 @@ discard block |
||
| 143 | 143 | public function __construct(Database $db = null){ |
| 144 | 144 | if (is_object($db)){ |
| 145 | 145 | $this->setDatabaseInstance($db); |
| 146 | - } |
|
| 147 | - else{ |
|
| 146 | + } else{ |
|
| 148 | 147 | $obj = & get_instance(); |
| 149 | 148 | if (isset($obj->database) && is_object($obj->database)){ |
| 150 | 149 | /** |
@@ -260,8 +259,7 @@ discard block |
||
| 260 | 259 | $this->trigger('after_create', $insert_id); |
| 261 | 260 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
| 262 | 261 | return ! $insert_id ? true : $insert_id; |
| 263 | - } |
|
| 264 | - else |
|
| 262 | + } else |
|
| 265 | 263 | { |
| 266 | 264 | return FALSE; |
| 267 | 265 | } |
@@ -298,8 +296,7 @@ discard block |
||
| 298 | 296 | $result = $this->_database->update($data, $escape); |
| 299 | 297 | $this->trigger('after_update', array($data, $result)); |
| 300 | 298 | return $result; |
| 301 | - } |
|
| 302 | - else |
|
| 299 | + } else |
|
| 303 | 300 | { |
| 304 | 301 | return FALSE; |
| 305 | 302 | } |
@@ -322,8 +319,7 @@ discard block |
||
| 322 | 319 | $result = $this->_database->update($data, $escape); |
| 323 | 320 | $this->trigger('after_update', array($data, $result)); |
| 324 | 321 | return $result; |
| 325 | - } |
|
| 326 | - else |
|
| 322 | + } else |
|
| 327 | 323 | { |
| 328 | 324 | return FALSE; |
| 329 | 325 | } |
@@ -340,8 +336,7 @@ discard block |
||
| 340 | 336 | if (is_array($args[1])){ |
| 341 | 337 | $data = array_pop($args); |
| 342 | 338 | } |
| 343 | - } |
|
| 344 | - else if (count($args) == 3){ |
|
| 339 | + } else if (count($args) == 3){ |
|
| 345 | 340 | if (is_array($args[2])){ |
| 346 | 341 | $data = array_pop($args); |
| 347 | 342 | } |
@@ -354,8 +349,7 @@ discard block |
||
| 354 | 349 | $result = $this->_database->update($data); |
| 355 | 350 | $this->trigger('after_update', array($data, $result)); |
| 356 | 351 | return $result; |
| 357 | - } |
|
| 358 | - else |
|
| 352 | + } else |
|
| 359 | 353 | { |
| 360 | 354 | return FALSE; |
| 361 | 355 | } |
@@ -385,8 +379,7 @@ discard block |
||
| 385 | 379 | { |
| 386 | 380 | $this->getQueryBuilder()->from($this->_table); |
| 387 | 381 | $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
| 388 | - } |
|
| 389 | - else |
|
| 382 | + } else |
|
| 390 | 383 | { |
| 391 | 384 | $this->getQueryBuilder()->from($this->_table); |
| 392 | 385 | $result = $this->_database->delete(); |
@@ -409,8 +402,7 @@ discard block |
||
| 409 | 402 | { |
| 410 | 403 | $this->getQueryBuilder()->from($this->_table); |
| 411 | 404 | $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
| 412 | - } |
|
| 413 | - else |
|
| 405 | + } else |
|
| 414 | 406 | { |
| 415 | 407 | $this->getQueryBuilder()->from($this->_table); |
| 416 | 408 | $result = $this->_database->delete(); |
@@ -431,8 +423,7 @@ discard block |
||
| 431 | 423 | { |
| 432 | 424 | $this->getQueryBuilder()->from($this->_table); |
| 433 | 425 | $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
| 434 | - } |
|
| 435 | - else |
|
| 426 | + } else |
|
| 436 | 427 | { |
| 437 | 428 | $this->getQueryBuilder()->from($this->_table); |
| 438 | 429 | $result = $this->_database->delete(); |
@@ -494,8 +485,7 @@ discard block |
||
| 494 | 485 | if (count($args) == 2) |
| 495 | 486 | { |
| 496 | 487 | list($key, $value) = $args; |
| 497 | - } |
|
| 498 | - else |
|
| 488 | + } else |
|
| 499 | 489 | { |
| 500 | 490 | $key = $this->primary_key; |
| 501 | 491 | $value = $args[0]; |
@@ -647,8 +637,7 @@ discard block |
||
| 647 | 637 | if (is_object($row)) |
| 648 | 638 | { |
| 649 | 639 | $row->created_at = date('Y-m-d H:i:s'); |
| 650 | - } |
|
| 651 | - else |
|
| 640 | + } else |
|
| 652 | 641 | { |
| 653 | 642 | $row['created_at'] = date('Y-m-d H:i:s'); |
| 654 | 643 | } |
@@ -660,8 +649,7 @@ discard block |
||
| 660 | 649 | if (is_object($row)) |
| 661 | 650 | { |
| 662 | 651 | $row->updated_at = date('Y-m-d H:i:s'); |
| 663 | - } |
|
| 664 | - else |
|
| 652 | + } else |
|
| 665 | 653 | { |
| 666 | 654 | $row['updated_at'] = date('Y-m-d H:i:s'); |
| 667 | 655 | } |
@@ -688,8 +676,7 @@ discard block |
||
| 688 | 676 | if (is_array($row)) |
| 689 | 677 | { |
| 690 | 678 | $row[$column] = unserialize($row[$column]); |
| 691 | - } |
|
| 692 | - else |
|
| 679 | + } else |
|
| 693 | 680 | { |
| 694 | 681 | $row->$column = unserialize($row->$column); |
| 695 | 682 | } |
@@ -709,8 +696,7 @@ discard block |
||
| 709 | 696 | if (isset($row->$attr)){ |
| 710 | 697 | unset($row->$attr); |
| 711 | 698 | } |
| 712 | - } |
|
| 713 | - else |
|
| 699 | + } else |
|
| 714 | 700 | { |
| 715 | 701 | if (isset($row[$attr])){ |
| 716 | 702 | unset($row[$attr]); |
@@ -810,8 +796,7 @@ discard block |
||
| 810 | 796 | { |
| 811 | 797 | $this->getQueryBuilder()->orderBy($key, $value); |
| 812 | 798 | } |
| 813 | - } |
|
| 814 | - else |
|
| 799 | + } else |
|
| 815 | 800 | { |
| 816 | 801 | $this->getQueryBuilder()->orderBy($criteria, $order); |
| 817 | 802 | } |
@@ -842,8 +827,7 @@ discard block |
||
| 842 | 827 | { |
| 843 | 828 | $relationship = $value; |
| 844 | 829 | $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
| 845 | - } |
|
| 846 | - else |
|
| 830 | + } else |
|
| 847 | 831 | { |
| 848 | 832 | $relationship = $key; |
| 849 | 833 | $options = $value; |
@@ -853,15 +837,13 @@ discard block |
||
| 853 | 837 | { |
| 854 | 838 | if (is_object($this->loaderInstance)){ |
| 855 | 839 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
| 856 | - } |
|
| 857 | - else{ |
|
| 840 | + } else{ |
|
| 858 | 841 | Loader::model($options['model'], $relationship . '_model'); |
| 859 | 842 | } |
| 860 | 843 | if (is_object($row)) |
| 861 | 844 | { |
| 862 | 845 | $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']}); |
| 863 | - } |
|
| 864 | - else |
|
| 846 | + } else |
|
| 865 | 847 | { |
| 866 | 848 | $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]); |
| 867 | 849 | } |
@@ -881,8 +863,7 @@ discard block |
||
| 881 | 863 | { |
| 882 | 864 | $relationship = $value; |
| 883 | 865 | $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
| 884 | - } |
|
| 885 | - else |
|
| 866 | + } else |
|
| 886 | 867 | { |
| 887 | 868 | $relationship = $key; |
| 888 | 869 | $options = $value; |
@@ -892,15 +873,13 @@ discard block |
||
| 892 | 873 | { |
| 893 | 874 | if (is_object($this->loaderInstance)){ |
| 894 | 875 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
| 895 | - } |
|
| 896 | - else{ |
|
| 876 | + } else{ |
|
| 897 | 877 | Loader::model($options['model'], $relationship . '_model'); |
| 898 | 878 | } |
| 899 | 879 | if (is_object($row)) |
| 900 | 880 | { |
| 901 | 881 | $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key}); |
| 902 | - } |
|
| 903 | - else |
|
| 882 | + } else |
|
| 904 | 883 | { |
| 905 | 884 | $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]); |
| 906 | 885 | } |
@@ -946,8 +925,7 @@ discard block |
||
| 946 | 925 | $fv = null; |
| 947 | 926 | if (is_object($this->formValidationInstance)){ |
| 948 | 927 | $fv = $this->formValidationInstance; |
| 949 | - } |
|
| 950 | - else{ |
|
| 928 | + } else{ |
|
| 951 | 929 | Loader::library('FormValidation'); |
| 952 | 930 | $fv = $this->formvalidation; |
| 953 | 931 | $this->setFormValidation($fv); |
@@ -959,13 +937,11 @@ discard block |
||
| 959 | 937 | if ($fv->run()) |
| 960 | 938 | { |
| 961 | 939 | return $data; |
| 962 | - } |
|
| 963 | - else |
|
| 940 | + } else |
|
| 964 | 941 | { |
| 965 | 942 | return FALSE; |
| 966 | 943 | } |
| 967 | - } |
|
| 968 | - else |
|
| 944 | + } else |
|
| 969 | 945 | { |
| 970 | 946 | return $data; |
| 971 | 947 | } |
@@ -982,14 +958,12 @@ discard block |
||
| 982 | 958 | if (is_array($filter)) |
| 983 | 959 | { |
| 984 | 960 | $this->getQueryBuilder()->in($field, $filter); |
| 985 | - } |
|
| 986 | - else |
|
| 961 | + } else |
|
| 987 | 962 | { |
| 988 | 963 | if (is_int($field)) |
| 989 | 964 | { |
| 990 | 965 | $this->getQueryBuilder()->where($filter); |
| 991 | - } |
|
| 992 | - else |
|
| 966 | + } else |
|
| 993 | 967 | { |
| 994 | 968 | $this->getQueryBuilder()->where($field, $filter); |
| 995 | 969 | } |
@@ -1006,33 +980,27 @@ discard block |
||
| 1006 | 980 | if (count($params) == 1 && is_array($params[0])) |
| 1007 | 981 | { |
| 1008 | 982 | $this->_set_where_array($params[0]); |
| 1009 | - } |
|
| 1010 | - else if (count($params) == 1) |
|
| 983 | + } else if (count($params) == 1) |
|
| 1011 | 984 | { |
| 1012 | 985 | $this->getQueryBuilder()->where($params[0]); |
| 1013 | - } |
|
| 1014 | - else if (count($params) == 2) |
|
| 986 | + } else if (count($params) == 2) |
|
| 1015 | 987 | { |
| 1016 | 988 | if (is_array($params[1])) |
| 1017 | 989 | { |
| 1018 | 990 | $this->getQueryBuilder()->in($params[0], $params[1]); |
| 1019 | - } |
|
| 1020 | - else |
|
| 991 | + } else |
|
| 1021 | 992 | { |
| 1022 | 993 | $this->getQueryBuilder()->where($params[0], $params[1]); |
| 1023 | 994 | } |
| 1024 | - } |
|
| 1025 | - else if (count($params) == 3) |
|
| 995 | + } else if (count($params) == 3) |
|
| 1026 | 996 | { |
| 1027 | 997 | $this->getQueryBuilder()->where($params[0], $params[1], $params[2]); |
| 1028 | - } |
|
| 1029 | - else |
|
| 998 | + } else |
|
| 1030 | 999 | { |
| 1031 | 1000 | if (is_array($params[1])) |
| 1032 | 1001 | { |
| 1033 | 1002 | $this->getQueryBuilder()->in($params[0], $params[1]); |
| 1034 | - } |
|
| 1035 | - else |
|
| 1003 | + } else |
|
| 1036 | 1004 | { |
| 1037 | 1005 | $this->getQueryBuilder()->where($params[0], $params[1]); |
| 1038 | 1006 | } |
@@ -153,14 +153,12 @@ discard block |
||
| 153 | 153 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
| 154 | 154 | $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
| 155 | 155 | return true; |
| 156 | - } |
|
| 157 | - catch (PDOException $e){ |
|
| 156 | + } catch (PDOException $e){ |
|
| 158 | 157 | $this->logger->fatal($e->getMessage()); |
| 159 | 158 | show_error('Cannot connect to Database.'); |
| 160 | 159 | return false; |
| 161 | 160 | } |
| 162 | - } |
|
| 163 | - else{ |
|
| 161 | + } else{ |
|
| 164 | 162 | show_error('Database configuration is not set.'); |
| 165 | 163 | return false; |
| 166 | 164 | } |
@@ -203,8 +201,7 @@ discard block |
||
| 203 | 201 | $query = $this->getAll(true); |
| 204 | 202 | if ($returnSQLQueryOrResultType === true){ |
| 205 | 203 | return $query; |
| 206 | - } |
|
| 207 | - else{ |
|
| 204 | + } else{ |
|
| 208 | 205 | return $this->query($query, false, $returnSQLQueryOrResultType == 'array'); |
| 209 | 206 | } |
| 210 | 207 | } |
@@ -628,15 +625,13 @@ discard block |
||
| 628 | 625 | //if need return all result like list of record |
| 629 | 626 | if (is_bool($all) && $all){ |
| 630 | 627 | $this->result = ($array === false) ? $pdoStatment->fetchAll(PDO::FETCH_OBJ) : $pdoStatment->fetchAll(PDO::FETCH_ASSOC); |
| 631 | - } |
|
| 632 | - else{ |
|
| 628 | + } else{ |
|
| 633 | 629 | $this->result = ($array === false) ? $pdoStatment->fetch(PDO::FETCH_OBJ) : $pdoStatment->fetch(PDO::FETCH_ASSOC); |
| 634 | 630 | } |
| 635 | 631 | //Sqlite and pgsql always return 0 when using rowCount() |
| 636 | 632 | if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){ |
| 637 | 633 | $this->numRows = count($this->result); |
| 638 | - } |
|
| 639 | - else{ |
|
| 634 | + } else{ |
|
| 640 | 635 | $this->numRows = $pdoStatment->rowCount(); |
| 641 | 636 | } |
| 642 | 637 | } |
@@ -650,8 +645,7 @@ discard block |
||
| 650 | 645 | if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){ |
| 651 | 646 | $this->result = true; //to test the result for the query like UPDATE, INSERT, DELETE |
| 652 | 647 | $this->numRows = 1; //TODO use the correct method to get the exact affected row |
| 653 | - } |
|
| 654 | - else{ |
|
| 648 | + } else{ |
|
| 655 | 649 | $this->result = $pdoStatment->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
| 656 | 650 | $this->numRows = $pdoStatment->rowCount(); |
| 657 | 651 | } |
@@ -776,8 +770,7 @@ discard block |
||
| 776 | 770 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
| 777 | 771 | if ($logger !== null){ |
| 778 | 772 | $this->setLogger($logger); |
| 779 | - } |
|
| 780 | - else{ |
|
| 773 | + } else{ |
|
| 781 | 774 | $this->logger =& class_loader('Log', 'classes'); |
| 782 | 775 | $this->logger->setLogger('Library::Database'); |
| 783 | 776 | } |
@@ -790,8 +783,7 @@ discard block |
||
| 790 | 783 | protected function setQueryBuilderFromParamOrCreateNewInstance(DatabaseQueryBuilder $queryBuilder = null){ |
| 791 | 784 | if ($queryBuilder !== null){ |
| 792 | 785 | $this->setQueryBuilder($queryBuilder); |
| 793 | - } |
|
| 794 | - else{ |
|
| 786 | + } else{ |
|
| 795 | 787 | $this->queryBuilder =& class_loader('DatabaseQueryBuilder', 'classes'); |
| 796 | 788 | } |
| 797 | 789 | } |
@@ -225,8 +225,7 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | if (empty($this->join)){ |
| 227 | 227 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 228 | - } |
|
| 229 | - else{ |
|
| 228 | + } else{ |
|
| 230 | 229 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 231 | 230 | } |
| 232 | 231 | return $this; |
@@ -334,8 +333,7 @@ discard block |
||
| 334 | 333 | $whereStr = ''; |
| 335 | 334 | if (is_array($where)){ |
| 336 | 335 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 337 | - } |
|
| 338 | - else{ |
|
| 336 | + } else{ |
|
| 339 | 337 | if (is_array($op)){ |
| 340 | 338 | $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
| 341 | 339 | } else { |
@@ -585,8 +583,7 @@ discard block |
||
| 585 | 583 | } |
| 586 | 584 | if (! is_null($limitEnd)){ |
| 587 | 585 | $this->limit = $limit . ', ' . $limitEnd; |
| 588 | - } |
|
| 589 | - else{ |
|
| 586 | + } else{ |
|
| 590 | 587 | $this->limit = $limit; |
| 591 | 588 | } |
| 592 | 589 | return $this; |
@@ -601,8 +598,7 @@ discard block |
||
| 601 | 598 | public function orderBy($orderBy, $orderDir = ' ASC'){ |
| 602 | 599 | if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
| 603 | 600 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 604 | - } |
|
| 605 | - else{ |
|
| 601 | + } else{ |
|
| 606 | 602 | $this->orderBy = empty($this->orderBy) |
| 607 | 603 | ? ($orderBy . ' ' . strtoupper($orderDir)) |
| 608 | 604 | : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
@@ -618,8 +614,7 @@ discard block |
||
| 618 | 614 | public function groupBy($field){ |
| 619 | 615 | if (is_array($field)){ |
| 620 | 616 | $this->groupBy = implode(', ', $field); |
| 621 | - } |
|
| 622 | - else{ |
|
| 617 | + } else{ |
|
| 623 | 618 | $this->groupBy = $field; |
| 624 | 619 | } |
| 625 | 620 | return $this; |
@@ -636,14 +631,12 @@ discard block |
||
| 636 | 631 | public function having($field, $op = null, $val = null, $escape = true){ |
| 637 | 632 | if (is_array($op)){ |
| 638 | 633 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
| 639 | - } |
|
| 640 | - else if (! in_array($op, $this->operatorList)){ |
|
| 634 | + } else if (! in_array($op, $this->operatorList)){ |
|
| 641 | 635 | if (is_null($op)){ |
| 642 | 636 | $op = ''; |
| 643 | 637 | } |
| 644 | 638 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
| 645 | - } |
|
| 646 | - else{ |
|
| 639 | + } else{ |
|
| 647 | 640 | if (is_null($val)){ |
| 648 | 641 | $val = ''; |
| 649 | 642 | } |