@@ -45,7 +45,7 @@ |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | private function getAllPossiblePaths() { |
| 48 | - return AmbiguityException::getAllPossiblePathsRec($this->paths); |
|
| 48 | + return AmbiguityException::getAllPossiblePathsRec($this->paths); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static function getAllPossiblePathsRec($sub_table_paths) |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | public function explainAmbiguity() { |
| 20 | 20 | $all_paths = $this->getAllPossiblePaths(); |
| 21 | 21 | |
| 22 | - $i=0; |
|
| 22 | + $i = 0; |
|
| 23 | 23 | $width_px = 0; |
| 24 | 24 | $height_px = 0; |
| 25 | 25 | $global_height_px = 0; |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | private static function getAllPossiblePathsRec($sub_table_paths) |
| 52 | 52 | { |
| 53 | - if (count($sub_table_paths)==0) |
|
| 53 | + if (count($sub_table_paths) == 0) |
|
| 54 | 54 | return array(); |
| 55 | 55 | |
| 56 | 56 | $table_path = array_shift($sub_table_paths); |
| 57 | - $possible_sub_paths = AmbiguityException::getAllPossiblePathsRec($sub_table_paths); |
|
| 57 | + $possible_sub_paths = AmbiguityException::getAllPossiblePathsRec($sub_table_paths); |
|
| 58 | 58 | $return_table_paths = array(); |
| 59 | 59 | foreach ($table_path['paths'] as $path) { |
| 60 | 60 | if (count($possible_sub_paths)>0) |
@@ -50,8 +50,9 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | private static function getAllPossiblePathsRec($sub_table_paths) |
| 52 | 52 | { |
| 53 | - if (count($sub_table_paths)==0) |
|
| 54 | - return array(); |
|
| 53 | + if (count($sub_table_paths)==0) { |
|
| 54 | + return array(); |
|
| 55 | + } |
|
| 55 | 56 | |
| 56 | 57 | $table_path = array_shift($sub_table_paths); |
| 57 | 58 | $possible_sub_paths = AmbiguityException::getAllPossiblePathsRec($sub_table_paths); |
@@ -63,9 +64,9 @@ discard block |
||
| 63 | 64 | { |
| 64 | 65 | $return_table_paths[] = array_merge(array(array('paths'=>array($path))), $possible_sub_path); |
| 65 | 66 | } |
| 67 | + } else { |
|
| 68 | + $return_table_paths[] = array(array('paths'=>array($path))); |
|
| 66 | 69 | } |
| 67 | - else |
|
| 68 | - $return_table_paths[] = array(array('paths'=>array($path))); |
|
| 69 | 70 | } |
| 70 | 71 | return $return_table_paths; |
| 71 | 72 | } |
@@ -65,9 +65,9 @@ |
||
| 65 | 65 | * @param string $func_name |
| 66 | 66 | * @param $values |
| 67 | 67 | * @return array|void |
| 68 | - * @throws TDBMException |
|
| 68 | + * @throws TDBMException |
|
| 69 | 69 | */ |
| 70 | - public function __call($func_name, $values) { |
|
| 70 | + public function __call($func_name, $values) { |
|
| 71 | 71 | |
| 72 | 72 | if (strpos($func_name,"getarray_") === 0) { |
| 73 | 73 | $column = substr($func_name, 9); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | class TDBMObjectArray extends \ArrayObject implements \JsonSerializable { |
| 29 | 29 | public function __get($var) { |
| 30 | 30 | $cnt = count($this); |
| 31 | - if ($cnt==1) |
|
| 31 | + if ($cnt == 1) |
|
| 32 | 32 | { |
| 33 | 33 | return $this[0]->__get($var); |
| 34 | 34 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | public function __set($var, $value) { |
| 46 | 46 | $cnt = count($this); |
| 47 | - if ($cnt==1) |
|
| 47 | + if ($cnt == 1) |
|
| 48 | 48 | { |
| 49 | 49 | return $this[0]->__set($var, $value); |
| 50 | 50 | } |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function __call($func_name, $values) { |
| 71 | 71 | |
| 72 | - if (strpos($func_name,"getarray_") === 0) { |
|
| 72 | + if (strpos($func_name, "getarray_") === 0) { |
|
| 73 | 73 | $column = substr($func_name, 9); |
| 74 | 74 | return $this->getarray($column); |
| 75 | - } elseif (strpos($func_name,"setarray_") === 0) { |
|
| 75 | + } elseif (strpos($func_name, "setarray_") === 0) { |
|
| 76 | 76 | $column = substr($func_name, 9); |
| 77 | 77 | return $this->setarray($column, $values[0]); |
| 78 | - } elseif (count($this)==1) { |
|
| 78 | + } elseif (count($this) == 1) { |
|
| 79 | 79 | $this[0]->__call($func_name, $values); |
| 80 | 80 | } |
| 81 | 81 | else |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public function jsonSerialize(){ |
|
| 102 | + public function jsonSerialize() { |
|
| 103 | 103 | return (array) $this; |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -31,12 +31,10 @@ discard block |
||
| 31 | 31 | if ($cnt==1) |
| 32 | 32 | { |
| 33 | 33 | return $this[0]->__get($var); |
| 34 | - } |
|
| 35 | - elseif ($cnt>1) |
|
| 34 | + } elseif ($cnt>1) |
|
| 36 | 35 | { |
| 37 | 36 | throw new TDBMException('Array contains many objects! Use getarray_'.$var.' to retrieve an array of '.$var); |
| 38 | - } |
|
| 39 | - else |
|
| 37 | + } else |
|
| 40 | 38 | { |
| 41 | 39 | throw new TDBMException('Array contains no objects'); |
| 42 | 40 | } |
@@ -47,12 +45,10 @@ discard block |
||
| 47 | 45 | if ($cnt==1) |
| 48 | 46 | { |
| 49 | 47 | return $this[0]->__set($var, $value); |
| 50 | - } |
|
| 51 | - elseif ($cnt>1) |
|
| 48 | + } elseif ($cnt>1) |
|
| 52 | 49 | { |
| 53 | 50 | throw new TDBMException('Array contains many objects! Use setarray_'.$var.' to set the array of '.$var); |
| 54 | - } |
|
| 55 | - else |
|
| 51 | + } else |
|
| 56 | 52 | { |
| 57 | 53 | throw new TDBMException('Array contains no objects'); |
| 58 | 54 | } |
@@ -77,8 +73,7 @@ discard block |
||
| 77 | 73 | return $this->setarray($column, $values[0]); |
| 78 | 74 | } elseif (count($this)==1) { |
| 79 | 75 | $this[0]->__call($func_name, $values); |
| 80 | - } |
|
| 81 | - else |
|
| 76 | + } else |
|
| 82 | 77 | { |
| 83 | 78 | throw new TDBMException("Method ".$func_name." not found"); |
| 84 | 79 | } |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * @param string $columnName |
| 86 | 86 | * @param string $value |
| 87 | 87 | */ |
| 88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
| 88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
| 89 | 89 | $this->tableName = $tableName; |
| 90 | 90 | $this->columnName = $columnName; |
| 91 | 91 | $this->value = $value; |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * @param string $columnName |
| 86 | 86 | * @param string $value |
| 87 | 87 | */ |
| 88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
| 88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
| 89 | 89 | $this->tableName = $tableName; |
| 90 | 90 | $this->columnName = $columnName; |
| 91 | 91 | $this->value = $value; |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * @param string $columnName |
| 86 | 86 | * @param string $value |
| 87 | 87 | */ |
| 88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
| 88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
| 89 | 89 | $this->tableName = $tableName; |
| 90 | 90 | $this->columnName = $columnName; |
| 91 | 91 | $this->value = $value; |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * @param string $columnName |
| 86 | 86 | * @param string $value |
| 87 | 87 | */ |
| 88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
| 88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
| 89 | 89 | $this->tableName = $tableName; |
| 90 | 90 | $this->columnName = $columnName; |
| 91 | 91 | $this->value = $value; |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * @param string $columnName |
| 86 | 86 | * @param string $value |
| 87 | 87 | */ |
| 88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
| 88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
| 89 | 89 | $this->tableName = $tableName; |
| 90 | 90 | $this->columnName = $columnName; |
| 91 | 91 | $this->value = $value; |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * @param string $columnName |
| 86 | 86 | * @param string $value |
| 87 | 87 | */ |
| 88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
| 88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
| 89 | 89 | $this->tableName = $tableName; |
| 90 | 90 | $this->columnName = $columnName; |
| 91 | 91 | $this->value = $value; |
@@ -238,6 +238,9 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | + /** |
|
| 242 | + * @param string $var |
|
| 243 | + */ |
|
| 241 | 244 | public function __get($var) { |
| 242 | 245 | $this->_dbLoadIfNotLoaded(); |
| 243 | 246 | |
@@ -290,6 +293,10 @@ discard block |
||
| 290 | 293 | return isset($this->db_row[$var]); |
| 291 | 294 | } |
| 292 | 295 | |
| 296 | + /** |
|
| 297 | + * @param string $var |
|
| 298 | + * @param string|null $value |
|
| 299 | + */ |
|
| 293 | 300 | public function __set($var, $value) { |
| 294 | 301 | $this->_dbLoadIfNotLoaded(); |
| 295 | 302 | |
@@ -642,7 +649,7 @@ discard block |
||
| 642 | 649 | /** |
| 643 | 650 | * Returns the tables used in the filter in an array. |
| 644 | 651 | * |
| 645 | - * @return array<string> |
|
| 652 | + * @return string[] |
|
| 646 | 653 | */ |
| 647 | 654 | public function getUsedTables() { |
| 648 | 655 | return array($this->db_table_name); |
@@ -170,26 +170,26 @@ discard block |
||
| 170 | 170 | $this->TDBMObject_state = $state; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * Internal TDBM method, you should not use this. |
|
| 175 | - * Loads the db_row property of the object from the $row array. |
|
| 176 | - * Any row having a key starting with 'tdbm_reserved_col_' is ignored. |
|
| 177 | - * |
|
| 178 | - * @param array $row |
|
| 179 | - * @param array|null $colsArray A big optimization to avoid calling strpos to many times. This array should |
|
| 180 | - * contain as keys the list of interesting columns. If null, this list will be initialized. |
|
| 181 | - */ |
|
| 173 | + /** |
|
| 174 | + * Internal TDBM method, you should not use this. |
|
| 175 | + * Loads the db_row property of the object from the $row array. |
|
| 176 | + * Any row having a key starting with 'tdbm_reserved_col_' is ignored. |
|
| 177 | + * |
|
| 178 | + * @param array $row |
|
| 179 | + * @param array|null $colsArray A big optimization to avoid calling strpos to many times. This array should |
|
| 180 | + * contain as keys the list of interesting columns. If null, this list will be initialized. |
|
| 181 | + */ |
|
| 182 | 182 | public function loadFromRow($row, &$colsArray) { |
| 183 | - if ($colsArray === null) { |
|
| 184 | - foreach ($row as $key=>$value) { |
|
| 185 | - if (strpos($key, 'tdbm_reserved_col_')!==0) { |
|
| 186 | - $colsArray[$key] = true; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - $this->db_row = array_intersect_key($row, $colsArray); |
|
| 192 | - $this->TDBMObject_state = "loaded"; |
|
| 183 | + if ($colsArray === null) { |
|
| 184 | + foreach ($row as $key=>$value) { |
|
| 185 | + if (strpos($key, 'tdbm_reserved_col_')!==0) { |
|
| 186 | + $colsArray[$key] = true; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + $this->db_row = array_intersect_key($row, $colsArray); |
|
| 192 | + $this->TDBMObject_state = "loaded"; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -507,10 +507,10 @@ discard block |
||
| 507 | 507 | * |
| 508 | 508 | * @param string $func_name |
| 509 | 509 | * @param $values |
| 510 | - * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
|
| 511 | - * @throws TDBMException |
|
| 510 | + * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
|
| 511 | + * @throws TDBMException |
|
| 512 | 512 | */ |
| 513 | - public function __call($func_name, $values) { |
|
| 513 | + public function __call($func_name, $values) { |
|
| 514 | 514 | |
| 515 | 515 | if (strpos($func_name,"get_") === 0) { |
| 516 | 516 | $table = substr($func_name,4); |
@@ -545,48 +545,48 @@ discard block |
||
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
| 548 | - * Implements array behaviour for our object. |
|
| 549 | - * |
|
| 550 | - * @param string $offset |
|
| 551 | - * @param string $value |
|
| 552 | - */ |
|
| 548 | + * Implements array behaviour for our object. |
|
| 549 | + * |
|
| 550 | + * @param string $offset |
|
| 551 | + * @param string $value |
|
| 552 | + */ |
|
| 553 | 553 | public function offsetSet($offset, $value) { |
| 554 | 554 | $this->__set($offset, $value); |
| 555 | - } |
|
| 555 | + } |
|
| 556 | 556 | /** |
| 557 | 557 | * Implements array behaviour for our object. |
| 558 | 558 | * |
| 559 | 559 | * @param string $offset |
| 560 | - * @return bool |
|
| 560 | + * @return bool |
|
| 561 | 561 | */ |
| 562 | - public function offsetExists($offset) { |
|
| 563 | - $this->_dbLoadIfNotLoaded(); |
|
| 564 | - return isset($this->db_row[$offset]); |
|
| 565 | - } |
|
| 562 | + public function offsetExists($offset) { |
|
| 563 | + $this->_dbLoadIfNotLoaded(); |
|
| 564 | + return isset($this->db_row[$offset]); |
|
| 565 | + } |
|
| 566 | 566 | /** |
| 567 | 567 | * Implements array behaviour for our object. |
| 568 | 568 | * |
| 569 | 569 | * @param string $offset |
| 570 | 570 | */ |
| 571 | - public function offsetUnset($offset) { |
|
| 571 | + public function offsetUnset($offset) { |
|
| 572 | 572 | $this->__set($offset, null); |
| 573 | - } |
|
| 573 | + } |
|
| 574 | 574 | /** |
| 575 | 575 | * Implements array behaviour for our object. |
| 576 | 576 | * |
| 577 | 577 | * @param string $offset |
| 578 | - * @return mixed|null |
|
| 578 | + * @return mixed|null |
|
| 579 | 579 | */ |
| 580 | - public function offsetGet($offset) { |
|
| 581 | - return $this->__get($offset); |
|
| 582 | - } |
|
| 580 | + public function offsetGet($offset) { |
|
| 581 | + return $this->__get($offset); |
|
| 582 | + } |
|
| 583 | 583 | |
| 584 | 584 | private $_validIterator = false; |
| 585 | 585 | /** |
| 586 | 586 | * Implements iterator behaviour for our object (so we can each column). |
| 587 | 587 | */ |
| 588 | 588 | public function rewind() { |
| 589 | - $this->_dbLoadIfNotLoaded(); |
|
| 589 | + $this->_dbLoadIfNotLoaded(); |
|
| 590 | 590 | if (count($this->db_row)>0) { |
| 591 | 591 | $this->_validIterator = true; |
| 592 | 592 | } else { |
@@ -674,21 +674,21 @@ discard block |
||
| 674 | 674 | return $sql_where; |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | - /** |
|
| 678 | - * Override the native php clone function for TDBMObjects |
|
| 679 | - */ |
|
| 680 | - public function __clone(){ |
|
| 681 | - $this->_dbLoadIfNotLoaded(); |
|
| 682 | - //First lets set the status to new (to enter the save function) |
|
| 683 | - $this->TDBMObject_state = "new"; |
|
| 684 | - |
|
| 685 | - // Add the current TDBMObject to the save object list |
|
| 686 | - $this->tdbmService->_addToToSaveObjectList($this); |
|
| 687 | - |
|
| 688 | - //Now unset the PK from the row |
|
| 689 | - $pk_array = $this->getPrimaryKey(); |
|
| 690 | - foreach ($pk_array as $pk) { |
|
| 691 | - $this->db_row[$pk] = null; |
|
| 692 | - } |
|
| 693 | - } |
|
| 677 | + /** |
|
| 678 | + * Override the native php clone function for TDBMObjects |
|
| 679 | + */ |
|
| 680 | + public function __clone(){ |
|
| 681 | + $this->_dbLoadIfNotLoaded(); |
|
| 682 | + //First lets set the status to new (to enter the save function) |
|
| 683 | + $this->TDBMObject_state = "new"; |
|
| 684 | + |
|
| 685 | + // Add the current TDBMObject to the save object list |
|
| 686 | + $this->tdbmService->_addToToSaveObjectList($this); |
|
| 687 | + |
|
| 688 | + //Now unset the PK from the row |
|
| 689 | + $pk_array = $this->getPrimaryKey(); |
|
| 690 | + foreach ($pk_array as $pk) { |
|
| 691 | + $this->db_row[$pk] = null; |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | 694 | } |
| 695 | 695 | \ No newline at end of file |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param string $table_name |
| 110 | 110 | * @param mixed $id |
| 111 | 111 | */ |
| 112 | - public function __construct(TDBMService $tdbmService, $table_name, $id=false) { |
|
| 112 | + public function __construct(TDBMService $tdbmService, $table_name, $id = false) { |
|
| 113 | 113 | $this->tdbmService = $tdbmService; |
| 114 | 114 | $this->db_connection = $this->tdbmService->getConnection(); |
| 115 | 115 | $this->db_table_name = $table_name; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * $TDBMObject_state = "loaded" when the object is cached in memory. |
| 155 | 155 | * @return string |
| 156 | 156 | */ |
| 157 | - public function getTDBMObjectState(){ |
|
| 157 | + public function getTDBMObjectState() { |
|
| 158 | 158 | return $this->TDBMObject_state; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * $TDBMObject_state = "loaded" when the object is cached in memory. |
| 167 | 167 | * @param string $state |
| 168 | 168 | */ |
| 169 | - public function setTDBMObjectState($state){ |
|
| 169 | + public function setTDBMObjectState($state) { |
|
| 170 | 170 | $this->TDBMObject_state = $state; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | public function loadFromRow($row, &$colsArray) { |
| 183 | 183 | if ($colsArray === null) { |
| 184 | 184 | foreach ($row as $key=>$value) { |
| 185 | - if (strpos($key, 'tdbm_reserved_col_')!==0) { |
|
| 185 | + if (strpos($key, 'tdbm_reserved_col_') !== 0) { |
|
| 186 | 186 | $colsArray[$key] = true; |
| 187 | 187 | } |
| 188 | 188 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $result = $this->db_connection->query($sql); |
| 221 | 221 | |
| 222 | 222 | |
| 223 | - if ($result->rowCount()==0) |
|
| 223 | + if ($result->rowCount() == 0) |
|
| 224 | 224 | { |
| 225 | 225 | throw new TDBMException("Could not retrieve object from table \"$this->db_table_name\" with ID \"".$this->TDBMObject_id."\"."); |
| 226 | 226 | } |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | $result->closeCursor(); |
| 231 | 231 | |
| 232 | 232 | $this->db_row = array(); |
| 233 | - foreach ($fullCaseRow[0] as $key=>$value) { |
|
| 234 | - $this->db_row[$this->db_connection->toStandardCaseColumn($key)]=$value; |
|
| 233 | + foreach ($fullCaseRow[0] as $key=>$value) { |
|
| 234 | + $this->db_row[$this->db_connection->toStandardCaseColumn($key)] = $value; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $this->TDBMObject_state = "loaded"; |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | // Let's try to be accurate in error reporting. The checkColumnExist returns an array of closest matches. |
| 264 | 264 | $result_array = $column_exist; |
| 265 | 265 | |
| 266 | - if (count($result_array)==1) |
|
| 266 | + if (count($result_array) == 1) |
|
| 267 | 267 | $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'"; |
| 268 | 268 | else |
| 269 | - $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'"; |
|
| 269 | + $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '", $result_array)."'"; |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | throw new TDBMException($str); |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | $pk_array = $this->getPrimaryKey(); |
| 340 | 340 | |
| 341 | 341 | foreach ($pk_array as $pk) { |
| 342 | - if (isset($this->db_row[$pk]) && $this->db_row[$pk]!==null) { |
|
| 343 | - $pk_set=true; |
|
| 342 | + if (isset($this->db_row[$pk]) && $this->db_row[$pk] !== null) { |
|
| 343 | + $pk_set = true; |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | // if there are many columns for the PK, and none is set, we have no way to find the object back! |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | if (!$first) |
| 364 | 364 | $sql .= ','; |
| 365 | 365 | $sql .= $this->db_connection->quoteSmart($value); |
| 366 | - $first=false; |
|
| 366 | + $first = false; |
|
| 367 | 367 | } |
| 368 | 368 | $sql .= ')'; |
| 369 | 369 | |
@@ -391,12 +391,12 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // If there is only one column for the primary key, and if it has not been filled, let's find it. |
| 393 | 393 | // We assume this is the biggest ID in the database |
| 394 | - if (count($pk_array)==1 && !$pk_set) { |
|
| 394 | + if (count($pk_array) == 1 && !$pk_set) { |
|
| 395 | 395 | // FIXME: for PostgreSQL or MSSQL, the getInsertId call is not thread safe |
| 396 | 396 | // We should start a transaction before the insert |
| 397 | - $this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name,$pk_array[0]); |
|
| 397 | + $this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name, $pk_array[0]); |
|
| 398 | 398 | $this->db_row[$pk_array[0]] = $this->TDBMObject_id; |
| 399 | - } elseif (count($pk_array)==1 && $pk_set) { |
|
| 399 | + } elseif (count($pk_array) == 1 && $pk_set) { |
|
| 400 | 400 | $this->TDBMObject_id = $this->db_row[$pk_array[0]]; |
| 401 | 401 | } |
| 402 | 402 | |
@@ -423,24 +423,24 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | // Let's add this object to the list of objects in cache. |
| 425 | 425 | $this->tdbmService->_addToCache($this); |
| 426 | - } else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state==true) { |
|
| 426 | + } else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state == true) { |
|
| 427 | 427 | //$primary_key = $this->getPrimaryKey(); |
| 428 | 428 | // Let's first get the primary keys |
| 429 | 429 | $pk_table = $this->getPrimaryKey(); |
| 430 | 430 | // Now for the object_id |
| 431 | 431 | $object_id = $this->TDBMObject_id; |
| 432 | 432 | // If there is only one primary key: |
| 433 | - if (count($pk_table)==1) { |
|
| 433 | + if (count($pk_table) == 1) { |
|
| 434 | 434 | $sql_where = $this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
| 435 | 435 | } else { |
| 436 | 436 | $ids = unserialize($object_id); |
| 437 | - $i=0; |
|
| 437 | + $i = 0; |
|
| 438 | 438 | $sql_where_array = array(); |
| 439 | 439 | foreach ($pk_table as $pk) { |
| 440 | 440 | $sql_where_array[] = $this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]); |
| 441 | 441 | $i++; |
| 442 | 442 | } |
| 443 | - $sql_where = implode(" AND ",$sql_where_array); |
|
| 443 | + $sql_where = implode(" AND ", $sql_where_array); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | $sql = 'UPDATE '.$this->db_connection->escapeDBItem($this->db_table_name).' SET '; |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | if (!$first) |
| 451 | 451 | $sql .= ','; |
| 452 | 452 | $sql .= $this->db_connection->escapeDBItem($key)." = ".$this->db_connection->quoteSmart($value); |
| 453 | - $first=false; |
|
| 453 | + $first = false; |
|
| 454 | 454 | } |
| 455 | 455 | $sql .= ' WHERE '.$sql_where/*$primary_key."='".$this->db_row[$primary_key]."'"*/; |
| 456 | 456 | try { |
@@ -512,8 +512,8 @@ discard block |
||
| 512 | 512 | */ |
| 513 | 513 | public function __call($func_name, $values) { |
| 514 | 514 | |
| 515 | - if (strpos($func_name,"get_") === 0) { |
|
| 516 | - $table = substr($func_name,4); |
|
| 515 | + if (strpos($func_name, "get_") === 0) { |
|
| 516 | + $table = substr($func_name, 4); |
|
| 517 | 517 | } else { |
| 518 | 518 | throw new TDBMException("Method ".$func_name." not found"); |
| 519 | 519 | } |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | * Implement the unique JsonSerializable method |
| 625 | 625 | * @return array |
| 626 | 626 | */ |
| 627 | - public function jsonSerialize(){ |
|
| 627 | + public function jsonSerialize() { |
|
| 628 | 628 | $this->_dbLoadIfNotLoaded(); |
| 629 | 629 | return $this->db_row; |
| 630 | 630 | } |
@@ -653,23 +653,23 @@ discard block |
||
| 653 | 653 | * |
| 654 | 654 | * @return string |
| 655 | 655 | */ |
| 656 | - private function getPrimaryKeyWhereStatement () { |
|
| 656 | + private function getPrimaryKeyWhereStatement() { |
|
| 657 | 657 | // Let's first get the primary keys |
| 658 | 658 | $pk_table = $this->getPrimaryKey(); |
| 659 | 659 | // Now for the object_id |
| 660 | 660 | $object_id = $this->TDBMObject_id; |
| 661 | 661 | // If there is only one primary key: |
| 662 | - if (count($pk_table)==1) { |
|
| 662 | + if (count($pk_table) == 1) { |
|
| 663 | 663 | $sql_where = $this->db_connection->escapeDBItem($this->db_table_name).'.'.$this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
| 664 | 664 | } else { |
| 665 | 665 | $ids = unserialize($object_id); |
| 666 | - $i=0; |
|
| 666 | + $i = 0; |
|
| 667 | 667 | $sql_where_array = array(); |
| 668 | 668 | foreach ($pk_table as $pk) { |
| 669 | 669 | $sql_where_array[] = $this->db_connection->escapeDBItem($this->db_table_name).'.'.$this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]); |
| 670 | 670 | $i++; |
| 671 | 671 | } |
| 672 | - $sql_where = implode(" AND ",$sql_where_array); |
|
| 672 | + $sql_where = implode(" AND ", $sql_where_array); |
|
| 673 | 673 | } |
| 674 | 674 | return $sql_where; |
| 675 | 675 | } |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | /** |
| 678 | 678 | * Override the native php clone function for TDBMObjects |
| 679 | 679 | */ |
| 680 | - public function __clone(){ |
|
| 680 | + public function __clone() { |
|
| 681 | 681 | $this->_dbLoadIfNotLoaded(); |
| 682 | 682 | //First lets set the status to new (to enter the save function) |
| 683 | 683 | $this->TDBMObject_state = "new"; |
@@ -263,10 +263,11 @@ discard block |
||
| 263 | 263 | // Let's try to be accurate in error reporting. The checkColumnExist returns an array of closest matches. |
| 264 | 264 | $result_array = $column_exist; |
| 265 | 265 | |
| 266 | - if (count($result_array)==1) |
|
| 267 | - $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'"; |
|
| 268 | - else |
|
| 269 | - $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'"; |
|
| 266 | + if (count($result_array)==1) { |
|
| 267 | + $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'"; |
|
| 268 | + } else { |
|
| 269 | + $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'"; |
|
| 270 | + } |
|
| 270 | 271 | |
| 271 | 272 | |
| 272 | 273 | throw new TDBMException($str); |
@@ -348,10 +349,11 @@ discard block |
||
| 348 | 349 | if (count($pk_array)>1 && !$pk_set) { |
| 349 | 350 | $msg = "Error! You did not set the primary keys for the new object of type '$this->db_table_name'. TDBM usually assumes that the primary key is automatically set by the DB engine to the maximum value in the database. However, in this case, the '$this->db_table_name' table has a primary key on multiple columns. TDBM would be unable to find back this record after save. Please specify the primary keys for all new objects of kind '$this->db_table_name'."; |
| 350 | 351 | |
| 351 | - if (!$this->tdbmService->isProgramExiting()) |
|
| 352 | - throw new TDBMException($msg); |
|
| 353 | - else |
|
| 354 | - trigger_error($msg, E_USER_ERROR); |
|
| 352 | + if (!$this->tdbmService->isProgramExiting()) { |
|
| 353 | + throw new TDBMException($msg); |
|
| 354 | + } else { |
|
| 355 | + trigger_error($msg, E_USER_ERROR); |
|
| 356 | + } |
|
| 355 | 357 | } |
| 356 | 358 | |
| 357 | 359 | $sql = 'INSERT INTO '.$this->db_connection->escapeDBItem($this->db_table_name). |
@@ -360,8 +362,9 @@ discard block |
||
| 360 | 362 | |
| 361 | 363 | $first = true; |
| 362 | 364 | foreach ($this->db_row as $key=>$value) { |
| 363 | - if (!$first) |
|
| 364 | - $sql .= ','; |
|
| 365 | + if (!$first) { |
|
| 366 | + $sql .= ','; |
|
| 367 | + } |
|
| 365 | 368 | $sql .= $this->db_connection->quoteSmart($value); |
| 366 | 369 | $first=false; |
| 367 | 370 | } |
@@ -378,9 +381,9 @@ discard block |
||
| 378 | 381 | // trigger_error("program exiting"); |
| 379 | 382 | trigger_error($e->getMessage(), E_USER_ERROR); |
| 380 | 383 | |
| 381 | - if (!$this->tdbmService->isProgramExiting()) |
|
| 382 | - throw $e; |
|
| 383 | - else |
|
| 384 | + if (!$this->tdbmService->isProgramExiting()) { |
|
| 385 | + throw $e; |
|
| 386 | + } else |
|
| 384 | 387 | { |
| 385 | 388 | trigger_error($e->getMessage(), E_USER_ERROR); |
| 386 | 389 | } |
@@ -447,8 +450,9 @@ discard block |
||
| 447 | 450 | |
| 448 | 451 | $first = true; |
| 449 | 452 | foreach ($this->db_row as $key=>$value) { |
| 450 | - if (!$first) |
|
| 451 | - $sql .= ','; |
|
| 453 | + if (!$first) { |
|
| 454 | + $sql .= ','; |
|
| 455 | + } |
|
| 452 | 456 | $sql .= $this->db_connection->escapeDBItem($key)." = ".$this->db_connection->quoteSmart($value); |
| 453 | 457 | $first=false; |
| 454 | 458 | } |
@@ -456,10 +460,11 @@ discard block |
||
| 456 | 460 | try { |
| 457 | 461 | $this->db_connection->exec($sql); |
| 458 | 462 | } catch (TDBMException $e) { |
| 459 | - if (!$this->tdbmService->isProgramExiting()) |
|
| 460 | - throw $e; |
|
| 461 | - else |
|
| 462 | - trigger_error($e->getMessage(), E_USER_ERROR); |
|
| 463 | + if (!$this->tdbmService->isProgramExiting()) { |
|
| 464 | + throw $e; |
|
| 465 | + } else { |
|
| 466 | + trigger_error($e->getMessage(), E_USER_ERROR); |
|
| 467 | + } |
|
| 463 | 468 | } |
| 464 | 469 | |
| 465 | 470 | // Let's remove this object from the $new_objects static table. |
@@ -490,11 +495,13 @@ discard block |
||
| 490 | 495 | * |
| 491 | 496 | */ |
| 492 | 497 | public function discardChanges() { |
| 493 | - if ($this->TDBMObject_state == "new") |
|
| 494 | - throw new TDBMException("You cannot call discardChanges() on an object that has been created with getNewObject and that has not yet been saved."); |
|
| 498 | + if ($this->TDBMObject_state == "new") { |
|
| 499 | + throw new TDBMException("You cannot call discardChanges() on an object that has been created with getNewObject and that has not yet been saved."); |
|
| 500 | + } |
|
| 495 | 501 | |
| 496 | - if ($this->TDBMObject_state == "deleted") |
|
| 497 | - throw new TDBMException("You cannot call discardChanges() on an object that has been deleted."); |
|
| 502 | + if ($this->TDBMObject_state == "deleted") { |
|
| 503 | + throw new TDBMException("You cannot call discardChanges() on an object that has been deleted."); |
|
| 504 | + } |
|
| 498 | 505 | |
| 499 | 506 | $this->db_modified_state = false; |
| 500 | 507 | $this->TDBMObject_state = "not loaded"; |