@@ -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 | } |
@@ -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); |
@@ -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"; |
@@ -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 | /** |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | |
326 | 326 | /** |
327 | 327 | * Saves the current object by INSERTing or UPDAT(E)ing it in the database. |
328 | - * |
|
329 | - * This method must be called only from the DAOs. |
|
330 | - * @internal |
|
328 | + * |
|
329 | + * This method must be called only from the DAOs. |
|
330 | + * @internal |
|
331 | 331 | */ |
332 | 332 | public function save() { |
333 | 333 | if (!is_array($this->db_row)) { |
@@ -510,10 +510,10 @@ discard block |
||
510 | 510 | * |
511 | 511 | * @param string $func_name |
512 | 512 | * @param $values |
513 | - * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
|
514 | - * @throws TDBMException |
|
513 | + * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
|
514 | + * @throws TDBMException |
|
515 | 515 | */ |
516 | - public function __call($func_name, $values) { |
|
516 | + public function __call($func_name, $values) { |
|
517 | 517 | |
518 | 518 | if (strpos($func_name,"get_") === 0) { |
519 | 519 | $table = substr($func_name,4); |
@@ -548,48 +548,48 @@ discard block |
||
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
551 | - * Implements array behaviour for our object. |
|
552 | - * |
|
553 | - * @param string $offset |
|
554 | - * @param string $value |
|
555 | - */ |
|
551 | + * Implements array behaviour for our object. |
|
552 | + * |
|
553 | + * @param string $offset |
|
554 | + * @param string $value |
|
555 | + */ |
|
556 | 556 | public function offsetSet($offset, $value) { |
557 | 557 | $this->__set($offset, $value); |
558 | - } |
|
558 | + } |
|
559 | 559 | /** |
560 | 560 | * Implements array behaviour for our object. |
561 | 561 | * |
562 | 562 | * @param string $offset |
563 | - * @return bool |
|
563 | + * @return bool |
|
564 | 564 | */ |
565 | - public function offsetExists($offset) { |
|
566 | - $this->_dbLoadIfNotLoaded(); |
|
567 | - return isset($this->db_row[$offset]); |
|
568 | - } |
|
565 | + public function offsetExists($offset) { |
|
566 | + $this->_dbLoadIfNotLoaded(); |
|
567 | + return isset($this->db_row[$offset]); |
|
568 | + } |
|
569 | 569 | /** |
570 | 570 | * Implements array behaviour for our object. |
571 | 571 | * |
572 | 572 | * @param string $offset |
573 | 573 | */ |
574 | - public function offsetUnset($offset) { |
|
574 | + public function offsetUnset($offset) { |
|
575 | 575 | $this->__set($offset, null); |
576 | - } |
|
576 | + } |
|
577 | 577 | /** |
578 | 578 | * Implements array behaviour for our object. |
579 | 579 | * |
580 | 580 | * @param string $offset |
581 | - * @return mixed|null |
|
581 | + * @return mixed|null |
|
582 | 582 | */ |
583 | - public function offsetGet($offset) { |
|
584 | - return $this->__get($offset); |
|
585 | - } |
|
583 | + public function offsetGet($offset) { |
|
584 | + return $this->__get($offset); |
|
585 | + } |
|
586 | 586 | |
587 | 587 | private $_validIterator = false; |
588 | 588 | /** |
589 | 589 | * Implements iterator behaviour for our object (so we can each column). |
590 | 590 | */ |
591 | 591 | public function rewind() { |
592 | - $this->_dbLoadIfNotLoaded(); |
|
592 | + $this->_dbLoadIfNotLoaded(); |
|
593 | 593 | if (count($this->db_row)>0) { |
594 | 594 | $this->_validIterator = true; |
595 | 595 | } else { |
@@ -677,21 +677,21 @@ discard block |
||
677 | 677 | return $sql_where; |
678 | 678 | } |
679 | 679 | |
680 | - /** |
|
681 | - * Override the native php clone function for TDBMObjects |
|
682 | - */ |
|
683 | - public function __clone(){ |
|
684 | - $this->_dbLoadIfNotLoaded(); |
|
685 | - //First lets set the status to new (to enter the save function) |
|
686 | - $this->TDBMObject_state = "new"; |
|
687 | - |
|
688 | - // Add the current TDBMObject to the save object list |
|
689 | - $this->tdbmService->_addToToSaveObjectList($this); |
|
690 | - |
|
691 | - //Now unset the PK from the row |
|
692 | - $pk_array = $this->getPrimaryKey(); |
|
693 | - foreach ($pk_array as $pk) { |
|
694 | - $this->db_row[$pk] = null; |
|
695 | - } |
|
696 | - } |
|
680 | + /** |
|
681 | + * Override the native php clone function for TDBMObjects |
|
682 | + */ |
|
683 | + public function __clone(){ |
|
684 | + $this->_dbLoadIfNotLoaded(); |
|
685 | + //First lets set the status to new (to enter the save function) |
|
686 | + $this->TDBMObject_state = "new"; |
|
687 | + |
|
688 | + // Add the current TDBMObject to the save object list |
|
689 | + $this->tdbmService->_addToToSaveObjectList($this); |
|
690 | + |
|
691 | + //Now unset the PK from the row |
|
692 | + $pk_array = $this->getPrimaryKey(); |
|
693 | + foreach ($pk_array as $pk) { |
|
694 | + $this->db_row[$pk] = null; |
|
695 | + } |
|
696 | + } |
|
697 | 697 | } |
698 | 698 | \ No newline at end of file |
@@ -166,7 +166,7 @@ |
||
166 | 166 | } |
167 | 167 | /** |
168 | 168 | * Returns the current result's _id |
169 | - * @return string The current result's _id as a string. |
|
169 | + * @return integer The current result's _id as a string. |
|
170 | 170 | */ |
171 | 171 | public function key() |
172 | 172 | { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | protected $current = false; |
57 | 57 | |
58 | - private $colsArray = null; |
|
58 | + private $colsArray = null; |
|
59 | 59 | |
60 | 60 | public function __construct(\PDOStatement $pdoStatement, ConnectionInterface $dbConnection, $primary_keys, $table_name, $objectStorage, $className, TDBMService $tdbmService, $sql) |
61 | 61 | { |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * Casts a document to a new instance specified in the $recordClass |
74 | 74 | * @param array $fullCaseRow |
75 | 75 | * @return Record_Abstract|false |
76 | - * @throws TDBMException |
|
76 | + * @throws TDBMException |
|
77 | 77 | */ |
78 | - protected function cast($fullCaseRow) |
|
78 | + protected function cast($fullCaseRow) |
|
79 | 79 | { |
80 | 80 | if (!is_array($fullCaseRow)) { |
81 | 81 | return false; |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | |
87 | 87 | if ($this->fetchStarted === false) { |
88 | 88 | // $keysStandardCased is an optimization to avoid calling toStandardCaseColumn on every cell of every row. |
89 | - foreach ($fullCaseRow as $key=>$value) { |
|
89 | + foreach ($fullCaseRow as $key=>$value) { |
|
90 | 90 | $this->keysStandardCased[$key] = $this->dbConnection->toStandardCaseColumn($key); |
91 | 91 | } |
92 | 92 | $this->fetchStarted = true; |
93 | 93 | } |
94 | - foreach ($fullCaseRow as $key=>$value) { |
|
95 | - $row[$this->keysStandardCased[$key]]=$value; |
|
94 | + foreach ($fullCaseRow as $key=>$value) { |
|
95 | + $row[$this->keysStandardCased[$key]] = $value; |
|
96 | 96 | } |
97 | 97 | |
98 | - if (count($this->primary_keys)==1) |
|
98 | + if (count($this->primary_keys) == 1) |
|
99 | 99 | { |
100 | 100 | if (!isset($this->keysStandardCased[$this->primary_keys[0]])) { |
101 | 101 | throw new TDBMException("Bad SQL request passed to getObjectsFromSQL. The SQL request should return all the rows from the '".$this->table_name."' table. Could not find primary key in this set of rows. SQL request passed: ".$this->sql); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $obj->loadFromRow($row, $this->colsArray); |
132 | 132 | // Check that the object fetched from cache is from the requested class. |
133 | 133 | if ($this->className != null) { |
134 | - if (!is_subclass_of(get_class($obj), $this->className) && get_class($obj) != $this->className) { |
|
134 | + if (!is_subclass_of(get_class($obj), $this->className) && get_class($obj) != $this->className) { |
|
135 | 135 | 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 ".$this->className." but the object available locally is of the class ".get_class($obj)."."); |
136 | 136 | } |
137 | 137 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | // Check that the object fetched from cache is from the requested class. |
140 | 140 | if ($this->className != null) { |
141 | 141 | $this->className = ltrim($this->className, '\\'); |
142 | - if (!is_subclass_of(get_class($obj), $this->className) && get_class($obj) != $this->className) { |
|
142 | + if (!is_subclass_of(get_class($obj), $this->className) && get_class($obj) != $this->className) { |
|
143 | 143 | 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 ".$this->className." but the object available locally is of the class ".get_class($obj)."."); |
144 | 144 | } |
145 | 145 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $this->current = false; |
186 | 186 | else |
187 | 187 | return true; |
188 | - }else |
|
188 | + } else |
|
189 | 189 | $this->current = false; |
190 | 190 | return false; |
191 | 191 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function valid() |
211 | 211 | { |
212 | - return ($this->current != false) || (($this->cursor == -1) && ($this->count() > 0)); |
|
212 | + return ($this->current != false) || (($this->cursor == -1) && ($this->count()>0)); |
|
213 | 213 | } |
214 | 214 | /** |
215 | 215 | * Fetches first record and rewinds the cursor |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function hasNext() |
228 | 228 | { |
229 | - return ($this->count() > 0) && (($this->cursor + 1) < $this->count()); |
|
229 | + return ($this->count()>0) && (($this->cursor+1)<$this->count()); |
|
230 | 230 | } |
231 | 231 | /** |
232 | 232 | * Return the next record to which this cursor points, and advance the cursor |
@@ -101,8 +101,7 @@ discard block |
||
101 | 101 | throw new TDBMException("Bad SQL request passed to getObjectsFromSQL. The SQL request should return all the rows from the '".$this->table_name."' table. Could not find primary key in this set of rows. SQL request passed: ".$this->sql); |
102 | 102 | } |
103 | 103 | $id = $row[$this->keysStandardCased[$this->primary_keys[0]]]; |
104 | - } |
|
105 | - else |
|
104 | + } else |
|
106 | 105 | { |
107 | 106 | // Let's generate the serialized primary key from the columns! |
108 | 107 | $ids = array(); |
@@ -181,12 +180,14 @@ discard block |
||
181 | 180 | if ($this->hasNext()) { |
182 | 181 | $this->cursor++; |
183 | 182 | $this->current = $this->pdoStatement->fetch(\PDO::FETCH_ASSOC); |
184 | - if (empty($this->current)) |
|
185 | - $this->current = false; |
|
186 | - else |
|
187 | - return true; |
|
188 | - }else |
|
189 | - $this->current = false; |
|
183 | + if (empty($this->current)) { |
|
184 | + $this->current = false; |
|
185 | + } else { |
|
186 | + return true; |
|
187 | + } |
|
188 | + } else { |
|
189 | + $this->current = false; |
|
190 | + } |
|
190 | 191 | return false; |
191 | 192 | } |
192 | 193 | |
@@ -259,10 +260,11 @@ discard block |
||
259 | 260 | $all = array(); |
260 | 261 | $this->rewind(); |
261 | 262 | foreach ($this->pdoStatement as $id => $doc) { |
262 | - if ($asRecords) |
|
263 | - $all[$id] = $this->cast($doc); |
|
264 | - else |
|
265 | - $all[$id] = $doc; |
|
263 | + if ($asRecords) { |
|
264 | + $all[$id] = $this->cast($doc); |
|
265 | + } else { |
|
266 | + $all[$id] = $doc; |
|
267 | + } |
|
266 | 268 | } |
267 | 269 | return $all; |
268 | 270 | } |
@@ -711,10 +711,10 @@ discard block |
||
711 | 711 | |
712 | 712 | /** |
713 | 713 | * Returns a generator for the database. |
714 | - * @param unknown $result |
|
714 | + * @param \PDOStatement $result |
|
715 | 715 | * @param unknown $table_name |
716 | - * @param unknown $className |
|
717 | - * @param unknown $sql |
|
716 | + * @param string $className |
|
717 | + * @param string $sql |
|
718 | 718 | */ |
719 | 719 | private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) { |
720 | 720 | $keysStandardCased = array(); |
@@ -1100,7 +1100,7 @@ discard block |
||
1100 | 1100 | * @param unknown_type $target_tables |
1101 | 1101 | * @param unknown_type $path |
1102 | 1102 | * @param unknown_type $queue |
1103 | - * @return unknown |
|
1103 | + * @return boolean |
|
1104 | 1104 | */ |
1105 | 1105 | private function find_paths_iter(&$target_tables, &$path, &$queue) { |
1106 | 1106 | // Get table to look at: |
@@ -1569,7 +1569,7 @@ discard block |
||
1569 | 1569 | * Takes in input a filter_bag (which can be about anything from a string to an array of TDBMObjects... see above from documentation), |
1570 | 1570 | * and gives back a proper Filter object. |
1571 | 1571 | * |
1572 | - * @param unknown_type $filter_bag |
|
1572 | + * @param unknown_type|null $filter_bag |
|
1573 | 1573 | * @return FilterInterface |
1574 | 1574 | */ |
1575 | 1575 | public function buildFilterFromFilterBag($filter_bag) { |
@@ -1634,7 +1634,7 @@ discard block |
||
1634 | 1634 | * Takes in input an order_bag (which can be about anything from a string to an array of OrderByColumn objects... see above from documentation), |
1635 | 1635 | * and gives back an array of OrderByColumn / OrderBySQLString objects. |
1636 | 1636 | * |
1637 | - * @param unknown_type $orderby_bag |
|
1637 | + * @param unknown_type|null $orderby_bag |
|
1638 | 1638 | * @return array |
1639 | 1639 | */ |
1640 | 1640 | public function buildOrderArrayFromOrderBag($orderby_bag) { |
@@ -1851,7 +1851,7 @@ discard block |
||
1851 | 1851 | * @param bool $support If the generated daos should keep support for old functions (eg : getUserList and getList) |
1852 | 1852 | * @param bool $storeInUtc If the generated daos should store the date in UTC timezone instead of user's timezone. |
1853 | 1853 | * @param bool $castDatesToDateTime |
1854 | - * @return \string[] the list of tables |
|
1854 | + * @return string[] the list of tables |
|
1855 | 1855 | */ |
1856 | 1856 | public function generateAllDaosAndBeans($daoFactoryClassName, $daonamespace, $beannamespace, $support, $storeInUtc, $castDatesToDateTime) { |
1857 | 1857 | $tdbmDaoGenerator = new TDBMDaoGenerator($this->dbConnection); |
@@ -28,7 +28,6 @@ |
||
28 | 28 | use Mouf\Utils\Cache\CacheInterface; |
29 | 29 | use Mouf\Database\TDBM\Filters\FilterInterface; |
30 | 30 | use Mouf\Database\DBConnection\ConnectionInterface; |
31 | -use Mouf\Database\DBConnection\DBConnectionException; |
|
32 | 31 | use Mouf\Database\TDBM\Filters\OrFilter; |
33 | 32 | use Mouf\Database\TDBM\Utils\TDBMDaoGenerator; |
34 | 33 |
@@ -456,10 +456,11 @@ discard block |
||
456 | 456 | /*$data =*/ $this->dbConnection->getTableInfo($table_name); |
457 | 457 | } catch (TDBMException $exception) { |
458 | 458 | $probable_table_name = $this->dbConnection->checkTableExist($table_name); |
459 | - if ($probable_table_name == null) |
|
460 | - throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist."); |
|
461 | - else |
|
462 | - throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist. Maybe you meant the table '$probable_table_name'."); |
|
459 | + if ($probable_table_name == null) { |
|
460 | + throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist."); |
|
461 | + } else { |
|
462 | + throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist. Maybe you meant the table '$probable_table_name'."); |
|
463 | + } |
|
463 | 464 | } |
464 | 465 | |
465 | 466 | if ($className === null) { |
@@ -537,8 +538,9 @@ discard block |
||
537 | 538 | $sql = 'DELETE FROM '.$this->dbConnection->escapeDBItem($object->_getDbTableName()).' WHERE '.$sql_where; |
538 | 539 | $result = $this->dbConnection->exec($sql); |
539 | 540 | |
540 | - if ($result != 1) |
|
541 | - throw new TDBMException("Error while deleting object from table ".$object->_getDbTableName().": ".$result." have been affected."); |
|
541 | + if ($result != 1) { |
|
542 | + throw new TDBMException("Error while deleting object from table ".$object->_getDbTableName().": ".$result." have been affected."); |
|
543 | + } |
|
542 | 544 | |
543 | 545 | $this->objectStorage->remove($object->_getDbTableName(), $object_id); |
544 | 546 | $object->setTDBMObjectState("deleted"); |
@@ -665,8 +667,7 @@ discard block |
||
665 | 667 | 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); |
666 | 668 | } |
667 | 669 | $id = $row[$keysStandardCased[$pk_table[0]]]; |
668 | - } |
|
669 | - else |
|
670 | + } else |
|
670 | 671 | { |
671 | 672 | // Let's generate the serialized primary key from the columns! |
672 | 673 | $ids = array(); |
@@ -740,8 +741,7 @@ discard block |
||
740 | 741 | 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); |
741 | 742 | } |
742 | 743 | $id = $row[$keysStandardCased[$pk_table[0]]]; |
743 | - } |
|
744 | - else |
|
744 | + } else |
|
745 | 745 | { |
746 | 746 | // Let's generate the serialized primary key from the columns! |
747 | 747 | $ids = array(); |
@@ -910,8 +910,7 @@ discard block |
||
910 | 910 | foreach ($path as $constraint) { |
911 | 911 | if ($constraint['type']=='1*') { |
912 | 912 | $msg .= 'Table "'.$constraint['table1'].'" points to "'.$constraint['table2'].'" through its foreign key "'.$constraint['col1'].'"\n'; |
913 | - } |
|
914 | - elseif ($constraint['type']=='*1') { |
|
913 | + } elseif ($constraint['type']=='*1') { |
|
915 | 914 | $msg .= 'Table "'.$constraint['table1'].'" is pointed by "'.$constraint['table2'].'" through its foreign key "'.$constraint['col2'].'"\n'; |
916 | 915 | } |
917 | 916 | } |
@@ -999,8 +998,9 @@ discard block |
||
999 | 998 | // If any table has more than 1 way to be reached, throw an exception. |
1000 | 999 | if (count($table_path['paths'])>1) { |
1001 | 1000 | // If this is the first ambiguity |
1002 | - if (!$ambiguity) |
|
1003 | - $msg .= 'An ambiguity has been found during the search. Please catch this exception and execute the $exception->explainAmbiguity() to get a nice graphical view of what you should do to solve this ambiguity.'; |
|
1001 | + if (!$ambiguity) { |
|
1002 | + $msg .= 'An ambiguity has been found during the search. Please catch this exception and execute the $exception->explainAmbiguity() to get a nice graphical view of what you should do to solve this ambiguity.'; |
|
1003 | + } |
|
1004 | 1004 | |
1005 | 1005 | $msg .= "The table \"".$table_path['name']."\" can be reached using several different ways from the table \"$table\".\n\n"; |
1006 | 1006 | $count = 0; |
@@ -1041,8 +1041,7 @@ discard block |
||
1041 | 1041 | if (isset($this->cache['paths'][$table1][$table2])) |
1042 | 1042 | { |
1043 | 1043 | return $this->cache['paths'][$table1][$table2]; |
1044 | - } |
|
1045 | - elseif (isset($this->cache['paths'][$table2][$table1])) |
|
1044 | + } elseif (isset($this->cache['paths'][$table2][$table1])) |
|
1046 | 1045 | { |
1047 | 1046 | // Let's revert the path! |
1048 | 1047 | $toRevertPath = $this->cache['paths'][$table2][$table1]; |
@@ -1087,8 +1086,9 @@ discard block |
||
1087 | 1086 | break; |
1088 | 1087 | } |
1089 | 1088 | } |
1090 | - if (!$found) |
|
1091 | - $flat_path[] = $path_step; |
|
1089 | + if (!$found) { |
|
1090 | + $flat_path[] = $path_step; |
|
1091 | + } |
|
1092 | 1092 | } |
1093 | 1093 | } |
1094 | 1094 | return $flat_path; |
@@ -1123,8 +1123,9 @@ discard block |
||
1123 | 1123 | } |
1124 | 1124 | } |
1125 | 1125 | |
1126 | - if ($found) |
|
1127 | - return true; |
|
1126 | + if ($found) { |
|
1127 | + return true; |
|
1128 | + } |
|
1128 | 1129 | } |
1129 | 1130 | |
1130 | 1131 | } |
@@ -1146,15 +1147,15 @@ discard block |
||
1146 | 1147 | { |
1147 | 1148 | $already_done = true; |
1148 | 1149 | break; |
1149 | - } |
|
1150 | - elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1150 | + } elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1151 | 1151 | { |
1152 | 1152 | $already_done = true; |
1153 | 1153 | break; |
1154 | 1154 | } |
1155 | 1155 | } |
1156 | - if ($already_done) |
|
1157 | - continue; |
|
1156 | + if ($already_done) { |
|
1157 | + continue; |
|
1158 | + } |
|
1158 | 1159 | |
1159 | 1160 | $new_path = array_merge($path, array(array("table1"=>$table1, |
1160 | 1161 | "col1"=>$col1, |
@@ -1179,15 +1180,15 @@ discard block |
||
1179 | 1180 | { |
1180 | 1181 | $already_done = true; |
1181 | 1182 | break; |
1182 | - } |
|
1183 | - elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1183 | + } elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1184 | 1184 | { |
1185 | 1185 | $already_done = true; |
1186 | 1186 | break; |
1187 | 1187 | } |
1188 | 1188 | } |
1189 | - if ($already_done) |
|
1190 | - continue; |
|
1189 | + if ($already_done) { |
|
1190 | + continue; |
|
1191 | + } |
|
1191 | 1192 | |
1192 | 1193 | $new_path = array_merge($path, array(array("table1"=>$table2, |
1193 | 1194 | "col1"=>$col2, |
@@ -1427,16 +1428,15 @@ discard block |
||
1427 | 1428 | { |
1428 | 1429 | $sql = $this->dbConnection->escapeDBItem($table_name); //Make by Pierre PIV (add escapeDBItem) |
1429 | 1430 | |
1430 | - if ($mode == 'explainTree') |
|
1431 | - throw new TDBMException("TODO: explainTree not implemented for only one table."); |
|
1432 | - } |
|
1433 | - else { |
|
1431 | + if ($mode == 'explainTree') { |
|
1432 | + throw new TDBMException("TODO: explainTree not implemented for only one table."); |
|
1433 | + } |
|
1434 | + } else { |
|
1434 | 1435 | if ($hint_path!=null && $mode != 'explainTree') |
1435 | 1436 | { |
1436 | 1437 | $path = $hint_path; |
1437 | 1438 | $flat_path = $this->flatten_paths($path); |
1438 | - } |
|
1439 | - else |
|
1439 | + } else |
|
1440 | 1440 | { |
1441 | 1441 | $full_paths = $this->static_find_paths($table_name,$needed_table_array); |
1442 | 1442 | |
@@ -1540,8 +1540,9 @@ discard block |
||
1540 | 1540 | $sql = "SELECT COUNT(DISTINCT $pk_str) FROM $sql"; |
1541 | 1541 | |
1542 | 1542 | $where_clause = $filter->toSql($this->dbConnection); |
1543 | - if ($where_clause != '') |
|
1544 | - $sql .= ' WHERE '.$where_clause; |
|
1543 | + if ($where_clause != '') { |
|
1544 | + $sql .= ' WHERE '.$where_clause; |
|
1545 | + } |
|
1545 | 1546 | |
1546 | 1547 | // Now, let's perform the request: |
1547 | 1548 | $result = $this->dbConnection->getOne($sql, array()); |
@@ -1552,8 +1553,9 @@ discard block |
||
1552 | 1553 | $sql = "SELECT DISTINCT ".$this->dbConnection->escapeDBItem($table_name).".* $orderby_column_statement FROM $sql"; |
1553 | 1554 | |
1554 | 1555 | $where_clause = $filter->toSql($this->dbConnection); |
1555 | - if ($where_clause != '') |
|
1556 | - $sql .= ' WHERE '.$where_clause; |
|
1556 | + if ($where_clause != '') { |
|
1557 | + $sql .= ' WHERE '.$where_clause; |
|
1558 | + } |
|
1557 | 1559 | |
1558 | 1560 | $sql .= $orderby_statement; |
1559 | 1561 | |
@@ -1578,8 +1580,7 @@ discard block |
||
1578 | 1580 | $filter_bag = array(); |
1579 | 1581 | } elseif (!is_array($filter_bag)) { |
1580 | 1582 | $filter_bag = array($filter_bag); |
1581 | - } |
|
1582 | - elseif (is_a($filter_bag, 'Mouf\\Database\\TDBM\\TDBMObjectArray')) { |
|
1583 | + } elseif (is_a($filter_bag, 'Mouf\\Database\\TDBM\\TDBMObjectArray')) { |
|
1583 | 1584 | $filter_bag = array($filter_bag); |
1584 | 1585 | } |
1585 | 1586 | |
@@ -1641,8 +1642,9 @@ discard block |
||
1641 | 1642 | // Fourth, let's apply the same steps to the orderby_bag |
1642 | 1643 | // 4-1 orderby_bag should be an array, if it is a singleton, let's put it in an array. |
1643 | 1644 | |
1644 | - if (!is_array($orderby_bag)) |
|
1645 | - $orderby_bag = array($orderby_bag); |
|
1645 | + if (!is_array($orderby_bag)) { |
|
1646 | + $orderby_bag = array($orderby_bag); |
|
1647 | + } |
|
1646 | 1648 | |
1647 | 1649 | // 4-2, let's take all the objects out of the orderby bag, and let's make objects from them |
1648 | 1650 | $orderby_bag2 = array(); |
@@ -1672,10 +1674,11 @@ discard block |
||
1672 | 1674 | $possible_tables = $this->dbConnection->checkTableExist($table); |
1673 | 1675 | if ($possible_tables !== true) |
1674 | 1676 | { |
1675 | - if (count($possible_tables)==1) |
|
1676 | - $str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'"; |
|
1677 | - else |
|
1678 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'"; |
|
1677 | + if (count($possible_tables)==1) { |
|
1678 | + $str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'"; |
|
1679 | + } else { |
|
1680 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'"; |
|
1681 | + } |
|
1679 | 1682 | throw new TDBMException($str); |
1680 | 1683 | } |
1681 | 1684 | } |
@@ -1709,16 +1712,15 @@ discard block |
||
1709 | 1712 | $link['col2']==$child->keyParent && |
1710 | 1713 | $link['type']==$child->link_type) { |
1711 | 1714 | $current_node = $child; |
1712 | - } |
|
1713 | - else |
|
1715 | + } else |
|
1714 | 1716 | { |
1715 | 1717 | // Now, we must add the rest of the links to the tree. |
1716 | 1718 | $found = false; |
1717 | 1719 | } |
1718 | 1720 | } |
1721 | + } else { |
|
1722 | + $found = false; |
|
1719 | 1723 | } |
1720 | - else |
|
1721 | - $found = false; |
|
1722 | 1724 | |
1723 | 1725 | } |
1724 | 1726 | |
@@ -1790,13 +1792,14 @@ discard block |
||
1790 | 1792 | // Unable to find primary key.... this is an error |
1791 | 1793 | // Let's try to be precise in error reporting. Let's try to find the table. |
1792 | 1794 | $tables = $this->dbConnection->checkTableExist($table); |
1793 | - if ($tables === true) |
|
1794 | - throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table."); |
|
1795 | - elseif ($tables !== null) { |
|
1796 | - if (count($tables)==1) |
|
1797 | - $str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'"; |
|
1798 | - else |
|
1799 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'"; |
|
1795 | + if ($tables === true) { |
|
1796 | + throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table."); |
|
1797 | + } elseif ($tables !== null) { |
|
1798 | + if (count($tables)==1) { |
|
1799 | + $str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'"; |
|
1800 | + } else { |
|
1801 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'"; |
|
1802 | + } |
|
1800 | 1803 | throw new TDBMException($str); |
1801 | 1804 | } |
1802 | 1805 | } |
@@ -545,45 +545,45 @@ discard block |
||
545 | 545 | } |
546 | 546 | } |
547 | 547 | |
548 | - /** |
|
549 | - * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
550 | - * by parameter before all. |
|
551 | - * |
|
552 | - * Notice: if the object has a multiple primary key, the function will not work. |
|
553 | - * |
|
554 | - * @param TDBMObject $objToDelete |
|
555 | - */ |
|
556 | - public function deleteCascade(TDBMObject $objToDelete) { |
|
557 | - $this->deleteAllConstraintWithThisObject($objToDelete); |
|
558 | - $this->deleteObject($objToDelete); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * This function is used only in TDBMService (private function) |
|
563 | - * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
564 | - * |
|
565 | - * @param TDBMObject $obj |
|
566 | - * @return TDBMObjectArray |
|
567 | - */ |
|
568 | - private function deleteAllConstraintWithThisObject(TDBMObject $obj) { |
|
569 | - $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName()); |
|
570 | - $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom); |
|
571 | - foreach ($constraints as $constraint) { |
|
572 | - $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]); |
|
573 | - $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]); |
|
574 | - $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]); |
|
575 | - $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]); |
|
576 | - $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id); |
|
577 | - $sql = "SELECT DISTINCT ".$tableTo.".*" |
|
578 | - ." FROM ".$tableFrom |
|
579 | - ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo |
|
580 | - ." WHERE ".$tableFrom.".".$idVarName."=".$idValue; |
|
581 | - $result = $this->getObjectsFromSQL($constraint["table1"], $sql); |
|
582 | - foreach ($result as $tdbmObj) { |
|
583 | - $this->deleteCascade($tdbmObj); |
|
584 | - } |
|
585 | - } |
|
586 | - } |
|
548 | + /** |
|
549 | + * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
550 | + * by parameter before all. |
|
551 | + * |
|
552 | + * Notice: if the object has a multiple primary key, the function will not work. |
|
553 | + * |
|
554 | + * @param TDBMObject $objToDelete |
|
555 | + */ |
|
556 | + public function deleteCascade(TDBMObject $objToDelete) { |
|
557 | + $this->deleteAllConstraintWithThisObject($objToDelete); |
|
558 | + $this->deleteObject($objToDelete); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * This function is used only in TDBMService (private function) |
|
563 | + * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
564 | + * |
|
565 | + * @param TDBMObject $obj |
|
566 | + * @return TDBMObjectArray |
|
567 | + */ |
|
568 | + private function deleteAllConstraintWithThisObject(TDBMObject $obj) { |
|
569 | + $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName()); |
|
570 | + $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom); |
|
571 | + foreach ($constraints as $constraint) { |
|
572 | + $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]); |
|
573 | + $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]); |
|
574 | + $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]); |
|
575 | + $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]); |
|
576 | + $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id); |
|
577 | + $sql = "SELECT DISTINCT ".$tableTo.".*" |
|
578 | + ." FROM ".$tableFrom |
|
579 | + ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo |
|
580 | + ." WHERE ".$tableFrom.".".$idVarName."=".$idValue; |
|
581 | + $result = $this->getObjectsFromSQL($constraint["table1"], $sql); |
|
582 | + foreach ($result as $tdbmObj) { |
|
583 | + $this->deleteCascade($tdbmObj); |
|
584 | + } |
|
585 | + } |
|
586 | + } |
|
587 | 587 | |
588 | 588 | /** |
589 | 589 | * The getObjectsFromSQL is used to retrieve objects from the database using a full SQL query. |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | } |
645 | 645 | $keysStandardCased = array(); |
646 | 646 | $firstLine = true; |
647 | - $colsArray = null; |
|
647 | + $colsArray = null; |
|
648 | 648 | while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC)) |
649 | 649 | { |
650 | 650 | $row = array(); |
@@ -676,17 +676,17 @@ discard block |
||
676 | 676 | $id = serialize($ids); |
677 | 677 | } |
678 | 678 | |
679 | - $obj = $this->objectStorage->get($table_name,$id); |
|
679 | + $obj = $this->objectStorage->get($table_name,$id); |
|
680 | 680 | if ($obj === null) |
681 | 681 | { |
682 | 682 | if (!is_a($className, "Mouf\\Database\\TDBM\\TDBMObject", true)) { |
683 | 683 | throw new TDBMException("Error while calling TDBM: The class ".$className." should extend TDBMObject."); |
684 | 684 | } |
685 | 685 | $obj = new $className($this, $table_name, $id); |
686 | - $obj->loadFromRow($row, $colsArray); |
|
687 | - $this->objectStorage->set($table_name, $id, $obj); |
|
686 | + $obj->loadFromRow($row, $colsArray); |
|
687 | + $this->objectStorage->set($table_name, $id, $obj); |
|
688 | 688 | } elseif ($obj->_getStatus() == "not loaded") { |
689 | - $obj->loadFromRow($row, $colsArray); |
|
689 | + $obj->loadFromRow($row, $colsArray); |
|
690 | 690 | // Check that the object fetched from cache is from the requested class. |
691 | 691 | if (!is_a($obj, $className)) { |
692 | 692 | 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($obj)."."); |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) { |
720 | 720 | $keysStandardCased = array(); |
721 | 721 | $firstLine = true; |
722 | - $colsArray = null; |
|
722 | + $colsArray = null; |
|
723 | 723 | while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC)) |
724 | 724 | { |
725 | 725 | $row = array(); |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | } |
751 | 751 | $id = serialize($ids); |
752 | 752 | } |
753 | - $obj = $this->objectStorage->get($table_name, $id); |
|
753 | + $obj = $this->objectStorage->get($table_name, $id); |
|
754 | 754 | if ($obj === null) |
755 | 755 | { |
756 | 756 | if ($className == null) { |
@@ -763,10 +763,10 @@ discard block |
||
763 | 763 | } else { |
764 | 764 | throw new TDBMException("Error while casting TDBMObject to class, the parameter passed is not a string. Value passed: ".$className); |
765 | 765 | } |
766 | - $obj->loadFromRow($row, $colsArray); |
|
767 | - $this->objectStorage->set($table_name, $id, $obj); |
|
766 | + $obj->loadFromRow($row, $colsArray); |
|
767 | + $this->objectStorage->set($table_name, $id, $obj); |
|
768 | 768 | } elseif ($obj->_getStatus() == "not loaded") { |
769 | - $obj->loadFromRow($row, $colsArray); |
|
769 | + $obj->loadFromRow($row, $colsArray); |
|
770 | 770 | // Check that the object fetched from cache is from the requested class. |
771 | 771 | if ($className != null) { |
772 | 772 | if (!is_subclass_of(get_class($obj), $className) && get_class($obj) != $className) { |
@@ -1466,33 +1466,33 @@ discard block |
||
1466 | 1466 | } |
1467 | 1467 | |
1468 | 1468 | //If no $hint_path is provided, check that a path exists |
1469 | - if($hint_path === null){ |
|
1470 | - // Now, for each needed table to perform the order by, we must verify if the relationship between the order by and the object is indeed a 1* relationship |
|
1471 | - foreach ($needed_table_array_for_orderby as $target_table_table) { |
|
1472 | - // Get the path between the main table and the target group by table |
|
1469 | + if($hint_path === null){ |
|
1470 | + // Now, for each needed table to perform the order by, we must verify if the relationship between the order by and the object is indeed a 1* relationship |
|
1471 | + foreach ($needed_table_array_for_orderby as $target_table_table) { |
|
1472 | + // Get the path between the main table and the target group by table |
|
1473 | 1473 | |
1474 | - // TODO! Pas bon!!!! Faut le quérir, hélas! |
|
1475 | - // Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni????? |
|
1474 | + // TODO! Pas bon!!!! Faut le quérir, hélas! |
|
1475 | + // Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni????? |
|
1476 | 1476 | |
1477 | - $path = $this->getPathFromCache($table_name, $target_table_table); |
|
1477 | + $path = $this->getPathFromCache($table_name, $target_table_table); |
|
1478 | 1478 | |
1479 | - /********************************** |
|
1479 | + /********************************** |
|
1480 | 1480 | * Modifier par Marc de *1 vers 1* |
1481 | 1481 | * (sur les conseils de David !) |
1482 | 1482 | */ |
1483 | - $is_ok = true; |
|
1484 | - foreach ($path as $step) { |
|
1485 | - if ($step["type"]=="1*") { |
|
1486 | - $is_ok = false; |
|
1487 | - break; |
|
1488 | - } |
|
1489 | - } |
|
1490 | - |
|
1491 | - if (!$is_ok) { |
|
1492 | - throw new TDBMException("Error in querying database from getObjectsByFilter. You tried to order your data according to a column of the '$target_table_table' table. However, the '$target_table_table' table has a many to 1 relationship with the '$table_name' table. This means that one '$table_name' object can contain many '$target_table_table' objects. Therefore, trying to order '$table_name' objects using '$target_table_table' objects is meaningless and cannot be performed."); |
|
1493 | - } |
|
1494 | - } |
|
1495 | - } |
|
1483 | + $is_ok = true; |
|
1484 | + foreach ($path as $step) { |
|
1485 | + if ($step["type"]=="1*") { |
|
1486 | + $is_ok = false; |
|
1487 | + break; |
|
1488 | + } |
|
1489 | + } |
|
1490 | + |
|
1491 | + if (!$is_ok) { |
|
1492 | + throw new TDBMException("Error in querying database from getObjectsByFilter. You tried to order your data according to a column of the '$target_table_table' table. However, the '$target_table_table' table has a many to 1 relationship with the '$table_name' table. This means that one '$table_name' object can contain many '$target_table_table' objects. Therefore, trying to order '$table_name' objects using '$target_table_table' objects is meaningless and cannot be performed."); |
|
1493 | + } |
|
1494 | + } |
|
1495 | + } |
|
1496 | 1496 | |
1497 | 1497 | // In a SELECT DISTINCT ... ORDER BY ... clause, the orderbyed columns must appear! |
1498 | 1498 | // Therefore, we must be able to parse the Orderby columns requested, give them dummy names and remove them afterward! |
@@ -1667,9 +1667,9 @@ discard block |
||
1667 | 1667 | * Throws a TDBMException if one of those table does not exist. |
1668 | 1668 | * |
1669 | 1669 | * @param array $tables |
1670 | - * @throws TDBMException |
|
1670 | + * @throws TDBMException |
|
1671 | 1671 | */ |
1672 | - private function checkTablesExist($tables) { |
|
1672 | + private function checkTablesExist($tables) { |
|
1673 | 1673 | foreach ($tables as $table) { |
1674 | 1674 | $possible_tables = $this->dbConnection->checkTableExist($table); |
1675 | 1675 | if ($possible_tables !== true) |
@@ -1742,12 +1742,12 @@ discard block |
||
1742 | 1742 | * This function returns the HTML to draw a tree of DisplayNode. |
1743 | 1743 | * |
1744 | 1744 | * @param DisplayNode $tree |
1745 | - * @param int $x |
|
1746 | - * @param int $y |
|
1747 | - * @param int $ret_width |
|
1748 | - * @param int $ret_height |
|
1749 | - * |
|
1750 | - * @return string |
|
1745 | + * @param int $x |
|
1746 | + * @param int $y |
|
1747 | + * @param int $ret_width |
|
1748 | + * @param int $ret_height |
|
1749 | + * |
|
1750 | + * @return string |
|
1751 | 1751 | */ |
1752 | 1752 | public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) { |
1753 | 1753 | |
@@ -1861,8 +1861,8 @@ discard block |
||
1861 | 1861 | } |
1862 | 1862 | |
1863 | 1863 | /** |
1864 | - * @param array<string, string> $tableToBeanMap |
|
1865 | - */ |
|
1864 | + * @param array<string, string> $tableToBeanMap |
|
1865 | + */ |
|
1866 | 1866 | public function setTableToBeanMap(array $tableToBeanMap) { |
1867 | 1867 | $this->tableToBeanMap = $tableToBeanMap; |
1868 | 1868 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | private $tableToBeanMap = []; |
149 | 149 | |
150 | 150 | public function __construct() { |
151 | - register_shutdown_function(array($this,"completeSaveOnExit")); |
|
151 | + register_shutdown_function(array($this, "completeSaveOnExit")); |
|
152 | 152 | if (extension_loaded('weakref')) { |
153 | 153 | $this->objectStorage = new WeakrefObjectStorage(); |
154 | 154 | } else { |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | $objects = $this->getObjects($table_name, $filters, null, null, null, $className); |
369 | 369 | if (count($objects) == 0) { |
370 | 370 | return null; |
371 | - } elseif (count($objects) > 1) { |
|
371 | + } elseif (count($objects)>1) { |
|
372 | 372 | 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."); |
373 | 373 | } |
374 | 374 | // Return the first and only object. |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * @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. |
446 | 446 | * @return TDBMObject |
447 | 447 | */ |
448 | - public function getNewObject($table_name, $auto_assign_id=true, $className = null) { |
|
448 | + public function getNewObject($table_name, $auto_assign_id = true, $className = null) { |
|
449 | 449 | if ($this->dbConnection == null) { |
450 | 450 | throw new TDBMException("Error while calling TDBMObject::getNewObject(): No connection has been established on the database!"); |
451 | 451 | } |
@@ -479,8 +479,8 @@ discard block |
||
479 | 479 | $object = new $className($this, $table_name); |
480 | 480 | |
481 | 481 | if ($auto_assign_id && !$this->isPrimaryKeyAutoIncrement($table_name)) { |
482 | - $pk_table = $this->getPrimaryKeyStatic($table_name); |
|
483 | - if (count($pk_table)==1) |
|
482 | + $pk_table = $this->getPrimaryKeyStatic($table_name); |
|
483 | + if (count($pk_table) == 1) |
|
484 | 484 | { |
485 | 485 | $root_table = $this->dbConnection->findRootSequenceTable($table_name); |
486 | 486 | $id = $this->dbConnection->nextId($root_table); |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | $sql = "SELECT MAX(".$this->dbConnection->escapeDBItem($pk_table[0]).") AS maxkey FROM ".$root_table; |
491 | 491 | $res = $this->dbConnection->getAll($sql); |
492 | 492 | // NOTE: this will work only if the ID is an integer! |
493 | - $newid = $res[0]['maxkey'] + 1; |
|
493 | + $newid = $res[0]['maxkey']+1; |
|
494 | 494 | if ($newid>$id) { |
495 | 495 | $id = $newid; |
496 | 496 | } |
@@ -520,17 +520,17 @@ discard block |
||
520 | 520 | // Now for the object_id |
521 | 521 | $object_id = $object->TDBMObject_id; |
522 | 522 | // If there is only one primary key: |
523 | - if (count($pk_table)==1) { |
|
523 | + if (count($pk_table) == 1) { |
|
524 | 524 | $sql_where = $this->dbConnection->escapeDBItem($pk_table[0])."=".$this->dbConnection->quoteSmart($object->TDBMObject_id); |
525 | 525 | } else { |
526 | 526 | $ids = unserialize($object_id); |
527 | - $i=0; |
|
527 | + $i = 0; |
|
528 | 528 | $sql_where_array = array(); |
529 | 529 | foreach ($pk_table as $pk) { |
530 | 530 | $sql_where_array[] = $this->dbConnection->escapeDBItem($pk)."=".$this->dbConnection->quoteSmart($ids[$i]); |
531 | 531 | $i++; |
532 | 532 | } |
533 | - $sql_where = implode(" AND ",$sql_where_array); |
|
533 | + $sql_where = implode(" AND ", $sql_where_array); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | * @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. |
614 | 614 | * @return array|\Generator|TDBMObjectArray The result set of the query as a TDBMObjectArray (an array of TDBMObjects with special properties) |
615 | 615 | */ |
616 | - public function getObjectsFromSQL($table_name, $sql, $from=null, $limit=null, $className=null) { |
|
616 | + public function getObjectsFromSQL($table_name, $sql, $from = null, $limit = null, $className = null) { |
|
617 | 617 | if ($this->dbConnection == null) { |
618 | 618 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
619 | 619 | } |
@@ -656,10 +656,10 @@ discard block |
||
656 | 656 | $firstLine = false; |
657 | 657 | } |
658 | 658 | foreach ($fullCaseRow as $key=>$value) { |
659 | - $row[$keysStandardCased[$key]]=$value; |
|
659 | + $row[$keysStandardCased[$key]] = $value; |
|
660 | 660 | } |
661 | 661 | $pk_table = $this->primary_keys[$table_name]; |
662 | - if (count($pk_table)==1) |
|
662 | + if (count($pk_table) == 1) |
|
663 | 663 | { |
664 | 664 | if (!isset($keysStandardCased[$pk_table[0]])) { |
665 | 665 | 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); |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | $id = serialize($ids); |
677 | 677 | } |
678 | 678 | |
679 | - $obj = $this->objectStorage->get($table_name,$id); |
|
679 | + $obj = $this->objectStorage->get($table_name, $id); |
|
680 | 680 | if ($obj === null) |
681 | 681 | { |
682 | 682 | if (!is_a($className, "Mouf\\Database\\TDBM\\TDBMObject", true)) { |
@@ -731,10 +731,10 @@ discard block |
||
731 | 731 | $firstLine = false; |
732 | 732 | } |
733 | 733 | foreach ($fullCaseRow as $key=>$value) { |
734 | - $row[$keysStandardCased[$key]]=$value; |
|
734 | + $row[$keysStandardCased[$key]] = $value; |
|
735 | 735 | } |
736 | 736 | $pk_table = $this->primary_keys[$table_name]; |
737 | - if (count($pk_table)==1) |
|
737 | + if (count($pk_table) == 1) |
|
738 | 738 | { |
739 | 739 | if (!isset($keysStandardCased[$pk_table[0]])) { |
740 | 740 | 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); |
@@ -829,14 +829,14 @@ discard block |
||
829 | 829 | // Now, let's commit or rollback if needed. |
830 | 830 | if ($this->dbConnection != null && $this->dbConnection->hasActiveTransaction()) { |
831 | 831 | if ($this->commitOnQuit) { |
832 | - try { |
|
832 | + try { |
|
833 | 833 | $this->dbConnection->commit(); |
834 | 834 | } catch (Exception $e) { |
835 | 835 | echo $e->getMessage()."<br/>"; |
836 | 836 | echo $e->getTraceAsString(); |
837 | 837 | } |
838 | 838 | } else { |
839 | - try { |
|
839 | + try { |
|
840 | 840 | $this->dbConnection->rollback(); |
841 | 841 | } catch (Exception $e) { |
842 | 842 | echo $e->getMessage()."<br/>"; |
@@ -897,21 +897,21 @@ discard block |
||
897 | 897 | * @param string $sql |
898 | 898 | * @return array the result of your query |
899 | 899 | */ |
900 | - public function getTransientObjectsFromSQL($sql,$classname=null) { |
|
900 | + public function getTransientObjectsFromSQL($sql, $classname = null) { |
|
901 | 901 | if ($this->dbConnection == null) { |
902 | 902 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
903 | 903 | } |
904 | - return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS,$classname); |
|
904 | + return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS, $classname); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | |
908 | 908 | private function to_explain_string($path) { |
909 | 909 | $msg = ''; |
910 | 910 | foreach ($path as $constraint) { |
911 | - if ($constraint['type']=='1*') { |
|
911 | + if ($constraint['type'] == '1*') { |
|
912 | 912 | $msg .= 'Table "'.$constraint['table1'].'" points to "'.$constraint['table2'].'" through its foreign key "'.$constraint['col1'].'"\n'; |
913 | 913 | } |
914 | - elseif ($constraint['type']=='*1') { |
|
914 | + elseif ($constraint['type'] == '*1') { |
|
915 | 915 | $msg .= 'Table "'.$constraint['table1'].'" is pointed by "'.$constraint['table2'].'" through its foreign key "'.$constraint['col2'].'"\n'; |
916 | 916 | } |
917 | 917 | } |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | $this->loadCache(); |
931 | 931 | |
932 | 932 | $path = array(); |
933 | - $queue = array(array($table,array())); |
|
933 | + $queue = array(array($table, array())); |
|
934 | 934 | |
935 | 935 | $found = false; |
936 | 936 | $found_depth = 0; |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | { |
966 | 966 | break; |
967 | 967 | } |
968 | - if ($ret==true) |
|
968 | + if ($ret == true) |
|
969 | 969 | { |
970 | 970 | // Ok, we got one, we will continue a bit more until we reach the next level in the tree, |
971 | 971 | // just to see if there is no ambiguity |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | } |
976 | 976 | |
977 | 977 | // At each iteration, let's check the time. |
978 | - if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time > $max_execution_time && $max_execution_time!=0) { |
|
978 | + if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time>$max_execution_time && $max_execution_time != 0) { |
|
979 | 979 | // Call check table names |
980 | 980 | $this->checkTablesExist($tables); |
981 | 981 | |
@@ -986,11 +986,11 @@ discard block |
||
986 | 986 | } |
987 | 987 | } |
988 | 988 | |
989 | - $ambiguity =false; |
|
989 | + $ambiguity = false; |
|
990 | 990 | $msg = ''; |
991 | 991 | foreach ($tables_paths as $table_path) { |
992 | 992 | // If any table has not been found, throw an exception |
993 | - if (!isset($table_path['founddepth']) || $table_path['founddepth']==null) { |
|
993 | + if (!isset($table_path['founddepth']) || $table_path['founddepth'] == null) { |
|
994 | 994 | // First, check if the tables do exist. |
995 | 995 | $this->checkTablesExist(array($table, $table_path['name'])); |
996 | 996 | // Else, throw an error. |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | 'table2' => $depArr['table1'], |
1053 | 1053 | 'col1' => $depArr['col2'], |
1054 | 1054 | 'col2' => $depArr['col1'], |
1055 | - 'type' => (($depArr['type'] == '1*')?'*1':'1*') |
|
1055 | + 'type' => (($depArr['type'] == '1*') ? '*1' : '1*') |
|
1056 | 1056 | ); |
1057 | 1057 | }, $toRevertPath); |
1058 | 1058 | return array_reverse($invertedDependencies); |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | * @param unknown_type $paths |
1071 | 1071 | */ |
1072 | 1072 | private function flatten_paths($paths) { |
1073 | - $flat_path=array(); |
|
1073 | + $flat_path = array(); |
|
1074 | 1074 | foreach ($paths as $path_bigarray) { |
1075 | 1075 | $path = $path_bigarray['paths'][0]; |
1076 | 1076 | |
@@ -1109,9 +1109,9 @@ discard block |
||
1109 | 1109 | $path = $current_vars[1]; |
1110 | 1110 | |
1111 | 1111 | foreach ($target_tables as $id=>$target_table) { |
1112 | - if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth']==null || $target_table['founddepth']==count($path))) { |
|
1112 | + if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth'] == null || $target_table['founddepth'] == count($path))) { |
|
1113 | 1113 | // When a path is found to a table, we mark the table as found with its depth. |
1114 | - $target_tables[$id]['founddepth']=count($path); |
|
1114 | + $target_tables[$id]['founddepth'] = count($path); |
|
1115 | 1115 | |
1116 | 1116 | // Then we add the path to table to the target_tables array |
1117 | 1117 | $target_tables[$id]['paths'][] = $path; |
@@ -1142,12 +1142,12 @@ discard block |
||
1142 | 1142 | $already_done = false; |
1143 | 1143 | foreach ($path as $previous_constraint) |
1144 | 1144 | { |
1145 | - if ($previous_constraint['type']=='1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"]) |
|
1145 | + if ($previous_constraint['type'] == '1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"]) |
|
1146 | 1146 | { |
1147 | 1147 | $already_done = true; |
1148 | 1148 | break; |
1149 | 1149 | } |
1150 | - elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1150 | + elseif ($previous_constraint['type'] == '*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1151 | 1151 | { |
1152 | 1152 | $already_done = true; |
1153 | 1153 | break; |
@@ -1175,12 +1175,12 @@ discard block |
||
1175 | 1175 | $already_done = false; |
1176 | 1176 | foreach ($path as $previous_constraint) |
1177 | 1177 | { |
1178 | - if ($previous_constraint['type']=='1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"]) |
|
1178 | + if ($previous_constraint['type'] == '1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"]) |
|
1179 | 1179 | { |
1180 | 1180 | $already_done = true; |
1181 | 1181 | break; |
1182 | 1182 | } |
1183 | - elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1183 | + elseif ($previous_constraint['type'] == '*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1184 | 1184 | { |
1185 | 1185 | $already_done = true; |
1186 | 1186 | break; |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1290 | 1290 | * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
1291 | 1291 | */ |
1292 | - public function getObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) { |
|
1292 | + public function getObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) { |
|
1293 | 1293 | if ($this->dbConnection == null) { |
1294 | 1294 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1295 | 1295 | } |
@@ -1305,7 +1305,7 @@ discard block |
||
1305 | 1305 | * @param unknown_type $hint_path |
1306 | 1306 | * @return integer |
1307 | 1307 | */ |
1308 | - public function getCount($table_name, $filter_bag=null, $hint_path=null) { |
|
1308 | + public function getCount($table_name, $filter_bag = null, $hint_path = null) { |
|
1309 | 1309 | if ($this->dbConnection == null) { |
1310 | 1310 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1311 | 1311 | } |
@@ -1323,7 +1323,7 @@ discard block |
||
1323 | 1323 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1324 | 1324 | * @return string The SQL that would be executed. |
1325 | 1325 | */ |
1326 | - public function explainSQLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) { |
|
1326 | + public function explainSQLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) { |
|
1327 | 1327 | if ($this->dbConnection == null) { |
1328 | 1328 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1329 | 1329 | } |
@@ -1341,7 +1341,7 @@ discard block |
||
1341 | 1341 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1342 | 1342 | * @return string The SQL that would be executed. |
1343 | 1343 | */ |
1344 | - public function explainRequestAsTextGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) { |
|
1344 | + public function explainRequestAsTextGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) { |
|
1345 | 1345 | if ($this->dbConnection == null) { |
1346 | 1346 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1347 | 1347 | } |
@@ -1362,12 +1362,12 @@ discard block |
||
1362 | 1362 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1363 | 1363 | * @return string The SQL that would be executed. |
1364 | 1364 | */ |
1365 | - public function explainRequestAsHTMLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null, $x=10, $y=10) { |
|
1365 | + public function explainRequestAsHTMLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null, $x = 10, $y = 10) { |
|
1366 | 1366 | if ($this->dbConnection == null) { |
1367 | 1367 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1368 | 1368 | } |
1369 | 1369 | $tree = $this->getObjectsByMode('explainTree', $table_name, $filter_bag, $orderby_bag, $from, $limit, $hint_path); |
1370 | - return $this->drawTree($tree,$x,$y); |
|
1370 | + return $this->drawTree($tree, $x, $y); |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | 1373 | /** |
@@ -1384,7 +1384,7 @@ discard block |
||
1384 | 1384 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1385 | 1385 | * @return array|\Generator|TDBMObjectArray|int An array or object containing the resulting objects of the query. |
1386 | 1386 | */ |
1387 | - public function getObjectsByMode($mode, $table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) { |
|
1387 | + public function getObjectsByMode($mode, $table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) { |
|
1388 | 1388 | $this->completeSave(); |
1389 | 1389 | $this->loadCache(); |
1390 | 1390 | |
@@ -1423,7 +1423,7 @@ discard block |
||
1423 | 1423 | } |
1424 | 1424 | } |
1425 | 1425 | |
1426 | - if (count($needed_table_array)==0) |
|
1426 | + if (count($needed_table_array) == 0) |
|
1427 | 1427 | { |
1428 | 1428 | $sql = $this->dbConnection->escapeDBItem($table_name); //Make by Pierre PIV (add escapeDBItem) |
1429 | 1429 | |
@@ -1431,14 +1431,14 @@ discard block |
||
1431 | 1431 | throw new TDBMException("TODO: explainTree not implemented for only one table."); |
1432 | 1432 | } |
1433 | 1433 | else { |
1434 | - if ($hint_path!=null && $mode != 'explainTree') |
|
1434 | + if ($hint_path != null && $mode != 'explainTree') |
|
1435 | 1435 | { |
1436 | 1436 | $path = $hint_path; |
1437 | 1437 | $flat_path = $this->flatten_paths($path); |
1438 | 1438 | } |
1439 | 1439 | else |
1440 | 1440 | { |
1441 | - $full_paths = $this->static_find_paths($table_name,$needed_table_array); |
|
1441 | + $full_paths = $this->static_find_paths($table_name, $needed_table_array); |
|
1442 | 1442 | |
1443 | 1443 | if ($mode == 'explainTree') { |
1444 | 1444 | return $this->getTablePathsTree($full_paths); |
@@ -1466,7 +1466,7 @@ discard block |
||
1466 | 1466 | } |
1467 | 1467 | |
1468 | 1468 | //If no $hint_path is provided, check that a path exists |
1469 | - if($hint_path === null){ |
|
1469 | + if ($hint_path === null) { |
|
1470 | 1470 | // Now, for each needed table to perform the order by, we must verify if the relationship between the order by and the object is indeed a 1* relationship |
1471 | 1471 | foreach ($needed_table_array_for_orderby as $target_table_table) { |
1472 | 1472 | // Get the path between the main table and the target group by table |
@@ -1482,7 +1482,7 @@ discard block |
||
1482 | 1482 | */ |
1483 | 1483 | $is_ok = true; |
1484 | 1484 | foreach ($path as $step) { |
1485 | - if ($step["type"]=="1*") { |
|
1485 | + if ($step["type"] == "1*") { |
|
1486 | 1486 | $is_ok = false; |
1487 | 1487 | break; |
1488 | 1488 | } |
@@ -1508,7 +1508,7 @@ discard block |
||
1508 | 1508 | $orderby_columns_array = array_merge($orderby_columns_array, $orderby_object->toSqlStatementsArray()); |
1509 | 1509 | } |
1510 | 1510 | |
1511 | - $orderby_statement = ' ORDER BY '.implode(',',$orderby_columns_array); |
|
1511 | + $orderby_statement = ' ORDER BY '.implode(',', $orderby_columns_array); |
|
1512 | 1512 | $count = 0; |
1513 | 1513 | foreach ($orderby_columns_array as $id=>$orderby_statement_phrase) { |
1514 | 1514 | // Let's remove the trailing ASC or DESC and add AS tdbm_reserved_col_Xxx |
@@ -1526,10 +1526,10 @@ discard block |
||
1526 | 1526 | $orderby_columns_array[$id] = $orderby_statement_phrase.' AS tdbm_reserved_col_'.$count; |
1527 | 1527 | $count++; |
1528 | 1528 | } |
1529 | - $orderby_column_statement = ', '.implode(',',$orderby_columns_array); |
|
1529 | + $orderby_column_statement = ', '.implode(',', $orderby_columns_array); |
|
1530 | 1530 | } |
1531 | 1531 | |
1532 | - if ($mode=="getCount") { |
|
1532 | + if ($mode == "getCount") { |
|
1533 | 1533 | // Let's get the list of primary keys to perform a DISTINCT request. |
1534 | 1534 | $pk_table = $this->getPrimaryKeyStatic($table_name); |
1535 | 1535 | |
@@ -1563,7 +1563,7 @@ discard block |
||
1563 | 1563 | if ($mode == 'explainSQL') { |
1564 | 1564 | return $sql; |
1565 | 1565 | } |
1566 | - return $this->getObjectsFromSQL($table_name, $sql, $from, $limit, $className); |
|
1566 | + return $this->getObjectsFromSQL($table_name, $sql, $from, $limit, $className); |
|
1567 | 1567 | |
1568 | 1568 | } |
1569 | 1569 | |
@@ -1588,17 +1588,17 @@ discard block |
||
1588 | 1588 | // Second, let's take all the objects out of the filter bag, and let's make filters from them |
1589 | 1589 | $filter_bag2 = array(); |
1590 | 1590 | foreach ($filter_bag as $thing) { |
1591 | - if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) { |
|
1591 | + if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) { |
|
1592 | 1592 | $filter_bag2[] = $thing; |
1593 | 1593 | } elseif (is_string($thing)) { |
1594 | 1594 | $filter_bag2[] = new SqlStringFilter($thing); |
1595 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) { |
|
1595 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) { |
|
1596 | 1596 | // Get table_name and column_name |
1597 | 1597 | $filter_table_name = $thing[0]->_getDbTableName(); |
1598 | 1598 | $filter_column_names = $thing[0]->getPrimaryKey(); |
1599 | 1599 | |
1600 | 1600 | // If there is only one primary key, we can use the InFilter |
1601 | - if (count($filter_column_names)==1) { |
|
1601 | + if (count($filter_column_names) == 1) { |
|
1602 | 1602 | $primary_keys_array = array(); |
1603 | 1603 | $filter_column_name = $filter_column_names[0]; |
1604 | 1604 | foreach ($thing as $TDBMObject) { |
@@ -1611,7 +1611,7 @@ discard block |
||
1611 | 1611 | { |
1612 | 1612 | $filter_bag_and = array(); |
1613 | 1613 | foreach ($thing as $TDBMObject) { |
1614 | - $filter_bag_temp_and=array(); |
|
1614 | + $filter_bag_temp_and = array(); |
|
1615 | 1615 | foreach ($filter_column_names as $pk) { |
1616 | 1616 | $filter_bag_temp_and[] = new EqualFilter($TDBMObject->_getDbTableName(), $pk, $TDBMObject->$pk); |
1617 | 1617 | } |
@@ -1621,7 +1621,7 @@ discard block |
||
1621 | 1621 | } |
1622 | 1622 | |
1623 | 1623 | |
1624 | - } elseif (!is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing!==null) { |
|
1624 | + } elseif (!is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing !== null) { |
|
1625 | 1625 | 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."); |
1626 | 1626 | } |
1627 | 1627 | } |
@@ -1649,9 +1649,9 @@ discard block |
||
1649 | 1649 | // 4-2, let's take all the objects out of the orderby bag, and let's make objects from them |
1650 | 1650 | $orderby_bag2 = array(); |
1651 | 1651 | foreach ($orderby_bag as $thing) { |
1652 | - if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
1652 | + if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
1653 | 1653 | $orderby_bag2[] = $thing; |
1654 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
1654 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
1655 | 1655 | $orderby_bag2[] = $thing; |
1656 | 1656 | } elseif (is_string($thing)) { |
1657 | 1657 | $orderby_bag2[] = new OrderBySQLString($thing); |
@@ -1674,10 +1674,10 @@ discard block |
||
1674 | 1674 | $possible_tables = $this->dbConnection->checkTableExist($table); |
1675 | 1675 | if ($possible_tables !== true) |
1676 | 1676 | { |
1677 | - if (count($possible_tables)==1) |
|
1677 | + if (count($possible_tables) == 1) |
|
1678 | 1678 | $str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'"; |
1679 | 1679 | else |
1680 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'"; |
|
1680 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $possible_tables)."'"; |
|
1681 | 1681 | throw new TDBMException($str); |
1682 | 1682 | } |
1683 | 1683 | } |
@@ -1700,16 +1700,16 @@ discard block |
||
1700 | 1700 | $current_node = $tree; |
1701 | 1701 | $found = true; |
1702 | 1702 | foreach ($path as $link) { |
1703 | - if ($found==true) |
|
1703 | + if ($found == true) |
|
1704 | 1704 | { |
1705 | 1705 | if (is_array($current_node->getChildren())) |
1706 | 1706 | { |
1707 | 1707 | foreach ($current_node->getChildren() as $child) |
1708 | 1708 | { |
1709 | - if ($link['table1']==$child->table_name && |
|
1710 | - $link['col1']==$child->keyNode && |
|
1711 | - $link['col2']==$child->keyParent && |
|
1712 | - $link['type']==$child->link_type) { |
|
1709 | + if ($link['table1'] == $child->table_name && |
|
1710 | + $link['col1'] == $child->keyNode && |
|
1711 | + $link['col2'] == $child->keyParent && |
|
1712 | + $link['type'] == $child->link_type) { |
|
1713 | 1713 | $current_node = $child; |
1714 | 1714 | } |
1715 | 1715 | else |
@@ -1724,7 +1724,7 @@ discard block |
||
1724 | 1724 | |
1725 | 1725 | } |
1726 | 1726 | |
1727 | - if ($found==false) |
|
1727 | + if ($found == false) |
|
1728 | 1728 | { |
1729 | 1729 | $current_node = new DisplayNode($link['table1'], $current_node, $link['type'], $link['col2'], $link['col1']); |
1730 | 1730 | } |
@@ -1749,7 +1749,7 @@ discard block |
||
1749 | 1749 | * |
1750 | 1750 | * @return string |
1751 | 1751 | */ |
1752 | - public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) { |
|
1752 | + public function drawTree($tree, $x, $y, &$ret_width = 0, &$ret_height = 0) { |
|
1753 | 1753 | |
1754 | 1754 | // Let's get the background div: |
1755 | 1755 | $treeDepth = $tree->computeDepth(1)-1; |
@@ -1760,7 +1760,7 @@ discard block |
||
1760 | 1760 | |
1761 | 1761 | $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>"; |
1762 | 1762 | |
1763 | - $str .= $tree->draw(0,0, $x, $y); |
|
1763 | + $str .= $tree->draw(0, 0, $x, $y); |
|
1764 | 1764 | |
1765 | 1765 | return $str; |
1766 | 1766 | } |
@@ -1795,10 +1795,10 @@ discard block |
||
1795 | 1795 | if ($tables === true) |
1796 | 1796 | throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table."); |
1797 | 1797 | elseif ($tables !== null) { |
1798 | - if (count($tables)==1) |
|
1798 | + if (count($tables) == 1) |
|
1799 | 1799 | $str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'"; |
1800 | 1800 | else |
1801 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'"; |
|
1801 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $tables)."'"; |
|
1802 | 1802 | throw new TDBMException($str); |
1803 | 1803 | } |
1804 | 1804 | } |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | if ($this->daoNamespace == null && $this->beanNamespace == null) { |
68 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
68 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
69 | 69 | |
70 | 70 | $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
71 | - if ($autoloadNamespaces) { |
|
71 | + if ($autoloadNamespaces) { |
|
72 | 72 | $this->autoloadDetected = true; |
73 | 73 | $rootNamespace = $autoloadNamespaces[0]; |
74 | 74 | $this->daoNamespace = $rootNamespace."Dao"; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | $tdbmService = new InstanceProxy($name); |
152 | 152 | /* @var $tdbmService TDBMService */ |
153 | - $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $keepSupport, $storeInUtc, $castDatesToDateTime); |
|
153 | + $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $keepSupport, $storeInUtc, $castDatesToDateTime); |
|
154 | 154 | |
155 | 155 | |
156 | 156 | $moufManager->declareComponent($daofactoryinstancename, $daonamespace."\\".$daofactoryclassname, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @Action |
43 | 43 | * //@Admin |
44 | 44 | */ |
45 | - public function defaultAction($name, $selfedit="false") { |
|
45 | + public function defaultAction($name, $selfedit = "false") { |
|
46 | 46 | $this->initController($name, $selfedit); |
47 | 47 | |
48 | 48 | // Fill variables |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param string $name |
94 | 94 | * @param bool $selfedit |
95 | 95 | */ |
96 | - public function generate($name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $keepSupport = 0, $storeInUtc = 0, $castDatesToDateTime = 0, $selfedit="false") { |
|
96 | + public function generate($name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $keepSupport = 0, $storeInUtc = 0, $castDatesToDateTime = 0, $selfedit = "false") { |
|
97 | 97 | $this->initController($name, $selfedit); |
98 | 98 | |
99 | 99 | self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit, $keepSupport, $storeInUtc, $castDatesToDateTime); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @param bool $castDatesToDateTime |
117 | 117 | * @throws \Mouf\MoufException |
118 | 118 | */ |
119 | - public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit="false", $keepSupport = null, $storeInUtc = null, $castDatesToDateTime = null) { |
|
119 | + public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit = "false", $keepSupport = null, $storeInUtc = null, $castDatesToDateTime = null) { |
|
120 | 120 | $moufManager->setVariable("tdbmDefaultDaoNamespace_".$name, $daonamespace); |
121 | 121 | $moufManager->setVariable("tdbmDefaultBeanNamespace_".$name, $beannamespace); |
122 | 122 | $moufManager->setVariable("tdbmDefaultDaoFactoryName_".$name, $daofactoryclassname); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $moufManager->bindComponentViaSetter($instanceName, "setTdbmService", $name); |
168 | 168 | $moufManager->bindComponentViaSetter($daofactoryinstancename, "set".$daoName, $instanceName); |
169 | 169 | |
170 | - $tableToBeanMap[$table] = $beannamespace . "\\" . TDBMDaoGenerator::getBeanNameFromTableName($table); |
|
170 | + $tableToBeanMap[$table] = $beannamespace."\\".TDBMDaoGenerator::getBeanNameFromTableName($table); |
|
171 | 171 | } |
172 | 172 | $tdbmServiceDescriptor = $moufManager->getInstanceDescriptor($name); |
173 | 173 | $tdbmServiceDescriptor->getSetterProperty("setTableToBeanMap")->setValue($tableToBeanMap); |
@@ -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"; |
@@ -67,8 +67,7 @@ |
||
67 | 67 | if ($this->link_type == "*1") |
68 | 68 | { |
69 | 69 | echo "Table $this->table_name points to table ".$this->parent_node->table_name." through its foreign key on column $this->keyNode that points to column $this->keyParent<br />"; |
70 | - } |
|
71 | - else if ($this->link_type == "1*") |
|
70 | + } else if ($this->link_type == "1*") |
|
72 | 71 | { |
73 | 72 | echo "Table $this->table_name is pointed by table ".$this->parent_node->table_name." by its foreign key on column $this->keyParent that points to column $this->keyNode<br />"; |
74 | 73 | } |
@@ -9,14 +9,14 @@ |
||
9 | 9 | */ |
10 | 10 | class FilterUtils |
11 | 11 | { |
12 | - /** |
|
13 | - * @param string|null|DateTimeInterface $value |
|
14 | - */ |
|
15 | - public static function valueToSql($value, ConnectionInterface $dbConnection) { |
|
16 | - if ($value instanceof DateTimeInterface) { |
|
17 | - return "'".$value->format('Y-m-d H:i:s')."'"; |
|
18 | - } else { |
|
19 | - return $dbConnection->quoteSmart($value); |
|
20 | - } |
|
21 | - } |
|
12 | + /** |
|
13 | + * @param string|null|DateTimeInterface $value |
|
14 | + */ |
|
15 | + public static function valueToSql($value, ConnectionInterface $dbConnection) { |
|
16 | + if ($value instanceof DateTimeInterface) { |
|
17 | + return "'".$value->format('Y-m-d H:i:s')."'"; |
|
18 | + } else { |
|
19 | + return $dbConnection->quoteSmart($value); |
|
20 | + } |
|
21 | + } |
|
22 | 22 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | <div class="control-group"> |
38 | 38 | <label class="control-label">Cast dates as <code>DateTimeImmutable</code>:</label> |
39 | 39 | <div class="controls"> |
40 | - <input type="checkbox" name="castDatesToDateTime" value="1" <?php echo $this->castDatesToDateTime?'checked="checked"':"" ?>></input> |
|
40 | + <input type="checkbox" name="castDatesToDateTime" value="1" <?php echo $this->castDatesToDateTime ? 'checked="checked"' : "" ?>></input> |
|
41 | 41 | <span class="help-block">Select this option if you want dates to be returned as <code>DateTimeImmutable</code>. |
42 | 42 | This is highly recommended. If you do not select this box, getters and setters will return / expect a timestamp |
43 | 43 | (this was the default behaviour up to TDBM 3.3).</span> |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | <div class="control-group"> |
47 | 47 | <label class="control-label">Store dates / timestamps in UTC:</label> |
48 | 48 | <div class="controls"> |
49 | - <input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc?'checked="checked"':"" ?>></input> |
|
49 | + <input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc ? 'checked="checked"' : "" ?>></input> |
|
50 | 50 | <span class="help-block">Select this option if you want timestamps to be stored in UTC. |
51 | 51 | If your application supports several time zones, you should select this option to store all dates in |
52 | 52 | the same time zone.</span> |