@@ -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; |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | public static $box_height = 30; |
| 34 | 34 | public static $interspace_width = 10; |
| 35 | 35 | public static $interspace_height = 50; |
| 36 | - public static $text_height=13; |
|
| 37 | - public static $border =2; |
|
| 36 | + public static $text_height = 13; |
|
| 37 | + public static $border = 2; |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | private $parent_node; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public $width; |
| 48 | 48 | |
| 49 | - public function __construct($table_name, $parent_node=null, $link_type=null, $keyParent=null, $keyNode=null) { |
|
| 49 | + public function __construct($table_name, $parent_node = null, $link_type = null, $keyParent = null, $keyNode = null) { |
|
| 50 | 50 | $this->table_name = $table_name; |
| 51 | 51 | if ($parent_node !== null) { |
| 52 | 52 | $this->parent_node = $parent_node; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | public function computeWidth() { |
| 86 | - if (!is_array($this->children) || count($this->children)==0) { |
|
| 86 | + if (!is_array($this->children) || count($this->children) == 0) { |
|
| 87 | 87 | $this->width = 1; |
| 88 | 88 | return 1; |
| 89 | 89 | } else { |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function computeDepth($my_depth) { |
| 100 | - if (!is_array($this->children) || count($this->children)==0) { |
|
| 100 | + if (!is_array($this->children) || count($this->children) == 0) { |
|
| 101 | 101 | return $my_depth+1; |
| 102 | 102 | } else { |
| 103 | 103 | $max = 0; |
| 104 | 104 | foreach ($this->children as $child) { |
| 105 | - $depth = $my_depth + $child->computeDepth($my_depth); |
|
| 106 | - if ($depth > $max) { |
|
| 105 | + $depth = $my_depth+$child->computeDepth($my_depth); |
|
| 106 | + if ($depth>$max) { |
|
| 107 | 107 | $max = $depth; |
| 108 | 108 | } |
| 109 | 109 | } |
@@ -113,23 +113,23 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | public function draw($x, $y, $left_px, $top_px) { |
| 115 | 115 | |
| 116 | - $mybox_width_px = $this->width*DisplayNode::$box_width + ($this->width-1)*DisplayNode::$interspace_width; |
|
| 117 | - $my_x_px = $left_px + DisplayNode::$left_start + $x*(DisplayNode::$box_width + DisplayNode::$interspace_width); |
|
| 118 | - $my_y_px = $top_px + DisplayNode::$top_start + $y*(DisplayNode::$box_height + DisplayNode::$interspace_height); |
|
| 116 | + $mybox_width_px = $this->width*DisplayNode::$box_width+($this->width-1)*DisplayNode::$interspace_width; |
|
| 117 | + $my_x_px = $left_px+DisplayNode::$left_start+$x*(DisplayNode::$box_width+DisplayNode::$interspace_width); |
|
| 118 | + $my_y_px = $top_px+DisplayNode::$top_start+$y*(DisplayNode::$box_height+DisplayNode::$interspace_height); |
|
| 119 | 119 | |
| 120 | 120 | // White background first |
| 121 | 121 | $str = "<div style='position:absolute; left:".$my_x_px."px; top:".$my_y_px."px; width:".$mybox_width_px."px; height:".DisplayNode::$box_height."; background-color:gray; color: white; text-align:center; border:".DisplayNode::$border."px solid black'>\n<b>".$this->table_name."</b></div>"; |
| 122 | 122 | |
| 123 | 123 | if ($this->keyParent != null) { |
| 124 | - $my_x_px_line = $my_x_px + DisplayNode::$box_width/2; |
|
| 125 | - $my_y_px_line = $my_y_px - DisplayNode::$interspace_height; |
|
| 124 | + $my_x_px_line = $my_x_px+DisplayNode::$box_width/2; |
|
| 125 | + $my_y_px_line = $my_y_px-DisplayNode::$interspace_height; |
|
| 126 | 126 | $str .= "<div style='position:absolute; left:".$my_x_px_line."px; top:".($my_y_px_line+DisplayNode::$border)."px; width:2px; height:".(DisplayNode::$interspace_height-DisplayNode::$border)."; background-color:black; '></div>\n"; |
| 127 | 127 | |
| 128 | - $top_key = ($this->link_type=='1*')?'* fk:':'1 pk:'; |
|
| 128 | + $top_key = ($this->link_type == '1*') ? '* fk:' : '1 pk:'; |
|
| 129 | 129 | $top_key .= '<i>'.$this->keyParent.'</i>'; |
| 130 | 130 | |
| 131 | 131 | |
| 132 | - $bottom_key = ($this->link_type=='*1')?'* fk:':'1 pk:'; |
|
| 132 | + $bottom_key = ($this->link_type == '*1') ? '* fk:' : '1 pk:'; |
|
| 133 | 133 | $bottom_key .= '<i>'.$this->keyParent.'</i>'; |
| 134 | 134 | |
| 135 | 135 | $str .= "<div style='position:absolute; left:".($my_x_px_line+2)."px; top:".($my_y_px_line+DisplayNode::$border*2)."px; background-color:#EEEEEE; font-size: 10px'>$top_key</div>\n"; |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $baseBeanName = $this->getBaseBeanNameFromTableName($tableName); |
| 134 | 134 | |
| 135 | 135 | $connection = $this->dbConnection; |
| 136 | - if ($connection instanceof CachedConnection){ |
|
| 136 | + if ($connection instanceof CachedConnection) { |
|
| 137 | 137 | $connection->cacheService->purgeAll(); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | if($date === null) |
| 232 | 232 | return null; |
| 233 | 233 | else |
| 234 | - return strtotime($date'.($this->storeInUtc?'.\' UTC\'':'').'); |
|
| 234 | + return strtotime($date'.($this->storeInUtc ? '.\' UTC\'' : '').'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | if ($this->'.$array["col1"].' == null) { |
| 322 | 322 | return null; |
| 323 | 323 | } |
| 324 | - return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\","\\\\",$this->beanNamespace).'\\\\'.$referencedBeanName.'", true); |
|
| 324 | + return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\", "\\\\", $this->beanNamespace).'\\\\'.$referencedBeanName.'", true); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -340,10 +340,10 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | // Now, let's implement the shortcuts to the getter of objects. |
| 342 | 342 | // Shortcuts are used to save typing. They are available only if a referenced table is referenced only once by our tables. |
| 343 | - foreach($referencedTablesList as $referrencedTable=>$number) { |
|
| 343 | + foreach ($referencedTablesList as $referrencedTable=>$number) { |
|
| 344 | 344 | if ($number == 1) { |
| 345 | 345 | foreach ($constraints as $array) { |
| 346 | - if ($array['table2'] ==$referrencedTable) { |
|
| 346 | + if ($array['table2'] == $referrencedTable) { |
|
| 347 | 347 | $columnName = $array['col1']; |
| 348 | 348 | $targetColumnName = $array['col2']; |
| 349 | 349 | break; |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | if ($this->'.$array["col1"].' == null) { |
| 375 | 375 | return null; |
| 376 | 376 | } |
| 377 | - return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\","\\\\",$this->beanNamespace).'\\\\'.$referencedBeanName.'"); |
|
| 377 | + return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\", "\\\\", $this->beanNamespace).'\\\\'.$referencedBeanName.'"); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | { |
| 417 | 417 | |
| 418 | 418 | }"; |
| 419 | - file_put_contents($this->beanDirectory.$fileName ,$str); |
|
| 419 | + file_put_contents($this->beanDirectory.$fileName, $str); |
|
| 420 | 420 | @chmod($this->beanDirectory.$fileName, 0664); |
| 421 | 421 | } |
| 422 | 422 | } |
@@ -434,11 +434,11 @@ discard block |
||
| 434 | 434 | foreach ($info as $index => $data) { |
| 435 | 435 | $comments = $data['column_comment']; |
| 436 | 436 | $matches = array(); |
| 437 | - if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0){ |
|
| 437 | + if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) { |
|
| 438 | 438 | $defaultSort = $data['column_name']; |
| 439 | - if (count($matches == 3)){ |
|
| 439 | + if (count($matches == 3)) { |
|
| 440 | 440 | $defaultSortDirection = $matches[2]; |
| 441 | - }else{ |
|
| 441 | + } else { |
|
| 442 | 442 | $defaultSortDirection = 'ASC'; |
| 443 | 443 | } |
| 444 | 444 | } |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | |
| 668 | 668 | |
| 669 | 669 | |
| 670 | - file_put_contents($this->daoDirectory.$baseFileName ,$str); |
|
| 670 | + file_put_contents($this->daoDirectory.$baseFileName, $str); |
|
| 671 | 671 | @chmod($this->daoDirectory.$baseFileName, 0664); |
| 672 | 672 | |
| 673 | 673 | // Now, let's generate the "editable" class |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | { |
| 690 | 690 | |
| 691 | 691 | }"; |
| 692 | - file_put_contents($this->daoDirectory.$fileName ,$str); |
|
| 692 | + file_put_contents($this->daoDirectory.$fileName, $str); |
|
| 693 | 693 | @chmod($this->daoDirectory.$fileName, 0664); |
| 694 | 694 | } |
| 695 | 695 | } |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | ?>'; |
| 757 | 757 | |
| 758 | 758 | //$daoDirectory = dirname(__FILE__)."/../../../../../dao/"; |
| 759 | - file_put_contents($this->daoDirectory.$this->daoFactoryClassName.'.php' ,$str); |
|
| 759 | + file_put_contents($this->daoDirectory.$this->daoFactoryClassName.'.php', $str); |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | * @return string |
| 824 | 824 | */ |
| 825 | 825 | public static function toCamelCase($str) { |
| 826 | - $str = strtoupper(substr($str,0,1)).substr($str,1); |
|
| 826 | + $str = strtoupper(substr($str, 0, 1)).substr($str, 1); |
|
| 827 | 827 | while (true) { |
| 828 | 828 | if (strpos($str, "_") === false && strpos($str, " ") === false) |
| 829 | 829 | break; |
@@ -832,9 +832,9 @@ discard block |
||
| 832 | 832 | if ($pos === false) { |
| 833 | 833 | $pos = strpos($str, " "); |
| 834 | 834 | } |
| 835 | - $before = substr($str,0,$pos); |
|
| 836 | - $after = substr($str,$pos+1); |
|
| 837 | - $str = $before.strtoupper(substr($after,0,1)).substr($after,1); |
|
| 835 | + $before = substr($str, 0, $pos); |
|
| 836 | + $after = substr($str, $pos+1); |
|
| 837 | + $str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1); |
|
| 838 | 838 | } |
| 839 | 839 | return $str; |
| 840 | 840 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | private $cacheKey = "__TDBM_Cache__"; |
| 124 | 124 | |
| 125 | 125 | public function __construct() { |
| 126 | - register_shutdown_function(array($this,"completeSaveOnExit")); |
|
| 126 | + register_shutdown_function(array($this, "completeSaveOnExit")); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $objects = $this->getObjects($table_name, $filters, null, null, null, $className); |
| 327 | 327 | if (count($objects) == 0) { |
| 328 | 328 | return null; |
| 329 | - } elseif (count($objects) > 1) { |
|
| 329 | + } elseif (count($objects)>1) { |
|
| 330 | 330 | throw new DuplicateRowException("Error while querying an object for table '$table_name': ".count($objects)." rows have been returned, but we should have received at most one."); |
| 331 | 331 | } |
| 332 | 332 | // Return the first and only object. |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | if (isset($this->objects[$table_name][$id])) { |
| 353 | - $obj = $this->objects[$table_name][$id]; |
|
| 353 | + $obj = $this->objects[$table_name][$id]; |
|
| 354 | 354 | if ($className == null || is_a($obj, $className)) { |
| 355 | 355 | return $obj; |
| 356 | 356 | } else { |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | * @param string $className Optional: The name of the class to instanciate. This class must extend the TDBMObject class. If none is specified, a TDBMObject instance will be returned. |
| 396 | 396 | * @return TDBMObject |
| 397 | 397 | */ |
| 398 | - public function getNewObject($table_name, $auto_assign_id=true, $className = null) { |
|
| 398 | + public function getNewObject($table_name, $auto_assign_id = true, $className = null) { |
|
| 399 | 399 | if ($this->dbConnection == null) { |
| 400 | 400 | throw new TDBMException("Error while calling TDBMObject::getNewObject(): No connection has been established on the database!"); |
| 401 | 401 | } |
@@ -425,8 +425,8 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | if ($auto_assign_id && !$this->isPrimaryKeyAutoIncrement($table_name)) { |
| 428 | - $pk_table = $this->getPrimaryKeyStatic($table_name); |
|
| 429 | - if (count($pk_table)==1) |
|
| 428 | + $pk_table = $this->getPrimaryKeyStatic($table_name); |
|
| 429 | + if (count($pk_table) == 1) |
|
| 430 | 430 | { |
| 431 | 431 | $root_table = $this->dbConnection->findRootSequenceTable($table_name); |
| 432 | 432 | $id = $this->dbConnection->nextId($root_table); |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | $sql = "SELECT MAX(".$this->dbConnection->escapeDBItem($pk_table[0]).") AS maxkey FROM ".$root_table; |
| 437 | 437 | $res = $this->dbConnection->getAll($sql); |
| 438 | 438 | // NOTE: this will work only if the ID is an integer! |
| 439 | - $newid = $res[0]['maxkey'] + 1; |
|
| 439 | + $newid = $res[0]['maxkey']+1; |
|
| 440 | 440 | if ($newid>$id) { |
| 441 | 441 | $id = $newid; |
| 442 | 442 | } |
@@ -467,17 +467,17 @@ discard block |
||
| 467 | 467 | // Now for the object_id |
| 468 | 468 | $object_id = $object->TDBMObject_id; |
| 469 | 469 | // If there is only one primary key: |
| 470 | - if (count($pk_table)==1) { |
|
| 470 | + if (count($pk_table) == 1) { |
|
| 471 | 471 | $sql_where = $this->dbConnection->escapeDBItem($pk_table[0])."=".$this->dbConnection->quoteSmart($object->TDBMObject_id); |
| 472 | 472 | } else { |
| 473 | 473 | $ids = unserialize($object_id); |
| 474 | - $i=0; |
|
| 474 | + $i = 0; |
|
| 475 | 475 | $sql_where_array = array(); |
| 476 | 476 | foreach ($pk_table as $pk) { |
| 477 | 477 | $sql_where_array[] = $this->dbConnection->escapeDBItem($pk)."=".$this->dbConnection->quoteSmart($ids[$i]); |
| 478 | 478 | $i++; |
| 479 | 479 | } |
| 480 | - $sql_where = implode(" AND ",$sql_where_array); |
|
| 480 | + $sql_where = implode(" AND ", $sql_where_array); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | * @param string $className Optional: The name of the class to instanciate. This class must extend the TDBMObject class. If none is specified, a TDBMObject instance will be returned. |
| 521 | 521 | * @return TDBMObjectArray The result set of the query as a TDBMObjectArray (an array of TDBMObjects with special properties) |
| 522 | 522 | */ |
| 523 | - public function getObjectsFromSQL($table_name, $sql, $from=null, $limit=null, $className=null) { |
|
| 523 | + public function getObjectsFromSQL($table_name, $sql, $from = null, $limit = null, $className = null) { |
|
| 524 | 524 | if ($this->dbConnection == null) { |
| 525 | 525 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
| 526 | 526 | } |
@@ -540,17 +540,17 @@ discard block |
||
| 540 | 540 | |
| 541 | 541 | if ($firstLine) { |
| 542 | 542 | // $keysStandardCased is an optimization to avoid calling toStandardCaseColumn on every cell of every row. |
| 543 | - foreach ($fullCaseRow as $key=>$value) { |
|
| 543 | + foreach ($fullCaseRow as $key=>$value) { |
|
| 544 | 544 | $keysStandardCased[$key] = $this->dbConnection->toStandardCaseColumn($key); |
| 545 | 545 | } |
| 546 | 546 | $firstLine = false; |
| 547 | 547 | } |
| 548 | - foreach ($fullCaseRow as $key=>$value) { |
|
| 549 | - $row[$keysStandardCased[$key]]=$value; |
|
| 548 | + foreach ($fullCaseRow as $key=>$value) { |
|
| 549 | + $row[$keysStandardCased[$key]] = $value; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | $pk_table = $this->primary_keys[$table_name]; |
| 553 | - if (count($pk_table)==1) |
|
| 553 | + if (count($pk_table) == 1) |
|
| 554 | 554 | { |
| 555 | 555 | if (!isset($keysStandardCased[$pk_table[0]])) { |
| 556 | 556 | throw new TDBMException("Bad SQL request passed to getObjectsFromSQL. The SQL request should return all the rows from the '$table_name' table. Could not find primary key in this set of rows. SQL request passed: ".$sql); |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | $this->objects[$table_name][$id]->loadFromRow($row); |
| 586 | 586 | // Check that the object fetched from cache is from the requested class. |
| 587 | 587 | if ($className != null) { |
| 588 | - if (!is_subclass_of(get_class($this->objects[$table_name][$id]), $className) && get_class($this->objects[$table_name][$id]) != $className) { |
|
| 588 | + if (!is_subclass_of(get_class($this->objects[$table_name][$id]), $className) && get_class($this->objects[$table_name][$id]) != $className) { |
|
| 589 | 589 | throw new TDBMException("Error while calling TDBM: An object fetched from database is already present in TDBM cache and they do not share the same class. You requested the object to be of the class ".$className." but the object available locally is of the class ".get_class($this->objects[$table_name][$id])."."); |
| 590 | 590 | } |
| 591 | 591 | } |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | // Check that the object fetched from cache is from the requested class. |
| 594 | 594 | if ($className != null) { |
| 595 | 595 | $className = ltrim($className, '\\'); |
| 596 | - if (!is_subclass_of(get_class($this->objects[$table_name][$id]), $className) && get_class($this->objects[$table_name][$id]) != $className) { |
|
| 596 | + if (!is_subclass_of(get_class($this->objects[$table_name][$id]), $className) && get_class($this->objects[$table_name][$id]) != $className) { |
|
| 597 | 597 | throw new TDBMException("Error while calling TDBM: An object fetched from database is already present in TDBM cache and they do not share the same class. You requested the object to be of the class ".$className." but the object available locally is of the class ".get_class($this->objects[$table_name][$id])."."); |
| 598 | 598 | } |
| 599 | 599 | } |
@@ -676,14 +676,14 @@ discard block |
||
| 676 | 676 | // Now, let's commit or rollback if needed. |
| 677 | 677 | if ($this->dbConnection != null && $this->dbConnection->hasActiveTransaction()) { |
| 678 | 678 | if ($this->commitOnQuit) { |
| 679 | - try { |
|
| 679 | + try { |
|
| 680 | 680 | $this->dbConnection->commit(); |
| 681 | 681 | } catch (Exception $e) { |
| 682 | 682 | echo $e->getMessage()."<br/>"; |
| 683 | 683 | echo $e->getTraceAsString(); |
| 684 | 684 | } |
| 685 | 685 | } else { |
| 686 | - try { |
|
| 686 | + try { |
|
| 687 | 687 | $this->dbConnection->rollback(); |
| 688 | 688 | } catch (Exception $e) { |
| 689 | 689 | echo $e->getMessage()."<br/>"; |
@@ -754,21 +754,21 @@ discard block |
||
| 754 | 754 | * @param string $sql |
| 755 | 755 | * @return array the result of your query |
| 756 | 756 | */ |
| 757 | - public function getTransientObjectsFromSQL($sql,$classname=null) { |
|
| 757 | + public function getTransientObjectsFromSQL($sql, $classname = null) { |
|
| 758 | 758 | if ($this->dbConnection == null) { |
| 759 | 759 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
| 760 | 760 | } |
| 761 | - return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS,$classname); |
|
| 761 | + return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS, $classname); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
| 765 | 765 | private function to_explain_string($path) { |
| 766 | 766 | $msg = ''; |
| 767 | 767 | foreach ($path as $constraint) { |
| 768 | - if ($constraint['type']=='1*') { |
|
| 768 | + if ($constraint['type'] == '1*') { |
|
| 769 | 769 | $msg .= 'Table "'.$constraint['table1'].'" points to "'.$constraint['table2'].'" through its foreign key "'.$constraint['col1'].'"\n'; |
| 770 | 770 | } |
| 771 | - elseif ($constraint['type']=='*1') { |
|
| 771 | + elseif ($constraint['type'] == '*1') { |
|
| 772 | 772 | $msg .= 'Table "'.$constraint['table1'].'" is pointed by "'.$constraint['table2'].'" through its foreign key "'.$constraint['col2'].'"\n'; |
| 773 | 773 | } |
| 774 | 774 | } |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | $this->loadCache(); |
| 788 | 788 | |
| 789 | 789 | $path = array(); |
| 790 | - $queue = array(array($table,array())); |
|
| 790 | + $queue = array(array($table, array())); |
|
| 791 | 791 | |
| 792 | 792 | //$found_paths=array(); |
| 793 | 793 | $found = false; |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | { |
| 824 | 824 | break; |
| 825 | 825 | } |
| 826 | - if ($ret==true) |
|
| 826 | + if ($ret == true) |
|
| 827 | 827 | { |
| 828 | 828 | |
| 829 | 829 | // Ok, we got one, we will continue a bit more until we reach the next level in the tree, |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | // At each iteration, let's check the time. |
| 837 | - if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time > $max_execution_time && $max_execution_time!=0) { |
|
| 837 | + if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time>$max_execution_time && $max_execution_time != 0) { |
|
| 838 | 838 | // Call check table names |
| 839 | 839 | $this->checkTablesExist($tables); |
| 840 | 840 | |
@@ -845,11 +845,11 @@ discard block |
||
| 845 | 845 | } |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | - $ambiguity =false; |
|
| 848 | + $ambiguity = false; |
|
| 849 | 849 | $msg = ''; |
| 850 | 850 | foreach ($tables_paths as $table_path) { |
| 851 | 851 | // If any table has not been found, throw an exception |
| 852 | - if (!isset($table_path['founddepth']) || $table_path['founddepth']==null) { |
|
| 852 | + if (!isset($table_path['founddepth']) || $table_path['founddepth'] == null) { |
|
| 853 | 853 | // First, check if the tables do exist. |
| 854 | 854 | $this->checkTablesExist(array($table, $table_path['name'])); |
| 855 | 855 | // Else, throw an error. |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | 'table2' => $depArr['table1'], |
| 915 | 915 | 'col1' => $depArr['col2'], |
| 916 | 916 | 'col2' => $depArr['col1'], |
| 917 | - 'type' => (($depArr['type'] == '1*')?'*1':'1*') |
|
| 917 | + 'type' => (($depArr['type'] == '1*') ? '*1' : '1*') |
|
| 918 | 918 | ); |
| 919 | 919 | }, $toRevertPath); |
| 920 | 920 | return array_reverse($invertedDependencies); |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | * @param unknown_type $paths |
| 933 | 933 | */ |
| 934 | 934 | private function flatten_paths($paths) { |
| 935 | - $flat_path=array(); |
|
| 935 | + $flat_path = array(); |
|
| 936 | 936 | foreach ($paths as $path_bigarray) { |
| 937 | 937 | $path = $path_bigarray['paths'][0]; |
| 938 | 938 | |
@@ -973,9 +973,9 @@ discard block |
||
| 973 | 973 | //echo '-'.$current_table.'-'; |
| 974 | 974 | //echo '.'; |
| 975 | 975 | foreach ($target_tables as $id=>$target_table) { |
| 976 | - if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth']==null || $target_table['founddepth']==count($path))) { |
|
| 976 | + if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth'] == null || $target_table['founddepth'] == count($path))) { |
|
| 977 | 977 | // When a path is found to a table, we mark the table as found with its depth. |
| 978 | - $target_tables[$id]['founddepth']=count($path); |
|
| 978 | + $target_tables[$id]['founddepth'] = count($path); |
|
| 979 | 979 | |
| 980 | 980 | // Then we add the path to table to the target_tables array |
| 981 | 981 | $target_tables[$id]['paths'][] = $path; |
@@ -1015,13 +1015,13 @@ discard block |
||
| 1015 | 1015 | $already_done = false; |
| 1016 | 1016 | foreach ($path as $previous_constraint) |
| 1017 | 1017 | { |
| 1018 | - if ($previous_constraint['type']=='1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"]) |
|
| 1018 | + if ($previous_constraint['type'] == '1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"]) |
|
| 1019 | 1019 | { |
| 1020 | 1020 | //echo "YOUHOU1! $current_table $col2"; |
| 1021 | 1021 | $already_done = true; |
| 1022 | 1022 | break; |
| 1023 | 1023 | } |
| 1024 | - elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
| 1024 | + elseif ($previous_constraint['type'] == '*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
| 1025 | 1025 | { |
| 1026 | 1026 | //echo "YOUHOU2! $current_table $col2"; |
| 1027 | 1027 | $already_done = true; |
@@ -1054,13 +1054,13 @@ discard block |
||
| 1054 | 1054 | foreach ($path as $previous_constraint) |
| 1055 | 1055 | { |
| 1056 | 1056 | //echo "TTTT".$table2." ".$col2."AAAA".$previous_constraint["table1"]." ".$previous_constraint["col1"]."YYYY".$previous_constraint["type"]."PPP"; |
| 1057 | - if ($previous_constraint['type']=='1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"]) |
|
| 1057 | + if ($previous_constraint['type'] == '1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"]) |
|
| 1058 | 1058 | { |
| 1059 | 1059 | //echo "YOUHOU3! $table2 $col2"; |
| 1060 | 1060 | $already_done = true; |
| 1061 | 1061 | break; |
| 1062 | 1062 | } |
| 1063 | - elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
| 1063 | + elseif ($previous_constraint['type'] == '*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
| 1064 | 1064 | { |
| 1065 | 1065 | //echo "YOUHOU4! $table2 $col2"; |
| 1066 | 1066 | $already_done = true; |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
| 1171 | 1171 | * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
| 1172 | 1172 | */ |
| 1173 | - public function getObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) { |
|
| 1173 | + public function getObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) { |
|
| 1174 | 1174 | if ($this->dbConnection == null) { |
| 1175 | 1175 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
| 1176 | 1176 | } |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | * @param unknown_type $hint_path |
| 1187 | 1187 | * @return integer |
| 1188 | 1188 | */ |
| 1189 | - public function getCount($table_name, $filter_bag=null, $hint_path=null) { |
|
| 1189 | + public function getCount($table_name, $filter_bag = null, $hint_path = null) { |
|
| 1190 | 1190 | if ($this->dbConnection == null) { |
| 1191 | 1191 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
| 1192 | 1192 | } |
@@ -1204,7 +1204,7 @@ discard block |
||
| 1204 | 1204 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
| 1205 | 1205 | * @return string The SQL that would be executed. |
| 1206 | 1206 | */ |
| 1207 | - public function explainSQLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) { |
|
| 1207 | + public function explainSQLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) { |
|
| 1208 | 1208 | if ($this->dbConnection == null) { |
| 1209 | 1209 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
| 1210 | 1210 | } |
@@ -1222,7 +1222,7 @@ discard block |
||
| 1222 | 1222 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
| 1223 | 1223 | * @return string The SQL that would be executed. |
| 1224 | 1224 | */ |
| 1225 | - public function explainRequestAsTextGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) { |
|
| 1225 | + public function explainRequestAsTextGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) { |
|
| 1226 | 1226 | if ($this->dbConnection == null) { |
| 1227 | 1227 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
| 1228 | 1228 | } |
@@ -1243,12 +1243,12 @@ discard block |
||
| 1243 | 1243 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
| 1244 | 1244 | * @return string The SQL that would be executed. |
| 1245 | 1245 | */ |
| 1246 | - public function explainRequestAsHTMLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null, $x=10, $y=10) { |
|
| 1246 | + public function explainRequestAsHTMLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null, $x = 10, $y = 10) { |
|
| 1247 | 1247 | if ($this->dbConnection == null) { |
| 1248 | 1248 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
| 1249 | 1249 | } |
| 1250 | 1250 | $tree = $this->getObjectsByMode('explainTree', $table_name, $filter_bag, $orderby_bag, $from, $limit, $hint_path); |
| 1251 | - return $this->drawTree($tree,$x,$y); |
|
| 1251 | + return $this->drawTree($tree, $x, $y); |
|
| 1252 | 1252 | } |
| 1253 | 1253 | |
| 1254 | 1254 | /** |
@@ -1265,7 +1265,7 @@ discard block |
||
| 1265 | 1265 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
| 1266 | 1266 | * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
| 1267 | 1267 | */ |
| 1268 | - public function getObjectsByMode($mode, $table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) { |
|
| 1268 | + public function getObjectsByMode($mode, $table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) { |
|
| 1269 | 1269 | $this->completeSave(); |
| 1270 | 1270 | $this->loadCache(); |
| 1271 | 1271 | |
@@ -1304,7 +1304,7 @@ discard block |
||
| 1304 | 1304 | } |
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | - if (count($needed_table_array)==0) |
|
| 1307 | + if (count($needed_table_array) == 0) |
|
| 1308 | 1308 | { |
| 1309 | 1309 | $table_number = 1; |
| 1310 | 1310 | $sql = $this->dbConnection->escapeDBItem($table_name); //Make by Pierre PIV (add escapeDBItem) |
@@ -1313,14 +1313,14 @@ discard block |
||
| 1313 | 1313 | throw new TDBMException("TODO: explainTree not implemented for only one table."); |
| 1314 | 1314 | } |
| 1315 | 1315 | else { |
| 1316 | - if ($hint_path!=null && $mode != 'explainTree') |
|
| 1316 | + if ($hint_path != null && $mode != 'explainTree') |
|
| 1317 | 1317 | { |
| 1318 | 1318 | $path = $hint_path; |
| 1319 | 1319 | $flat_path = $this->flatten_paths($path); |
| 1320 | 1320 | } |
| 1321 | 1321 | else |
| 1322 | 1322 | { |
| 1323 | - $full_paths = $this->static_find_paths($table_name,$needed_table_array); |
|
| 1323 | + $full_paths = $this->static_find_paths($table_name, $needed_table_array); |
|
| 1324 | 1324 | |
| 1325 | 1325 | if ($mode == 'explainTree') { |
| 1326 | 1326 | return $this->getTablePathsTree($full_paths); |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | */ |
| 1374 | 1374 | $is_ok = true; |
| 1375 | 1375 | foreach ($path as $step) { |
| 1376 | - if ($step["type"]=="1*") { |
|
| 1376 | + if ($step["type"] == "1*") { |
|
| 1377 | 1377 | $is_ok = false; |
| 1378 | 1378 | break; |
| 1379 | 1379 | } |
@@ -1398,7 +1398,7 @@ discard block |
||
| 1398 | 1398 | $orderby_columns_array = array_merge($orderby_columns_array, $orderby_object->toSqlStatementsArray()); |
| 1399 | 1399 | } |
| 1400 | 1400 | |
| 1401 | - $orderby_statement = ' ORDER BY '.implode(',',$orderby_columns_array); |
|
| 1401 | + $orderby_statement = ' ORDER BY '.implode(',', $orderby_columns_array); |
|
| 1402 | 1402 | $count = 0; |
| 1403 | 1403 | foreach ($orderby_columns_array as $id=>$orderby_statement_phrase) { |
| 1404 | 1404 | // Let's remove the trailing ASC or DESC and add AS tdbm_reserved_col_Xxx |
@@ -1416,10 +1416,10 @@ discard block |
||
| 1416 | 1416 | $orderby_columns_array[$id] = $orderby_statement_phrase.' AS tdbm_reserved_col_'.$count; |
| 1417 | 1417 | $count++; |
| 1418 | 1418 | } |
| 1419 | - $orderby_column_statement = ', '.implode(',',$orderby_columns_array); |
|
| 1419 | + $orderby_column_statement = ', '.implode(',', $orderby_columns_array); |
|
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | - if ($mode=="getCount") { |
|
| 1422 | + if ($mode == "getCount") { |
|
| 1423 | 1423 | // Let's get the list of primary keys to perform a DISTINCT request. |
| 1424 | 1424 | $pk_table = $this->getPrimaryKeyStatic($table_name); |
| 1425 | 1425 | |
@@ -1453,7 +1453,7 @@ discard block |
||
| 1453 | 1453 | if ($mode == 'explainSQL') { |
| 1454 | 1454 | return $sql; |
| 1455 | 1455 | } |
| 1456 | - return $this->getObjectsFromSQL($table_name, $sql, $from, $limit, $className); |
|
| 1456 | + return $this->getObjectsFromSQL($table_name, $sql, $from, $limit, $className); |
|
| 1457 | 1457 | |
| 1458 | 1458 | } |
| 1459 | 1459 | |
@@ -1478,19 +1478,19 @@ discard block |
||
| 1478 | 1478 | // Second, let's take all the objects out of the filter bag, and let's make filters from them |
| 1479 | 1479 | $filter_bag2 = array(); |
| 1480 | 1480 | foreach ($filter_bag as $thing) { |
| 1481 | - if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) { |
|
| 1481 | + if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) { |
|
| 1482 | 1482 | $filter_bag2[] = $thing; |
| 1483 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\TDBMObject')) { |
|
| 1483 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObject')) { |
|
| 1484 | 1484 | $pk_table = $thing->getPrimaryKey(); |
| 1485 | 1485 | // If there is only one primary key: |
| 1486 | - if (count($pk_table)==1) { |
|
| 1486 | + if (count($pk_table) == 1) { |
|
| 1487 | 1487 | //$sql_where = "t1".$pk_table[0]."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
| 1488 | 1488 | $pkStr = $pk_table[0]; |
| 1489 | 1489 | $filter_bag2[] = new EqualFilter($thing->_getDbTableName(), $pk_table[0], $thing->$pkStr); |
| 1490 | 1490 | } else { |
| 1491 | 1491 | //$ids = unserialize($this->TDBMObject_id); |
| 1492 | 1492 | //$i=0; |
| 1493 | - $filter_bag_temp_and=array(); |
|
| 1493 | + $filter_bag_temp_and = array(); |
|
| 1494 | 1494 | foreach ($pk_table as $pk) { |
| 1495 | 1495 | $filter_bag_temp_and[] = new EqualFilter($thing->_getDbTableName(), $pk, $thing->$pk); |
| 1496 | 1496 | } |
@@ -1502,13 +1502,13 @@ discard block |
||
| 1502 | 1502 | //$filter_bag2[] = new EqualFilter($thing->_getDbTableName(), $primary_key, $thing->$primary_key); |
| 1503 | 1503 | } elseif (is_string($thing)) { |
| 1504 | 1504 | $filter_bag2[] = new SqlStringFilter($thing); |
| 1505 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) { |
|
| 1505 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) { |
|
| 1506 | 1506 | // Get table_name and column_name |
| 1507 | 1507 | $filter_table_name = $thing[0]->_getDbTableName(); |
| 1508 | 1508 | $filter_column_names = $thing[0]->getPrimaryKey(); |
| 1509 | 1509 | |
| 1510 | 1510 | // If there is only one primary key, we can use the InFilter |
| 1511 | - if (count($filter_column_names)==1) { |
|
| 1511 | + if (count($filter_column_names) == 1) { |
|
| 1512 | 1512 | $primary_keys_array = array(); |
| 1513 | 1513 | $filter_column_name = $filter_column_names[0]; |
| 1514 | 1514 | foreach ($thing as $TDBMObject) { |
@@ -1521,7 +1521,7 @@ discard block |
||
| 1521 | 1521 | { |
| 1522 | 1522 | $filter_bag_and = array(); |
| 1523 | 1523 | foreach ($thing as $TDBMObject) { |
| 1524 | - $filter_bag_temp_and=array(); |
|
| 1524 | + $filter_bag_temp_and = array(); |
|
| 1525 | 1525 | foreach ($filter_column_names as $pk) { |
| 1526 | 1526 | $filter_bag_temp_and[] = new EqualFilter($TDBMObject->_getDbTableName(), $pk, $TDBMObject->$pk); |
| 1527 | 1527 | } |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | 1533 | |
| 1534 | - } elseif (!is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing!==null) { |
|
| 1534 | + } elseif (!is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing !== null) { |
|
| 1535 | 1535 | throw new TDBMException("Error in filter bag in getObjectsByFilter. An object has been passed that is neither a filter, nor a TDBMObject, nor a TDBMObjectArray, nor a string, nor null."); |
| 1536 | 1536 | } |
| 1537 | 1537 | } |
@@ -1559,9 +1559,9 @@ discard block |
||
| 1559 | 1559 | // 4-2, let's take all the objects out of the orderby bag, and let's make objects from them |
| 1560 | 1560 | $orderby_bag2 = array(); |
| 1561 | 1561 | foreach ($orderby_bag as $thing) { |
| 1562 | - if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
| 1562 | + if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
| 1563 | 1563 | $orderby_bag2[] = $thing; |
| 1564 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
| 1564 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
| 1565 | 1565 | $orderby_bag2[] = $thing; |
| 1566 | 1566 | } elseif (is_string($thing)) { |
| 1567 | 1567 | $orderby_bag2[] = new OrderBySQLString($thing); |
@@ -1583,10 +1583,10 @@ discard block |
||
| 1583 | 1583 | $possible_tables = $this->dbConnection->checkTableExist($table); |
| 1584 | 1584 | if ($possible_tables !== true) |
| 1585 | 1585 | { |
| 1586 | - if (count($possible_tables)==1) |
|
| 1586 | + if (count($possible_tables) == 1) |
|
| 1587 | 1587 | $str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'"; |
| 1588 | 1588 | else |
| 1589 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'"; |
|
| 1589 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $possible_tables)."'"; |
|
| 1590 | 1590 | throw new TDBMException($str); |
| 1591 | 1591 | } |
| 1592 | 1592 | } |
@@ -1615,16 +1615,16 @@ discard block |
||
| 1615 | 1615 | $current_node = $tree; |
| 1616 | 1616 | $found = true; |
| 1617 | 1617 | foreach ($path as $link) { |
| 1618 | - if ($found==true) |
|
| 1618 | + if ($found == true) |
|
| 1619 | 1619 | { |
| 1620 | 1620 | if (is_array($current_node->getChildren())) |
| 1621 | 1621 | { |
| 1622 | 1622 | foreach ($current_node->getChildren() as $child) |
| 1623 | 1623 | { |
| 1624 | - if ($link['table1']==$child->table_name && |
|
| 1625 | - $link['col1']==$child->keyNode && |
|
| 1626 | - $link['col2']==$child->keyParent && |
|
| 1627 | - $link['type']==$child->link_type) { |
|
| 1624 | + if ($link['table1'] == $child->table_name && |
|
| 1625 | + $link['col1'] == $child->keyNode && |
|
| 1626 | + $link['col2'] == $child->keyParent && |
|
| 1627 | + $link['type'] == $child->link_type) { |
|
| 1628 | 1628 | $current_node = $child; |
| 1629 | 1629 | } |
| 1630 | 1630 | else |
@@ -1639,7 +1639,7 @@ discard block |
||
| 1639 | 1639 | |
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | - if ($found==false) |
|
| 1642 | + if ($found == false) |
|
| 1643 | 1643 | { |
| 1644 | 1644 | $current_node = new DisplayNode($link['table1'], $current_node, $link['type'], $link['col2'], $link['col1']); |
| 1645 | 1645 | /*if ($link['type']=='*1') |
@@ -1662,7 +1662,7 @@ discard block |
||
| 1662 | 1662 | * |
| 1663 | 1663 | * @param unknown_type $tree |
| 1664 | 1664 | */ |
| 1665 | - public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) { |
|
| 1665 | + public function drawTree($tree, $x, $y, &$ret_width = 0, &$ret_height = 0) { |
|
| 1666 | 1666 | |
| 1667 | 1667 | // Let's get the background div: |
| 1668 | 1668 | $treeDepth = $tree->computeDepth(1)-1; |
@@ -1673,7 +1673,7 @@ discard block |
||
| 1673 | 1673 | |
| 1674 | 1674 | $str = "<div style='position:absolute; left:".($x+DisplayNode::$left_start-DisplayNode::$border)."px; top:".($y+DisplayNode::$top_start-DisplayNode::$border)."px; width:".$ret_width."px; height:".$ret_height."; background-color:#EEEEEE; color: white; text-align:center;'></div>"; |
| 1675 | 1675 | |
| 1676 | - $str .= $tree->draw(0,0, $x, $y); |
|
| 1676 | + $str .= $tree->draw(0, 0, $x, $y); |
|
| 1677 | 1677 | |
| 1678 | 1678 | return $str; |
| 1679 | 1679 | |
@@ -1709,10 +1709,10 @@ discard block |
||
| 1709 | 1709 | if ($tables === true) |
| 1710 | 1710 | throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table."); |
| 1711 | 1711 | elseif ($tables !== null) { |
| 1712 | - if (count($tables)==1) |
|
| 1712 | + if (count($tables) == 1) |
|
| 1713 | 1713 | $str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'"; |
| 1714 | 1714 | else |
| 1715 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'"; |
|
| 1715 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $tables)."'"; |
|
| 1716 | 1716 | throw new TDBMException($str); |
| 1717 | 1717 | } |
| 1718 | 1718 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param string $table_name |
| 114 | 114 | * @param mixed $id |
| 115 | 115 | */ |
| 116 | - public function __construct(TDBMService $tdbmService, $table_name, $id=false) { |
|
| 116 | + public function __construct(TDBMService $tdbmService, $table_name, $id = false) { |
|
| 117 | 117 | $this->tdbmService = $tdbmService; |
| 118 | 118 | $this->db_connection = $this->tdbmService->getConnection(); |
| 119 | 119 | $this->db_table_name = $table_name; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * $TDBMObject_state = "loaded" when the object is cached in memory. |
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - public function getTDBMObjectState(){ |
|
| 162 | + public function getTDBMObjectState() { |
|
| 163 | 163 | return $this->TDBMObject_state; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * $TDBMObject_state = "loaded" when the object is cached in memory. |
| 172 | 172 | * @param string $state |
| 173 | 173 | */ |
| 174 | - public function setTDBMObjectState($state){ |
|
| 174 | + public function setTDBMObjectState($state) { |
|
| 175 | 175 | $this->TDBMObject_state = $state; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function loadFromRow($row) { |
| 186 | 186 | foreach ($row as $key=>$value) { |
| 187 | - if (strpos($key, 'tdbm_reserved_col_')!==0) { |
|
| 188 | - $this->db_row[$key]=$value; |
|
| 187 | + if (strpos($key, 'tdbm_reserved_col_') !== 0) { |
|
| 188 | + $this->db_row[$key] = $value; |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
@@ -219,24 +219,24 @@ discard block |
||
| 219 | 219 | // Now for the object_id |
| 220 | 220 | $object_id = $this->TDBMObject_id; |
| 221 | 221 | // If there is only one primary key: |
| 222 | - if (count($pk_table)==1) { |
|
| 222 | + if (count($pk_table) == 1) { |
|
| 223 | 223 | $sql_where = $this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
| 224 | 224 | } else { |
| 225 | 225 | $ids = unserialize($object_id); |
| 226 | - $i=0; |
|
| 226 | + $i = 0; |
|
| 227 | 227 | $sql_where_array = array(); |
| 228 | 228 | foreach ($pk_table as $pk) { |
| 229 | 229 | $sql_where_array[] = $this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]); |
| 230 | 230 | $i++; |
| 231 | 231 | } |
| 232 | - $sql_where = implode(" AND ",$sql_where_array); |
|
| 232 | + $sql_where = implode(" AND ", $sql_where_array); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $sql = "SELECT * FROM ".$this->db_connection->escapeDBItem($this->db_table_name)." WHERE ".$sql_where; |
| 236 | 236 | $result = $this->db_connection->query($sql); |
| 237 | 237 | |
| 238 | 238 | |
| 239 | - if ($result->rowCount()==0) |
|
| 239 | + if ($result->rowCount() == 0) |
|
| 240 | 240 | { |
| 241 | 241 | throw new TDBMException("Could not retrieve object from table \"$this->db_table_name\" with ID \"".$this->TDBMObject_id."\"."); |
| 242 | 242 | } |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | $result = null; |
| 248 | 248 | |
| 249 | 249 | $this->db_row = array(); |
| 250 | - foreach ($fullCaseRow[0] as $key=>$value) { |
|
| 251 | - $this->db_row[$this->db_connection->toStandardCaseColumn($key)]=$value; |
|
| 250 | + foreach ($fullCaseRow[0] as $key=>$value) { |
|
| 251 | + $this->db_row[$this->db_connection->toStandardCaseColumn($key)] = $value; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | $this->TDBMObject_state = "loaded"; |
@@ -280,10 +280,10 @@ discard block |
||
| 280 | 280 | // Let's try to be accurate in error reporting. The checkColumnExist returns an array of closest matches. |
| 281 | 281 | $result_array = $column_exist; |
| 282 | 282 | |
| 283 | - if (count($result_array)==1) |
|
| 283 | + if (count($result_array) == 1) |
|
| 284 | 284 | $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'"; |
| 285 | 285 | else |
| 286 | - $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'"; |
|
| 286 | + $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '", $result_array)."'"; |
|
| 287 | 287 | |
| 288 | 288 | |
| 289 | 289 | throw new TDBMException($str); |
@@ -356,8 +356,8 @@ discard block |
||
| 356 | 356 | $pk_array = $this->getPrimaryKey(); |
| 357 | 357 | |
| 358 | 358 | foreach ($pk_array as $pk) { |
| 359 | - if (isset($this->db_row[$pk]) && $this->db_row[$pk]!==null) { |
|
| 360 | - $pk_set=true; |
|
| 359 | + if (isset($this->db_row[$pk]) && $this->db_row[$pk] !== null) { |
|
| 360 | + $pk_set = true; |
|
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | // if there are many columns for the PK, and none is set, we have no way to find the object back! |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | if (!$first) |
| 381 | 381 | $sql .= ','; |
| 382 | 382 | $sql .= $this->db_connection->quoteSmart($value); |
| 383 | - $first=false; |
|
| 383 | + $first = false; |
|
| 384 | 384 | } |
| 385 | 385 | $sql .= ')'; |
| 386 | 386 | |
@@ -408,12 +408,12 @@ discard block |
||
| 408 | 408 | |
| 409 | 409 | // If there is only one column for the primary key, and if it has not been filled, let's find it. |
| 410 | 410 | // We assume this is the biggest ID in the database |
| 411 | - if (count($pk_array)==1 && !$pk_set) { |
|
| 411 | + if (count($pk_array) == 1 && !$pk_set) { |
|
| 412 | 412 | // FIXME: for PostgreSQL or MSSQL, the getInsertId call is not thread safe |
| 413 | 413 | // We should start a transaction before the insert |
| 414 | - $this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name,$pk_array[0]); |
|
| 414 | + $this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name, $pk_array[0]); |
|
| 415 | 415 | $this->db_row[$pk_array[0]] = $this->TDBMObject_id; |
| 416 | - } elseif (count($pk_array)==1 && $pk_set) { |
|
| 416 | + } elseif (count($pk_array) == 1 && $pk_set) { |
|
| 417 | 417 | $this->TDBMObject_id = $this->db_row[$pk_array[0]]; |
| 418 | 418 | } |
| 419 | 419 | |
@@ -440,24 +440,24 @@ discard block |
||
| 440 | 440 | |
| 441 | 441 | // Let's add this object to the list of objects in cache. |
| 442 | 442 | $this->tdbmService->_addToCache($this); |
| 443 | - } else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state==true) { |
|
| 443 | + } else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state == true) { |
|
| 444 | 444 | //$primary_key = $this->getPrimaryKey(); |
| 445 | 445 | // Let's first get the primary keys |
| 446 | 446 | $pk_table = $this->getPrimaryKey(); |
| 447 | 447 | // Now for the object_id |
| 448 | 448 | $object_id = $this->TDBMObject_id; |
| 449 | 449 | // If there is only one primary key: |
| 450 | - if (count($pk_table)==1) { |
|
| 450 | + if (count($pk_table) == 1) { |
|
| 451 | 451 | $sql_where = $this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
| 452 | 452 | } else { |
| 453 | 453 | $ids = unserialize($object_id); |
| 454 | - $i=0; |
|
| 454 | + $i = 0; |
|
| 455 | 455 | $sql_where_array = array(); |
| 456 | 456 | foreach ($pk_table as $pk) { |
| 457 | 457 | $sql_where_array[] = $this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]); |
| 458 | 458 | $i++; |
| 459 | 459 | } |
| 460 | - $sql_where = implode(" AND ",$sql_where_array); |
|
| 460 | + $sql_where = implode(" AND ", $sql_where_array); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | $sql = 'UPDATE '.$this->db_connection->escapeDBItem($this->db_table_name).' SET '; |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | if (!$first) |
| 468 | 468 | $sql .= ','; |
| 469 | 469 | $sql .= $this->db_connection->escapeDBItem($key)." = ".$this->db_connection->quoteSmart($value); |
| 470 | - $first=false; |
|
| 470 | + $first = false; |
|
| 471 | 471 | } |
| 472 | 472 | $sql .= ' WHERE '.$sql_where/*$primary_key."='".$this->db_row[$primary_key]."'"*/; |
| 473 | 473 | try { |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | */ |
| 530 | 530 | public function __call($func_name, $values) { |
| 531 | 531 | |
| 532 | - if (strpos($func_name,"get_") === 0) { |
|
| 533 | - $table = substr($func_name,4); |
|
| 532 | + if (strpos($func_name, "get_") === 0) { |
|
| 533 | + $table = substr($func_name, 4); |
|
| 534 | 534 | } else { |
| 535 | 535 | throw new TDBMException("Method ".$func_name." not found"); |
| 536 | 536 | } |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | * Implement the unique JsonSerializable method |
| 641 | 641 | * @return array |
| 642 | 642 | */ |
| 643 | - public function jsonSerialize(){ |
|
| 643 | + public function jsonSerialize() { |
|
| 644 | 644 | $this->_dbLoadIfNotLoaded(); |
| 645 | 645 | return $this->db_row; |
| 646 | 646 | } |