@@ -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); |
@@ -170,26 +170,26 @@ discard block |
||
170 | 170 | $this->TDBMObject_state = $state; |
171 | 171 | } |
172 | 172 | |
173 | - /** |
|
174 | - * Internal TDBM method, you should not use this. |
|
175 | - * Loads the db_row property of the object from the $row array. |
|
176 | - * Any row having a key starting with 'tdbm_reserved_col_' is ignored. |
|
177 | - * |
|
178 | - * @param array $row |
|
179 | - * @param array|null $colsArray A big optimization to avoid calling strpos to many times. This array should |
|
180 | - * contain as keys the list of interesting columns. If null, this list will be initialized. |
|
181 | - */ |
|
173 | + /** |
|
174 | + * Internal TDBM method, you should not use this. |
|
175 | + * Loads the db_row property of the object from the $row array. |
|
176 | + * Any row having a key starting with 'tdbm_reserved_col_' is ignored. |
|
177 | + * |
|
178 | + * @param array $row |
|
179 | + * @param array|null $colsArray A big optimization to avoid calling strpos to many times. This array should |
|
180 | + * contain as keys the list of interesting columns. If null, this list will be initialized. |
|
181 | + */ |
|
182 | 182 | public function loadFromRow($row, &$colsArray) { |
183 | - if ($colsArray === null) { |
|
184 | - foreach ($row as $key=>$value) { |
|
185 | - if (strpos($key, 'tdbm_reserved_col_')!==0) { |
|
186 | - $colsArray[$key] = true; |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - $this->db_row = array_intersect_key($row, $colsArray); |
|
192 | - $this->TDBMObject_state = "loaded"; |
|
183 | + if ($colsArray === null) { |
|
184 | + foreach ($row as $key=>$value) { |
|
185 | + if (strpos($key, 'tdbm_reserved_col_')!==0) { |
|
186 | + $colsArray[$key] = true; |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + $this->db_row = array_intersect_key($row, $colsArray); |
|
192 | + $this->TDBMObject_state = "loaded"; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -507,10 +507,10 @@ discard block |
||
507 | 507 | * |
508 | 508 | * @param string $func_name |
509 | 509 | * @param $values |
510 | - * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
|
511 | - * @throws TDBMException |
|
510 | + * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
|
511 | + * @throws TDBMException |
|
512 | 512 | */ |
513 | - public function __call($func_name, $values) { |
|
513 | + public function __call($func_name, $values) { |
|
514 | 514 | |
515 | 515 | if (strpos($func_name,"get_") === 0) { |
516 | 516 | $table = substr($func_name,4); |
@@ -545,48 +545,48 @@ discard block |
||
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
548 | - * Implements array behaviour for our object. |
|
549 | - * |
|
550 | - * @param string $offset |
|
551 | - * @param string $value |
|
552 | - */ |
|
548 | + * Implements array behaviour for our object. |
|
549 | + * |
|
550 | + * @param string $offset |
|
551 | + * @param string $value |
|
552 | + */ |
|
553 | 553 | public function offsetSet($offset, $value) { |
554 | 554 | $this->__set($offset, $value); |
555 | - } |
|
555 | + } |
|
556 | 556 | /** |
557 | 557 | * Implements array behaviour for our object. |
558 | 558 | * |
559 | 559 | * @param string $offset |
560 | - * @return bool |
|
560 | + * @return bool |
|
561 | 561 | */ |
562 | - public function offsetExists($offset) { |
|
563 | - $this->_dbLoadIfNotLoaded(); |
|
564 | - return isset($this->db_row[$offset]); |
|
565 | - } |
|
562 | + public function offsetExists($offset) { |
|
563 | + $this->_dbLoadIfNotLoaded(); |
|
564 | + return isset($this->db_row[$offset]); |
|
565 | + } |
|
566 | 566 | /** |
567 | 567 | * Implements array behaviour for our object. |
568 | 568 | * |
569 | 569 | * @param string $offset |
570 | 570 | */ |
571 | - public function offsetUnset($offset) { |
|
571 | + public function offsetUnset($offset) { |
|
572 | 572 | $this->__set($offset, null); |
573 | - } |
|
573 | + } |
|
574 | 574 | /** |
575 | 575 | * Implements array behaviour for our object. |
576 | 576 | * |
577 | 577 | * @param string $offset |
578 | - * @return mixed|null |
|
578 | + * @return mixed|null |
|
579 | 579 | */ |
580 | - public function offsetGet($offset) { |
|
581 | - return $this->__get($offset); |
|
582 | - } |
|
580 | + public function offsetGet($offset) { |
|
581 | + return $this->__get($offset); |
|
582 | + } |
|
583 | 583 | |
584 | 584 | private $_validIterator = false; |
585 | 585 | /** |
586 | 586 | * Implements iterator behaviour for our object (so we can each column). |
587 | 587 | */ |
588 | 588 | public function rewind() { |
589 | - $this->_dbLoadIfNotLoaded(); |
|
589 | + $this->_dbLoadIfNotLoaded(); |
|
590 | 590 | if (count($this->db_row)>0) { |
591 | 591 | $this->_validIterator = true; |
592 | 592 | } else { |
@@ -674,21 +674,21 @@ discard block |
||
674 | 674 | return $sql_where; |
675 | 675 | } |
676 | 676 | |
677 | - /** |
|
678 | - * Override the native php clone function for TDBMObjects |
|
679 | - */ |
|
680 | - public function __clone(){ |
|
681 | - $this->_dbLoadIfNotLoaded(); |
|
682 | - //First lets set the status to new (to enter the save function) |
|
683 | - $this->TDBMObject_state = "new"; |
|
684 | - |
|
685 | - // Add the current TDBMObject to the save object list |
|
686 | - $this->tdbmService->_addToToSaveObjectList($this); |
|
687 | - |
|
688 | - //Now unset the PK from the row |
|
689 | - $pk_array = $this->getPrimaryKey(); |
|
690 | - foreach ($pk_array as $pk) { |
|
691 | - $this->db_row[$pk] = null; |
|
692 | - } |
|
693 | - } |
|
677 | + /** |
|
678 | + * Override the native php clone function for TDBMObjects |
|
679 | + */ |
|
680 | + public function __clone(){ |
|
681 | + $this->_dbLoadIfNotLoaded(); |
|
682 | + //First lets set the status to new (to enter the save function) |
|
683 | + $this->TDBMObject_state = "new"; |
|
684 | + |
|
685 | + // Add the current TDBMObject to the save object list |
|
686 | + $this->tdbmService->_addToToSaveObjectList($this); |
|
687 | + |
|
688 | + //Now unset the PK from the row |
|
689 | + $pk_array = $this->getPrimaryKey(); |
|
690 | + foreach ($pk_array as $pk) { |
|
691 | + $this->db_row[$pk] = null; |
|
692 | + } |
|
693 | + } |
|
694 | 694 | } |
695 | 695 | \ No newline at end of file |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string $table_name |
110 | 110 | * @param mixed $id |
111 | 111 | */ |
112 | - public function __construct(TDBMService $tdbmService, $table_name, $id=false) { |
|
112 | + public function __construct(TDBMService $tdbmService, $table_name, $id = false) { |
|
113 | 113 | $this->tdbmService = $tdbmService; |
114 | 114 | $this->db_connection = $this->tdbmService->getConnection(); |
115 | 115 | $this->db_table_name = $table_name; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * $TDBMObject_state = "loaded" when the object is cached in memory. |
155 | 155 | * @return string |
156 | 156 | */ |
157 | - public function getTDBMObjectState(){ |
|
157 | + public function getTDBMObjectState() { |
|
158 | 158 | return $this->TDBMObject_state; |
159 | 159 | } |
160 | 160 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * $TDBMObject_state = "loaded" when the object is cached in memory. |
167 | 167 | * @param string $state |
168 | 168 | */ |
169 | - public function setTDBMObjectState($state){ |
|
169 | + public function setTDBMObjectState($state) { |
|
170 | 170 | $this->TDBMObject_state = $state; |
171 | 171 | } |
172 | 172 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public function loadFromRow($row, &$colsArray) { |
183 | 183 | if ($colsArray === null) { |
184 | 184 | foreach ($row as $key=>$value) { |
185 | - if (strpos($key, 'tdbm_reserved_col_')!==0) { |
|
185 | + if (strpos($key, 'tdbm_reserved_col_') !== 0) { |
|
186 | 186 | $colsArray[$key] = true; |
187 | 187 | } |
188 | 188 | } |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $result = $this->db_connection->query($sql); |
221 | 221 | |
222 | 222 | |
223 | - if ($result->rowCount()==0) |
|
223 | + if ($result->rowCount() == 0) |
|
224 | 224 | { |
225 | 225 | throw new TDBMException("Could not retrieve object from table \"$this->db_table_name\" with ID \"".$this->TDBMObject_id."\"."); |
226 | 226 | } |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | $result->closeCursor(); |
231 | 231 | |
232 | 232 | $this->db_row = array(); |
233 | - foreach ($fullCaseRow[0] as $key=>$value) { |
|
234 | - $this->db_row[$this->db_connection->toStandardCaseColumn($key)]=$value; |
|
233 | + foreach ($fullCaseRow[0] as $key=>$value) { |
|
234 | + $this->db_row[$this->db_connection->toStandardCaseColumn($key)] = $value; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $this->TDBMObject_state = "loaded"; |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | // Let's try to be accurate in error reporting. The checkColumnExist returns an array of closest matches. |
264 | 264 | $result_array = $column_exist; |
265 | 265 | |
266 | - if (count($result_array)==1) |
|
266 | + if (count($result_array) == 1) |
|
267 | 267 | $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'"; |
268 | 268 | else |
269 | - $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'"; |
|
269 | + $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '", $result_array)."'"; |
|
270 | 270 | |
271 | 271 | |
272 | 272 | throw new TDBMException($str); |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | $pk_array = $this->getPrimaryKey(); |
340 | 340 | |
341 | 341 | foreach ($pk_array as $pk) { |
342 | - if (isset($this->db_row[$pk]) && $this->db_row[$pk]!==null) { |
|
343 | - $pk_set=true; |
|
342 | + if (isset($this->db_row[$pk]) && $this->db_row[$pk] !== null) { |
|
343 | + $pk_set = true; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | // if there are many columns for the PK, and none is set, we have no way to find the object back! |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | if (!$first) |
364 | 364 | $sql .= ','; |
365 | 365 | $sql .= $this->db_connection->quoteSmart($value); |
366 | - $first=false; |
|
366 | + $first = false; |
|
367 | 367 | } |
368 | 368 | $sql .= ')'; |
369 | 369 | |
@@ -391,12 +391,12 @@ discard block |
||
391 | 391 | |
392 | 392 | // If there is only one column for the primary key, and if it has not been filled, let's find it. |
393 | 393 | // We assume this is the biggest ID in the database |
394 | - if (count($pk_array)==1 && !$pk_set) { |
|
394 | + if (count($pk_array) == 1 && !$pk_set) { |
|
395 | 395 | // FIXME: for PostgreSQL or MSSQL, the getInsertId call is not thread safe |
396 | 396 | // We should start a transaction before the insert |
397 | - $this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name,$pk_array[0]); |
|
397 | + $this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name, $pk_array[0]); |
|
398 | 398 | $this->db_row[$pk_array[0]] = $this->TDBMObject_id; |
399 | - } elseif (count($pk_array)==1 && $pk_set) { |
|
399 | + } elseif (count($pk_array) == 1 && $pk_set) { |
|
400 | 400 | $this->TDBMObject_id = $this->db_row[$pk_array[0]]; |
401 | 401 | } |
402 | 402 | |
@@ -423,24 +423,24 @@ discard block |
||
423 | 423 | |
424 | 424 | // Let's add this object to the list of objects in cache. |
425 | 425 | $this->tdbmService->_addToCache($this); |
426 | - } else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state==true) { |
|
426 | + } else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state == true) { |
|
427 | 427 | //$primary_key = $this->getPrimaryKey(); |
428 | 428 | // Let's first get the primary keys |
429 | 429 | $pk_table = $this->getPrimaryKey(); |
430 | 430 | // Now for the object_id |
431 | 431 | $object_id = $this->TDBMObject_id; |
432 | 432 | // If there is only one primary key: |
433 | - if (count($pk_table)==1) { |
|
433 | + if (count($pk_table) == 1) { |
|
434 | 434 | $sql_where = $this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
435 | 435 | } else { |
436 | 436 | $ids = unserialize($object_id); |
437 | - $i=0; |
|
437 | + $i = 0; |
|
438 | 438 | $sql_where_array = array(); |
439 | 439 | foreach ($pk_table as $pk) { |
440 | 440 | $sql_where_array[] = $this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]); |
441 | 441 | $i++; |
442 | 442 | } |
443 | - $sql_where = implode(" AND ",$sql_where_array); |
|
443 | + $sql_where = implode(" AND ", $sql_where_array); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | $sql = 'UPDATE '.$this->db_connection->escapeDBItem($this->db_table_name).' SET '; |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | if (!$first) |
451 | 451 | $sql .= ','; |
452 | 452 | $sql .= $this->db_connection->escapeDBItem($key)." = ".$this->db_connection->quoteSmart($value); |
453 | - $first=false; |
|
453 | + $first = false; |
|
454 | 454 | } |
455 | 455 | $sql .= ' WHERE '.$sql_where/*$primary_key."='".$this->db_row[$primary_key]."'"*/; |
456 | 456 | try { |
@@ -512,8 +512,8 @@ discard block |
||
512 | 512 | */ |
513 | 513 | public function __call($func_name, $values) { |
514 | 514 | |
515 | - if (strpos($func_name,"get_") === 0) { |
|
516 | - $table = substr($func_name,4); |
|
515 | + if (strpos($func_name, "get_") === 0) { |
|
516 | + $table = substr($func_name, 4); |
|
517 | 517 | } else { |
518 | 518 | throw new TDBMException("Method ".$func_name." not found"); |
519 | 519 | } |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | * Implement the unique JsonSerializable method |
625 | 625 | * @return array |
626 | 626 | */ |
627 | - public function jsonSerialize(){ |
|
627 | + public function jsonSerialize() { |
|
628 | 628 | $this->_dbLoadIfNotLoaded(); |
629 | 629 | return $this->db_row; |
630 | 630 | } |
@@ -653,23 +653,23 @@ discard block |
||
653 | 653 | * |
654 | 654 | * @return string |
655 | 655 | */ |
656 | - private function getPrimaryKeyWhereStatement () { |
|
656 | + private function getPrimaryKeyWhereStatement() { |
|
657 | 657 | // Let's first get the primary keys |
658 | 658 | $pk_table = $this->getPrimaryKey(); |
659 | 659 | // Now for the object_id |
660 | 660 | $object_id = $this->TDBMObject_id; |
661 | 661 | // If there is only one primary key: |
662 | - if (count($pk_table)==1) { |
|
662 | + if (count($pk_table) == 1) { |
|
663 | 663 | $sql_where = $this->db_connection->escapeDBItem($this->db_table_name).'.'.$this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
664 | 664 | } else { |
665 | 665 | $ids = unserialize($object_id); |
666 | - $i=0; |
|
666 | + $i = 0; |
|
667 | 667 | $sql_where_array = array(); |
668 | 668 | foreach ($pk_table as $pk) { |
669 | 669 | $sql_where_array[] = $this->db_connection->escapeDBItem($this->db_table_name).'.'.$this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]); |
670 | 670 | $i++; |
671 | 671 | } |
672 | - $sql_where = implode(" AND ",$sql_where_array); |
|
672 | + $sql_where = implode(" AND ", $sql_where_array); |
|
673 | 673 | } |
674 | 674 | return $sql_where; |
675 | 675 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | /** |
678 | 678 | * Override the native php clone function for TDBMObjects |
679 | 679 | */ |
680 | - public function __clone(){ |
|
680 | + public function __clone() { |
|
681 | 681 | $this->_dbLoadIfNotLoaded(); |
682 | 682 | //First lets set the status to new (to enter the save function) |
683 | 683 | $this->TDBMObject_state = "new"; |
@@ -263,10 +263,11 @@ discard block |
||
263 | 263 | // Let's try to be accurate in error reporting. The checkColumnExist returns an array of closest matches. |
264 | 264 | $result_array = $column_exist; |
265 | 265 | |
266 | - if (count($result_array)==1) |
|
267 | - $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'"; |
|
268 | - else |
|
269 | - $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'"; |
|
266 | + if (count($result_array)==1) { |
|
267 | + $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'"; |
|
268 | + } else { |
|
269 | + $str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'"; |
|
270 | + } |
|
270 | 271 | |
271 | 272 | |
272 | 273 | throw new TDBMException($str); |
@@ -348,10 +349,11 @@ discard block |
||
348 | 349 | if (count($pk_array)>1 && !$pk_set) { |
349 | 350 | $msg = "Error! You did not set the primary keys for the new object of type '$this->db_table_name'. TDBM usually assumes that the primary key is automatically set by the DB engine to the maximum value in the database. However, in this case, the '$this->db_table_name' table has a primary key on multiple columns. TDBM would be unable to find back this record after save. Please specify the primary keys for all new objects of kind '$this->db_table_name'."; |
350 | 351 | |
351 | - if (!$this->tdbmService->isProgramExiting()) |
|
352 | - throw new TDBMException($msg); |
|
353 | - else |
|
354 | - trigger_error($msg, E_USER_ERROR); |
|
352 | + if (!$this->tdbmService->isProgramExiting()) { |
|
353 | + throw new TDBMException($msg); |
|
354 | + } else { |
|
355 | + trigger_error($msg, E_USER_ERROR); |
|
356 | + } |
|
355 | 357 | } |
356 | 358 | |
357 | 359 | $sql = 'INSERT INTO '.$this->db_connection->escapeDBItem($this->db_table_name). |
@@ -360,8 +362,9 @@ discard block |
||
360 | 362 | |
361 | 363 | $first = true; |
362 | 364 | foreach ($this->db_row as $key=>$value) { |
363 | - if (!$first) |
|
364 | - $sql .= ','; |
|
365 | + if (!$first) { |
|
366 | + $sql .= ','; |
|
367 | + } |
|
365 | 368 | $sql .= $this->db_connection->quoteSmart($value); |
366 | 369 | $first=false; |
367 | 370 | } |
@@ -378,9 +381,9 @@ discard block |
||
378 | 381 | // trigger_error("program exiting"); |
379 | 382 | trigger_error($e->getMessage(), E_USER_ERROR); |
380 | 383 | |
381 | - if (!$this->tdbmService->isProgramExiting()) |
|
382 | - throw $e; |
|
383 | - else |
|
384 | + if (!$this->tdbmService->isProgramExiting()) { |
|
385 | + throw $e; |
|
386 | + } else |
|
384 | 387 | { |
385 | 388 | trigger_error($e->getMessage(), E_USER_ERROR); |
386 | 389 | } |
@@ -447,8 +450,9 @@ discard block |
||
447 | 450 | |
448 | 451 | $first = true; |
449 | 452 | foreach ($this->db_row as $key=>$value) { |
450 | - if (!$first) |
|
451 | - $sql .= ','; |
|
453 | + if (!$first) { |
|
454 | + $sql .= ','; |
|
455 | + } |
|
452 | 456 | $sql .= $this->db_connection->escapeDBItem($key)." = ".$this->db_connection->quoteSmart($value); |
453 | 457 | $first=false; |
454 | 458 | } |
@@ -456,10 +460,11 @@ discard block |
||
456 | 460 | try { |
457 | 461 | $this->db_connection->exec($sql); |
458 | 462 | } catch (TDBMException $e) { |
459 | - if (!$this->tdbmService->isProgramExiting()) |
|
460 | - throw $e; |
|
461 | - else |
|
462 | - trigger_error($e->getMessage(), E_USER_ERROR); |
|
463 | + if (!$this->tdbmService->isProgramExiting()) { |
|
464 | + throw $e; |
|
465 | + } else { |
|
466 | + trigger_error($e->getMessage(), E_USER_ERROR); |
|
467 | + } |
|
463 | 468 | } |
464 | 469 | |
465 | 470 | // Let's remove this object from the $new_objects static table. |
@@ -490,11 +495,13 @@ discard block |
||
490 | 495 | * |
491 | 496 | */ |
492 | 497 | public function discardChanges() { |
493 | - if ($this->TDBMObject_state == "new") |
|
494 | - throw new TDBMException("You cannot call discardChanges() on an object that has been created with getNewObject and that has not yet been saved."); |
|
498 | + if ($this->TDBMObject_state == "new") { |
|
499 | + throw new TDBMException("You cannot call discardChanges() on an object that has been created with getNewObject and that has not yet been saved."); |
|
500 | + } |
|
495 | 501 | |
496 | - if ($this->TDBMObject_state == "deleted") |
|
497 | - throw new TDBMException("You cannot call discardChanges() on an object that has been deleted."); |
|
502 | + if ($this->TDBMObject_state == "deleted") { |
|
503 | + throw new TDBMException("You cannot call discardChanges() on an object that has been deleted."); |
|
504 | + } |
|
498 | 505 | |
499 | 506 | $this->db_modified_state = false; |
500 | 507 | $this->TDBMObject_state = "not loaded"; |
@@ -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 | } |
@@ -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 |
@@ -695,10 +695,10 @@ discard block |
||
695 | 695 | |
696 | 696 | /** |
697 | 697 | * Returns a generator for the database. |
698 | - * @param unknown $result |
|
698 | + * @param \PDOStatement $result |
|
699 | 699 | * @param unknown $table_name |
700 | - * @param unknown $className |
|
701 | - * @param unknown $sql |
|
700 | + * @param string|null $className |
|
701 | + * @param string $sql |
|
702 | 702 | */ |
703 | 703 | private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) { |
704 | 704 | $keysStandardCased = array(); |
@@ -1084,7 +1084,7 @@ discard block |
||
1084 | 1084 | * @param unknown_type $target_tables |
1085 | 1085 | * @param unknown_type $path |
1086 | 1086 | * @param unknown_type $queue |
1087 | - * @return unknown |
|
1087 | + * @return boolean |
|
1088 | 1088 | */ |
1089 | 1089 | private function find_paths_iter(&$target_tables, &$path, &$queue) { |
1090 | 1090 | // Get table to look at: |
@@ -1559,7 +1559,7 @@ discard block |
||
1559 | 1559 | * Takes in input a filter_bag (which can be about anything from a string to an array of TDBMObjects... see above from documentation), |
1560 | 1560 | * and gives back a proper Filter object. |
1561 | 1561 | * |
1562 | - * @param unknown_type $filter_bag |
|
1562 | + * @param unknown_type|null $filter_bag |
|
1563 | 1563 | * @return FilterInterface |
1564 | 1564 | */ |
1565 | 1565 | public function buildFilterFromFilterBag($filter_bag) { |
@@ -1624,7 +1624,7 @@ discard block |
||
1624 | 1624 | * Takes in input an order_bag (which can be about anything from a string to an array of OrderByColumn objects... see above from documentation), |
1625 | 1625 | * and gives back an array of OrderByColumn / OrderBySQLString objects. |
1626 | 1626 | * |
1627 | - * @param unknown_type $orderby_bag |
|
1627 | + * @param unknown_type|null $orderby_bag |
|
1628 | 1628 | * @return array |
1629 | 1629 | */ |
1630 | 1630 | public function buildOrderArrayFromOrderBag($orderby_bag) { |
@@ -446,10 +446,11 @@ discard block |
||
446 | 446 | /*$data =*/ $this->dbConnection->getTableInfo($table_name); |
447 | 447 | } catch (TDBMException $exception) { |
448 | 448 | $probable_table_name = $this->dbConnection->checkTableExist($table_name); |
449 | - if ($probable_table_name == null) |
|
450 | - throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist."); |
|
451 | - else |
|
452 | - throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist. Maybe you meant the table '$probable_table_name'."); |
|
449 | + if ($probable_table_name == null) { |
|
450 | + throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist."); |
|
451 | + } else { |
|
452 | + throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist. Maybe you meant the table '$probable_table_name'."); |
|
453 | + } |
|
453 | 454 | } |
454 | 455 | |
455 | 456 | if ($className == null) { |
@@ -523,8 +524,9 @@ discard block |
||
523 | 524 | $sql = 'DELETE FROM '.$this->dbConnection->escapeDBItem($object->_getDbTableName()).' WHERE '.$sql_where; |
524 | 525 | $result = $this->dbConnection->exec($sql); |
525 | 526 | |
526 | - if ($result != 1) |
|
527 | - throw new TDBMException("Error while deleting object from table ".$object->_getDbTableName().": ".$result." have been affected."); |
|
527 | + if ($result != 1) { |
|
528 | + throw new TDBMException("Error while deleting object from table ".$object->_getDbTableName().": ".$result." have been affected."); |
|
529 | + } |
|
528 | 530 | |
529 | 531 | $this->objectStorage->remove($object->_getDbTableName(), $object_id); |
530 | 532 | $object->setTDBMObjectState("deleted"); |
@@ -639,8 +641,7 @@ discard block |
||
639 | 641 | 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); |
640 | 642 | } |
641 | 643 | $id = $row[$keysStandardCased[$pk_table[0]]]; |
642 | - } |
|
643 | - else |
|
644 | + } else |
|
644 | 645 | { |
645 | 646 | // Let's generate the serialized primary key from the columns! |
646 | 647 | $ids = array(); |
@@ -724,8 +725,7 @@ discard block |
||
724 | 725 | 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); |
725 | 726 | } |
726 | 727 | $id = $row[$keysStandardCased[$pk_table[0]]]; |
727 | - } |
|
728 | - else |
|
728 | + } else |
|
729 | 729 | { |
730 | 730 | // Let's generate the serialized primary key from the columns! |
731 | 731 | $ids = array(); |
@@ -894,8 +894,7 @@ discard block |
||
894 | 894 | foreach ($path as $constraint) { |
895 | 895 | if ($constraint['type']=='1*') { |
896 | 896 | $msg .= 'Table "'.$constraint['table1'].'" points to "'.$constraint['table2'].'" through its foreign key "'.$constraint['col1'].'"\n'; |
897 | - } |
|
898 | - elseif ($constraint['type']=='*1') { |
|
897 | + } elseif ($constraint['type']=='*1') { |
|
899 | 898 | $msg .= 'Table "'.$constraint['table1'].'" is pointed by "'.$constraint['table2'].'" through its foreign key "'.$constraint['col2'].'"\n'; |
900 | 899 | } |
901 | 900 | } |
@@ -983,8 +982,9 @@ discard block |
||
983 | 982 | // If any table has more than 1 way to be reached, throw an exception. |
984 | 983 | if (count($table_path['paths'])>1) { |
985 | 984 | // If this is the first ambiguity |
986 | - if (!$ambiguity) |
|
987 | - $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.'; |
|
985 | + if (!$ambiguity) { |
|
986 | + $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.'; |
|
987 | + } |
|
988 | 988 | |
989 | 989 | $msg .= "The table \"".$table_path['name']."\" can be reached using several different ways from the table \"$table\".\n\n"; |
990 | 990 | $count = 0; |
@@ -1025,8 +1025,7 @@ discard block |
||
1025 | 1025 | if (isset($this->cache['paths'][$table1][$table2])) |
1026 | 1026 | { |
1027 | 1027 | return $this->cache['paths'][$table1][$table2]; |
1028 | - } |
|
1029 | - elseif (isset($this->cache['paths'][$table2][$table1])) |
|
1028 | + } elseif (isset($this->cache['paths'][$table2][$table1])) |
|
1030 | 1029 | { |
1031 | 1030 | // Let's revert the path! |
1032 | 1031 | $toRevertPath = $this->cache['paths'][$table2][$table1]; |
@@ -1071,8 +1070,9 @@ discard block |
||
1071 | 1070 | break; |
1072 | 1071 | } |
1073 | 1072 | } |
1074 | - if (!$found) |
|
1075 | - $flat_path[] = $path_step; |
|
1073 | + if (!$found) { |
|
1074 | + $flat_path[] = $path_step; |
|
1075 | + } |
|
1076 | 1076 | } |
1077 | 1077 | } |
1078 | 1078 | return $flat_path; |
@@ -1107,8 +1107,9 @@ discard block |
||
1107 | 1107 | } |
1108 | 1108 | } |
1109 | 1109 | |
1110 | - if ($found) |
|
1111 | - return true; |
|
1110 | + if ($found) { |
|
1111 | + return true; |
|
1112 | + } |
|
1112 | 1113 | } |
1113 | 1114 | |
1114 | 1115 | } |
@@ -1131,16 +1132,16 @@ discard block |
||
1131 | 1132 | //echo "YOUHOU1! $current_table $col2"; |
1132 | 1133 | $already_done = true; |
1133 | 1134 | break; |
1134 | - } |
|
1135 | - elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1135 | + } elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1136 | 1136 | { |
1137 | 1137 | //echo "YOUHOU2! $current_table $col2"; |
1138 | 1138 | $already_done = true; |
1139 | 1139 | break; |
1140 | 1140 | } |
1141 | 1141 | } |
1142 | - if ($already_done) |
|
1143 | - continue; |
|
1142 | + if ($already_done) { |
|
1143 | + continue; |
|
1144 | + } |
|
1144 | 1145 | |
1145 | 1146 | $new_path = array_merge($path, array(array("table1"=>$table1, |
1146 | 1147 | "col1"=>$col1, |
@@ -1165,15 +1166,15 @@ discard block |
||
1165 | 1166 | { |
1166 | 1167 | $already_done = true; |
1167 | 1168 | break; |
1168 | - } |
|
1169 | - elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1169 | + } elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1170 | 1170 | { |
1171 | 1171 | $already_done = true; |
1172 | 1172 | break; |
1173 | 1173 | } |
1174 | 1174 | } |
1175 | - if ($already_done) |
|
1176 | - continue; |
|
1175 | + if ($already_done) { |
|
1176 | + continue; |
|
1177 | + } |
|
1177 | 1178 | |
1178 | 1179 | $new_path = array_merge($path, array(array("table1"=>$table2, |
1179 | 1180 | "col1"=>$col2, |
@@ -1413,16 +1414,15 @@ discard block |
||
1413 | 1414 | { |
1414 | 1415 | $sql = $this->dbConnection->escapeDBItem($table_name); //Make by Pierre PIV (add escapeDBItem) |
1415 | 1416 | |
1416 | - if ($mode == 'explainTree') |
|
1417 | - throw new TDBMException("TODO: explainTree not implemented for only one table."); |
|
1418 | - } |
|
1419 | - else { |
|
1417 | + if ($mode == 'explainTree') { |
|
1418 | + throw new TDBMException("TODO: explainTree not implemented for only one table."); |
|
1419 | + } |
|
1420 | + } else { |
|
1420 | 1421 | if ($hint_path!=null && $mode != 'explainTree') |
1421 | 1422 | { |
1422 | 1423 | $path = $hint_path; |
1423 | 1424 | $flat_path = $this->flatten_paths($path); |
1424 | - } |
|
1425 | - else |
|
1425 | + } else |
|
1426 | 1426 | { |
1427 | 1427 | $full_paths = $this->static_find_paths($table_name,$needed_table_array); |
1428 | 1428 | |
@@ -1530,8 +1530,9 @@ discard block |
||
1530 | 1530 | $sql = "SELECT COUNT(DISTINCT $pk_str) FROM $sql"; |
1531 | 1531 | |
1532 | 1532 | $where_clause = $filter->toSql($this->dbConnection); |
1533 | - if ($where_clause != '') |
|
1534 | - $sql .= ' WHERE '.$where_clause; |
|
1533 | + if ($where_clause != '') { |
|
1534 | + $sql .= ' WHERE '.$where_clause; |
|
1535 | + } |
|
1535 | 1536 | |
1536 | 1537 | // Now, let's perform the request: |
1537 | 1538 | $result = $this->dbConnection->getOne($sql, array()); |
@@ -1542,8 +1543,9 @@ discard block |
||
1542 | 1543 | $sql = "SELECT DISTINCT ".$this->dbConnection->escapeDBItem($table_name).".* $orderby_column_statement FROM $sql"; |
1543 | 1544 | |
1544 | 1545 | $where_clause = $filter->toSql($this->dbConnection); |
1545 | - if ($where_clause != '') |
|
1546 | - $sql .= ' WHERE '.$where_clause; |
|
1546 | + if ($where_clause != '') { |
|
1547 | + $sql .= ' WHERE '.$where_clause; |
|
1548 | + } |
|
1547 | 1549 | |
1548 | 1550 | $sql .= $orderby_statement; |
1549 | 1551 | |
@@ -1568,8 +1570,7 @@ discard block |
||
1568 | 1570 | $filter_bag = array(); |
1569 | 1571 | } elseif (!is_array($filter_bag)) { |
1570 | 1572 | $filter_bag = array($filter_bag); |
1571 | - } |
|
1572 | - elseif (is_a($filter_bag, 'Mouf\\Database\\TDBM\\TDBMObjectArray')) { |
|
1573 | + } elseif (is_a($filter_bag, 'Mouf\\Database\\TDBM\\TDBMObjectArray')) { |
|
1573 | 1574 | $filter_bag = array($filter_bag); |
1574 | 1575 | } |
1575 | 1576 | |
@@ -1631,8 +1632,9 @@ discard block |
||
1631 | 1632 | // Fourth, let's apply the same steps to the orderby_bag |
1632 | 1633 | // 4-1 orderby_bag should be an array, if it is a singleton, let's put it in an array. |
1633 | 1634 | |
1634 | - if (!is_array($orderby_bag)) |
|
1635 | - $orderby_bag = array($orderby_bag); |
|
1635 | + if (!is_array($orderby_bag)) { |
|
1636 | + $orderby_bag = array($orderby_bag); |
|
1637 | + } |
|
1636 | 1638 | |
1637 | 1639 | // 4-2, let's take all the objects out of the orderby bag, and let's make objects from them |
1638 | 1640 | $orderby_bag2 = array(); |
@@ -1662,10 +1664,11 @@ discard block |
||
1662 | 1664 | $possible_tables = $this->dbConnection->checkTableExist($table); |
1663 | 1665 | if ($possible_tables !== true) |
1664 | 1666 | { |
1665 | - if (count($possible_tables)==1) |
|
1666 | - $str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'"; |
|
1667 | - else |
|
1668 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'"; |
|
1667 | + if (count($possible_tables)==1) { |
|
1668 | + $str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'"; |
|
1669 | + } else { |
|
1670 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'"; |
|
1671 | + } |
|
1669 | 1672 | throw new TDBMException($str); |
1670 | 1673 | } |
1671 | 1674 | } |
@@ -1699,16 +1702,15 @@ discard block |
||
1699 | 1702 | $link['col2']==$child->keyParent && |
1700 | 1703 | $link['type']==$child->link_type) { |
1701 | 1704 | $current_node = $child; |
1702 | - } |
|
1703 | - else |
|
1705 | + } else |
|
1704 | 1706 | { |
1705 | 1707 | // Now, we must add the rest of the links to the tree. |
1706 | 1708 | $found = false; |
1707 | 1709 | } |
1708 | 1710 | } |
1711 | + } else { |
|
1712 | + $found = false; |
|
1709 | 1713 | } |
1710 | - else |
|
1711 | - $found = false; |
|
1712 | 1714 | |
1713 | 1715 | } |
1714 | 1716 | |
@@ -1780,13 +1782,14 @@ discard block |
||
1780 | 1782 | // Unable to find primary key.... this is an error |
1781 | 1783 | // Let's try to be precise in error reporting. Let's try to find the table. |
1782 | 1784 | $tables = $this->dbConnection->checkTableExist($table); |
1783 | - if ($tables === true) |
|
1784 | - throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table."); |
|
1785 | - elseif ($tables !== null) { |
|
1786 | - if (count($tables)==1) |
|
1787 | - $str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'"; |
|
1788 | - else |
|
1789 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'"; |
|
1785 | + if ($tables === true) { |
|
1786 | + throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table."); |
|
1787 | + } elseif ($tables !== null) { |
|
1788 | + if (count($tables)==1) { |
|
1789 | + $str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'"; |
|
1790 | + } else { |
|
1791 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'"; |
|
1792 | + } |
|
1790 | 1793 | throw new TDBMException($str); |
1791 | 1794 | } |
1792 | 1795 | } |
@@ -531,45 +531,45 @@ discard block |
||
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
534 | - /** |
|
535 | - * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
536 | - * by parameter before all. |
|
537 | - * |
|
538 | - * Notice: if the object has a multiple primary key, the function will not work. |
|
539 | - * |
|
540 | - * @param TDBMObject $objToDelete |
|
541 | - */ |
|
542 | - public function deleteCascade(TDBMObject $objToDelete) { |
|
543 | - $this->deleteAllConstraintWithThisObject($objToDelete); |
|
544 | - $this->deleteObject($objToDelete); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * This function is used only in TDBMService (private function) |
|
549 | - * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
550 | - * |
|
551 | - * @param TDBMObject $obj |
|
552 | - * @return TDBMObjectArray |
|
553 | - */ |
|
554 | - private function deleteAllConstraintWithThisObject(TDBMObject $obj) { |
|
555 | - $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName()); |
|
556 | - $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom); |
|
557 | - foreach ($constraints as $constraint) { |
|
558 | - $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]); |
|
559 | - $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]); |
|
560 | - $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]); |
|
561 | - $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]); |
|
562 | - $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id); |
|
563 | - $sql = "SELECT DISTINCT ".$tableTo.".*" |
|
564 | - ." FROM ".$tableFrom |
|
565 | - ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo |
|
566 | - ." WHERE ".$tableFrom.".".$idVarName."=".$idValue; |
|
567 | - $result = $this->getObjectsFromSQL($constraint["table1"], $sql); |
|
568 | - foreach ($result as $tdbmObj) { |
|
569 | - $this->deleteCascade($tdbmObj); |
|
570 | - } |
|
571 | - } |
|
572 | - } |
|
534 | + /** |
|
535 | + * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
536 | + * by parameter before all. |
|
537 | + * |
|
538 | + * Notice: if the object has a multiple primary key, the function will not work. |
|
539 | + * |
|
540 | + * @param TDBMObject $objToDelete |
|
541 | + */ |
|
542 | + public function deleteCascade(TDBMObject $objToDelete) { |
|
543 | + $this->deleteAllConstraintWithThisObject($objToDelete); |
|
544 | + $this->deleteObject($objToDelete); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * This function is used only in TDBMService (private function) |
|
549 | + * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
550 | + * |
|
551 | + * @param TDBMObject $obj |
|
552 | + * @return TDBMObjectArray |
|
553 | + */ |
|
554 | + private function deleteAllConstraintWithThisObject(TDBMObject $obj) { |
|
555 | + $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName()); |
|
556 | + $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom); |
|
557 | + foreach ($constraints as $constraint) { |
|
558 | + $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]); |
|
559 | + $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]); |
|
560 | + $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]); |
|
561 | + $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]); |
|
562 | + $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id); |
|
563 | + $sql = "SELECT DISTINCT ".$tableTo.".*" |
|
564 | + ." FROM ".$tableFrom |
|
565 | + ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo |
|
566 | + ." WHERE ".$tableFrom.".".$idVarName."=".$idValue; |
|
567 | + $result = $this->getObjectsFromSQL($constraint["table1"], $sql); |
|
568 | + foreach ($result as $tdbmObj) { |
|
569 | + $this->deleteCascade($tdbmObj); |
|
570 | + } |
|
571 | + } |
|
572 | + } |
|
573 | 573 | |
574 | 574 | /** |
575 | 575 | * The getObjectsFromSQL is used to retrieve objects from the database using a full SQL query. |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | } |
619 | 619 | $keysStandardCased = array(); |
620 | 620 | $firstLine = true; |
621 | - $colsArray = null; |
|
621 | + $colsArray = null; |
|
622 | 622 | while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC)) |
623 | 623 | { |
624 | 624 | $row = array(); |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | $id = serialize($ids); |
651 | 651 | } |
652 | 652 | |
653 | - $obj = $this->objectStorage->get($table_name,$id); |
|
653 | + $obj = $this->objectStorage->get($table_name,$id); |
|
654 | 654 | if ($obj === null) |
655 | 655 | { |
656 | 656 | if ($className == null) { |
@@ -663,10 +663,10 @@ discard block |
||
663 | 663 | } else { |
664 | 664 | throw new TDBMException("Error while casting TDBMObject to class, the parameter passed is not a string. Value passed: ".$className); |
665 | 665 | } |
666 | - $obj->loadFromRow($row, $colsArray); |
|
667 | - $this->objectStorage->set($table_name, $id, $obj); |
|
666 | + $obj->loadFromRow($row, $colsArray); |
|
667 | + $this->objectStorage->set($table_name, $id, $obj); |
|
668 | 668 | } elseif ($obj->_getStatus() == "not loaded") { |
669 | - $obj->loadFromRow($row, $colsArray); |
|
669 | + $obj->loadFromRow($row, $colsArray); |
|
670 | 670 | // Check that the object fetched from cache is from the requested class. |
671 | 671 | if ($className != null) { |
672 | 672 | if (!is_subclass_of(get_class($obj), $className) && get_class($obj) != $className) { |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) { |
704 | 704 | $keysStandardCased = array(); |
705 | 705 | $firstLine = true; |
706 | - $colsArray = null; |
|
706 | + $colsArray = null; |
|
707 | 707 | while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC)) |
708 | 708 | { |
709 | 709 | $row = array(); |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | } |
735 | 735 | $id = serialize($ids); |
736 | 736 | } |
737 | - $obj = $this->objectStorage->get($table_name, $id); |
|
737 | + $obj = $this->objectStorage->get($table_name, $id); |
|
738 | 738 | if ($obj === null) |
739 | 739 | { |
740 | 740 | if ($className == null) { |
@@ -747,10 +747,10 @@ discard block |
||
747 | 747 | } else { |
748 | 748 | throw new TDBMException("Error while casting TDBMObject to class, the parameter passed is not a string. Value passed: ".$className); |
749 | 749 | } |
750 | - $obj->loadFromRow($row, $colsArray); |
|
751 | - $this->objectStorage->set($table_name, $id, $obj); |
|
750 | + $obj->loadFromRow($row, $colsArray); |
|
751 | + $this->objectStorage->set($table_name, $id, $obj); |
|
752 | 752 | } elseif ($obj->_getStatus() == "not loaded") { |
753 | - $obj->loadFromRow($row, $colsArray); |
|
753 | + $obj->loadFromRow($row, $colsArray); |
|
754 | 754 | // Check that the object fetched from cache is from the requested class. |
755 | 755 | if ($className != null) { |
756 | 756 | if (!is_subclass_of(get_class($obj), $className) && get_class($obj) != $className) { |
@@ -1455,33 +1455,33 @@ discard block |
||
1455 | 1455 | |
1456 | 1456 | |
1457 | 1457 | //If no $hint_path is provided, check that a path exists |
1458 | - if($hint_path === null){ |
|
1459 | - // 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 |
|
1460 | - foreach ($needed_table_array_for_orderby as $target_table_table) { |
|
1461 | - // Get the path between the main table and the target group by table |
|
1458 | + if($hint_path === null){ |
|
1459 | + // 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 |
|
1460 | + foreach ($needed_table_array_for_orderby as $target_table_table) { |
|
1461 | + // Get the path between the main table and the target group by table |
|
1462 | 1462 | |
1463 | - // TODO! Pas bon!!!! Faut le quérir, hélas! |
|
1464 | - // Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni????? |
|
1463 | + // TODO! Pas bon!!!! Faut le quérir, hélas! |
|
1464 | + // Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni????? |
|
1465 | 1465 | |
1466 | - $path = $this->getPathFromCache($table_name, $target_table_table); |
|
1466 | + $path = $this->getPathFromCache($table_name, $target_table_table); |
|
1467 | 1467 | |
1468 | - /********************************** |
|
1468 | + /********************************** |
|
1469 | 1469 | * Modifier par Marc de *1 vers 1* |
1470 | 1470 | * (sur les conseils de David !) |
1471 | 1471 | */ |
1472 | - $is_ok = true; |
|
1473 | - foreach ($path as $step) { |
|
1474 | - if ($step["type"]=="1*") { |
|
1475 | - $is_ok = false; |
|
1476 | - break; |
|
1477 | - } |
|
1478 | - } |
|
1479 | - |
|
1480 | - if (!$is_ok) { |
|
1481 | - 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."); |
|
1482 | - } |
|
1483 | - } |
|
1484 | - } |
|
1472 | + $is_ok = true; |
|
1473 | + foreach ($path as $step) { |
|
1474 | + if ($step["type"]=="1*") { |
|
1475 | + $is_ok = false; |
|
1476 | + break; |
|
1477 | + } |
|
1478 | + } |
|
1479 | + |
|
1480 | + if (!$is_ok) { |
|
1481 | + 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."); |
|
1482 | + } |
|
1483 | + } |
|
1484 | + } |
|
1485 | 1485 | |
1486 | 1486 | // In a SELECT DISTINCT ... ORDER BY ... clause, the orderbyed columns must appear! |
1487 | 1487 | // Therefore, we must be able to parse the Orderby columns requested, give them dummy names and remove them afterward! |
@@ -1656,9 +1656,9 @@ discard block |
||
1656 | 1656 | * Throws a TDBMException if one of those table does not exist. |
1657 | 1657 | * |
1658 | 1658 | * @param array $tables |
1659 | - * @throws TDBMException |
|
1659 | + * @throws TDBMException |
|
1660 | 1660 | */ |
1661 | - private function checkTablesExist($tables) { |
|
1661 | + private function checkTablesExist($tables) { |
|
1662 | 1662 | foreach ($tables as $table) { |
1663 | 1663 | $possible_tables = $this->dbConnection->checkTableExist($table); |
1664 | 1664 | if ($possible_tables !== true) |
@@ -1731,12 +1731,12 @@ discard block |
||
1731 | 1731 | * This function returns the HTML to draw a tree of DisplayNode. |
1732 | 1732 | * |
1733 | 1733 | * @param DisplayNode $tree |
1734 | - * @param int $x |
|
1735 | - * @param int $y |
|
1736 | - * @param int $ret_width |
|
1737 | - * @param int $ret_height |
|
1738 | - * |
|
1739 | - * @return string |
|
1734 | + * @param int $x |
|
1735 | + * @param int $y |
|
1736 | + * @param int $ret_width |
|
1737 | + * @param int $ret_height |
|
1738 | + * |
|
1739 | + * @return string |
|
1740 | 1740 | */ |
1741 | 1741 | public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) { |
1742 | 1742 |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | private $cacheKey = "__TDBM_Cache__"; |
143 | 143 | |
144 | 144 | public function __construct() { |
145 | - register_shutdown_function(array($this,"completeSaveOnExit")); |
|
145 | + register_shutdown_function(array($this, "completeSaveOnExit")); |
|
146 | 146 | if (extension_loaded('weakref')) { |
147 | 147 | $this->objectStorage = new WeakrefObjectStorage(); |
148 | 148 | } else { |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $objects = $this->getObjects($table_name, $filters, null, null, null, $className); |
363 | 363 | if (count($objects) == 0) { |
364 | 364 | return null; |
365 | - } elseif (count($objects) > 1) { |
|
365 | + } elseif (count($objects)>1) { |
|
366 | 366 | 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."); |
367 | 367 | } |
368 | 368 | // Return the first and only object. |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * @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. |
436 | 436 | * @return TDBMObject |
437 | 437 | */ |
438 | - public function getNewObject($table_name, $auto_assign_id=true, $className = null) { |
|
438 | + public function getNewObject($table_name, $auto_assign_id = true, $className = null) { |
|
439 | 439 | if ($this->dbConnection == null) { |
440 | 440 | throw new TDBMException("Error while calling TDBMObject::getNewObject(): No connection has been established on the database!"); |
441 | 441 | } |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | } |
466 | 466 | |
467 | 467 | if ($auto_assign_id && !$this->isPrimaryKeyAutoIncrement($table_name)) { |
468 | - $pk_table = $this->getPrimaryKeyStatic($table_name); |
|
469 | - if (count($pk_table)==1) |
|
468 | + $pk_table = $this->getPrimaryKeyStatic($table_name); |
|
469 | + if (count($pk_table) == 1) |
|
470 | 470 | { |
471 | 471 | $root_table = $this->dbConnection->findRootSequenceTable($table_name); |
472 | 472 | $id = $this->dbConnection->nextId($root_table); |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | $sql = "SELECT MAX(".$this->dbConnection->escapeDBItem($pk_table[0]).") AS maxkey FROM ".$root_table; |
477 | 477 | $res = $this->dbConnection->getAll($sql); |
478 | 478 | // NOTE: this will work only if the ID is an integer! |
479 | - $newid = $res[0]['maxkey'] + 1; |
|
479 | + $newid = $res[0]['maxkey']+1; |
|
480 | 480 | if ($newid>$id) { |
481 | 481 | $id = $newid; |
482 | 482 | } |
@@ -506,17 +506,17 @@ discard block |
||
506 | 506 | // Now for the object_id |
507 | 507 | $object_id = $object->TDBMObject_id; |
508 | 508 | // If there is only one primary key: |
509 | - if (count($pk_table)==1) { |
|
509 | + if (count($pk_table) == 1) { |
|
510 | 510 | $sql_where = $this->dbConnection->escapeDBItem($pk_table[0])."=".$this->dbConnection->quoteSmart($object->TDBMObject_id); |
511 | 511 | } else { |
512 | 512 | $ids = unserialize($object_id); |
513 | - $i=0; |
|
513 | + $i = 0; |
|
514 | 514 | $sql_where_array = array(); |
515 | 515 | foreach ($pk_table as $pk) { |
516 | 516 | $sql_where_array[] = $this->dbConnection->escapeDBItem($pk)."=".$this->dbConnection->quoteSmart($ids[$i]); |
517 | 517 | $i++; |
518 | 518 | } |
519 | - $sql_where = implode(" AND ",$sql_where_array); |
|
519 | + $sql_where = implode(" AND ", $sql_where_array); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | * @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. |
600 | 600 | * @return array|Generator|TDBMObjectArray The result set of the query as a TDBMObjectArray (an array of TDBMObjects with special properties) |
601 | 601 | */ |
602 | - public function getObjectsFromSQL($table_name, $sql, $from=null, $limit=null, $className=null) { |
|
602 | + public function getObjectsFromSQL($table_name, $sql, $from = null, $limit = null, $className = null) { |
|
603 | 603 | if ($this->dbConnection == null) { |
604 | 604 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
605 | 605 | } |
@@ -630,10 +630,10 @@ discard block |
||
630 | 630 | $firstLine = false; |
631 | 631 | } |
632 | 632 | foreach ($fullCaseRow as $key=>$value) { |
633 | - $row[$keysStandardCased[$key]]=$value; |
|
633 | + $row[$keysStandardCased[$key]] = $value; |
|
634 | 634 | } |
635 | 635 | $pk_table = $this->primary_keys[$table_name]; |
636 | - if (count($pk_table)==1) |
|
636 | + if (count($pk_table) == 1) |
|
637 | 637 | { |
638 | 638 | if (!isset($keysStandardCased[$pk_table[0]])) { |
639 | 639 | 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); |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | $id = serialize($ids); |
651 | 651 | } |
652 | 652 | |
653 | - $obj = $this->objectStorage->get($table_name,$id); |
|
653 | + $obj = $this->objectStorage->get($table_name, $id); |
|
654 | 654 | if ($obj === null) |
655 | 655 | { |
656 | 656 | if ($className == null) { |
@@ -715,10 +715,10 @@ discard block |
||
715 | 715 | $firstLine = false; |
716 | 716 | } |
717 | 717 | foreach ($fullCaseRow as $key=>$value) { |
718 | - $row[$keysStandardCased[$key]]=$value; |
|
718 | + $row[$keysStandardCased[$key]] = $value; |
|
719 | 719 | } |
720 | 720 | $pk_table = $this->primary_keys[$table_name]; |
721 | - if (count($pk_table)==1) |
|
721 | + if (count($pk_table) == 1) |
|
722 | 722 | { |
723 | 723 | if (!isset($keysStandardCased[$pk_table[0]])) { |
724 | 724 | 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); |
@@ -813,14 +813,14 @@ discard block |
||
813 | 813 | // Now, let's commit or rollback if needed. |
814 | 814 | if ($this->dbConnection != null && $this->dbConnection->hasActiveTransaction()) { |
815 | 815 | if ($this->commitOnQuit) { |
816 | - try { |
|
816 | + try { |
|
817 | 817 | $this->dbConnection->commit(); |
818 | 818 | } catch (Exception $e) { |
819 | 819 | echo $e->getMessage()."<br/>"; |
820 | 820 | echo $e->getTraceAsString(); |
821 | 821 | } |
822 | 822 | } else { |
823 | - try { |
|
823 | + try { |
|
824 | 824 | $this->dbConnection->rollback(); |
825 | 825 | } catch (Exception $e) { |
826 | 826 | echo $e->getMessage()."<br/>"; |
@@ -881,21 +881,21 @@ discard block |
||
881 | 881 | * @param string $sql |
882 | 882 | * @return array the result of your query |
883 | 883 | */ |
884 | - public function getTransientObjectsFromSQL($sql,$classname=null) { |
|
884 | + public function getTransientObjectsFromSQL($sql, $classname = null) { |
|
885 | 885 | if ($this->dbConnection == null) { |
886 | 886 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
887 | 887 | } |
888 | - return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS,$classname); |
|
888 | + return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS, $classname); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | |
892 | 892 | private function to_explain_string($path) { |
893 | 893 | $msg = ''; |
894 | 894 | foreach ($path as $constraint) { |
895 | - if ($constraint['type']=='1*') { |
|
895 | + if ($constraint['type'] == '1*') { |
|
896 | 896 | $msg .= 'Table "'.$constraint['table1'].'" points to "'.$constraint['table2'].'" through its foreign key "'.$constraint['col1'].'"\n'; |
897 | 897 | } |
898 | - elseif ($constraint['type']=='*1') { |
|
898 | + elseif ($constraint['type'] == '*1') { |
|
899 | 899 | $msg .= 'Table "'.$constraint['table1'].'" is pointed by "'.$constraint['table2'].'" through its foreign key "'.$constraint['col2'].'"\n'; |
900 | 900 | } |
901 | 901 | } |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | $this->loadCache(); |
915 | 915 | |
916 | 916 | $path = array(); |
917 | - $queue = array(array($table,array())); |
|
917 | + $queue = array(array($table, array())); |
|
918 | 918 | |
919 | 919 | $found = false; |
920 | 920 | $found_depth = 0; |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | { |
950 | 950 | break; |
951 | 951 | } |
952 | - if ($ret==true) |
|
952 | + if ($ret == true) |
|
953 | 953 | { |
954 | 954 | // Ok, we got one, we will continue a bit more until we reach the next level in the tree, |
955 | 955 | // just to see if there is no ambiguity |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | } |
960 | 960 | |
961 | 961 | // At each iteration, let's check the time. |
962 | - if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time > $max_execution_time && $max_execution_time!=0) { |
|
962 | + if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time>$max_execution_time && $max_execution_time != 0) { |
|
963 | 963 | // Call check table names |
964 | 964 | $this->checkTablesExist($tables); |
965 | 965 | |
@@ -970,11 +970,11 @@ discard block |
||
970 | 970 | } |
971 | 971 | } |
972 | 972 | |
973 | - $ambiguity =false; |
|
973 | + $ambiguity = false; |
|
974 | 974 | $msg = ''; |
975 | 975 | foreach ($tables_paths as $table_path) { |
976 | 976 | // If any table has not been found, throw an exception |
977 | - if (!isset($table_path['founddepth']) || $table_path['founddepth']==null) { |
|
977 | + if (!isset($table_path['founddepth']) || $table_path['founddepth'] == null) { |
|
978 | 978 | // First, check if the tables do exist. |
979 | 979 | $this->checkTablesExist(array($table, $table_path['name'])); |
980 | 980 | // Else, throw an error. |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | 'table2' => $depArr['table1'], |
1037 | 1037 | 'col1' => $depArr['col2'], |
1038 | 1038 | 'col2' => $depArr['col1'], |
1039 | - 'type' => (($depArr['type'] == '1*')?'*1':'1*') |
|
1039 | + 'type' => (($depArr['type'] == '1*') ? '*1' : '1*') |
|
1040 | 1040 | ); |
1041 | 1041 | }, $toRevertPath); |
1042 | 1042 | return array_reverse($invertedDependencies); |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | * @param unknown_type $paths |
1055 | 1055 | */ |
1056 | 1056 | private function flatten_paths($paths) { |
1057 | - $flat_path=array(); |
|
1057 | + $flat_path = array(); |
|
1058 | 1058 | foreach ($paths as $path_bigarray) { |
1059 | 1059 | $path = $path_bigarray['paths'][0]; |
1060 | 1060 | |
@@ -1093,9 +1093,9 @@ discard block |
||
1093 | 1093 | $path = $current_vars[1]; |
1094 | 1094 | |
1095 | 1095 | foreach ($target_tables as $id=>$target_table) { |
1096 | - if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth']==null || $target_table['founddepth']==count($path))) { |
|
1096 | + if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth'] == null || $target_table['founddepth'] == count($path))) { |
|
1097 | 1097 | // When a path is found to a table, we mark the table as found with its depth. |
1098 | - $target_tables[$id]['founddepth']=count($path); |
|
1098 | + $target_tables[$id]['founddepth'] = count($path); |
|
1099 | 1099 | |
1100 | 1100 | // Then we add the path to table to the target_tables array |
1101 | 1101 | $target_tables[$id]['paths'][] = $path; |
@@ -1126,13 +1126,13 @@ discard block |
||
1126 | 1126 | $already_done = false; |
1127 | 1127 | foreach ($path as $previous_constraint) |
1128 | 1128 | { |
1129 | - if ($previous_constraint['type']=='1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"]) |
|
1129 | + if ($previous_constraint['type'] == '1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"]) |
|
1130 | 1130 | { |
1131 | 1131 | //echo "YOUHOU1! $current_table $col2"; |
1132 | 1132 | $already_done = true; |
1133 | 1133 | break; |
1134 | 1134 | } |
1135 | - elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1135 | + elseif ($previous_constraint['type'] == '*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"]) |
|
1136 | 1136 | { |
1137 | 1137 | //echo "YOUHOU2! $current_table $col2"; |
1138 | 1138 | $already_done = true; |
@@ -1161,12 +1161,12 @@ discard block |
||
1161 | 1161 | $already_done = false; |
1162 | 1162 | foreach ($path as $previous_constraint) |
1163 | 1163 | { |
1164 | - if ($previous_constraint['type']=='1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"]) |
|
1164 | + if ($previous_constraint['type'] == '1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"]) |
|
1165 | 1165 | { |
1166 | 1166 | $already_done = true; |
1167 | 1167 | break; |
1168 | 1168 | } |
1169 | - elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1169 | + elseif ($previous_constraint['type'] == '*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"]) |
|
1170 | 1170 | { |
1171 | 1171 | $already_done = true; |
1172 | 1172 | break; |
@@ -1275,7 +1275,7 @@ discard block |
||
1275 | 1275 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1276 | 1276 | * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query. |
1277 | 1277 | */ |
1278 | - public function getObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) { |
|
1278 | + public function getObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) { |
|
1279 | 1279 | if ($this->dbConnection == null) { |
1280 | 1280 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1281 | 1281 | } |
@@ -1291,7 +1291,7 @@ discard block |
||
1291 | 1291 | * @param unknown_type $hint_path |
1292 | 1292 | * @return integer |
1293 | 1293 | */ |
1294 | - public function getCount($table_name, $filter_bag=null, $hint_path=null) { |
|
1294 | + public function getCount($table_name, $filter_bag = null, $hint_path = null) { |
|
1295 | 1295 | if ($this->dbConnection == null) { |
1296 | 1296 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1297 | 1297 | } |
@@ -1309,7 +1309,7 @@ discard block |
||
1309 | 1309 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1310 | 1310 | * @return string The SQL that would be executed. |
1311 | 1311 | */ |
1312 | - public function explainSQLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) { |
|
1312 | + public function explainSQLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) { |
|
1313 | 1313 | if ($this->dbConnection == null) { |
1314 | 1314 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1315 | 1315 | } |
@@ -1327,7 +1327,7 @@ discard block |
||
1327 | 1327 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1328 | 1328 | * @return string The SQL that would be executed. |
1329 | 1329 | */ |
1330 | - public function explainRequestAsTextGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) { |
|
1330 | + public function explainRequestAsTextGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) { |
|
1331 | 1331 | if ($this->dbConnection == null) { |
1332 | 1332 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1333 | 1333 | } |
@@ -1348,12 +1348,12 @@ discard block |
||
1348 | 1348 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1349 | 1349 | * @return string The SQL that would be executed. |
1350 | 1350 | */ |
1351 | - public function explainRequestAsHTMLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null, $x=10, $y=10) { |
|
1351 | + public function explainRequestAsHTMLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null, $x = 10, $y = 10) { |
|
1352 | 1352 | if ($this->dbConnection == null) { |
1353 | 1353 | throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!"); |
1354 | 1354 | } |
1355 | 1355 | $tree = $this->getObjectsByMode('explainTree', $table_name, $filter_bag, $orderby_bag, $from, $limit, $hint_path); |
1356 | - return $this->drawTree($tree,$x,$y); |
|
1356 | + return $this->drawTree($tree, $x, $y); |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | /** |
@@ -1370,7 +1370,7 @@ discard block |
||
1370 | 1370 | * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null). |
1371 | 1371 | * @return array|Generator|TDBMObjectArray An array or object containing the resulting objects of the query. |
1372 | 1372 | */ |
1373 | - public function getObjectsByMode($mode, $table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) { |
|
1373 | + public function getObjectsByMode($mode, $table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) { |
|
1374 | 1374 | $this->completeSave(); |
1375 | 1375 | $this->loadCache(); |
1376 | 1376 | |
@@ -1409,7 +1409,7 @@ discard block |
||
1409 | 1409 | } |
1410 | 1410 | } |
1411 | 1411 | |
1412 | - if (count($needed_table_array)==0) |
|
1412 | + if (count($needed_table_array) == 0) |
|
1413 | 1413 | { |
1414 | 1414 | $sql = $this->dbConnection->escapeDBItem($table_name); //Make by Pierre PIV (add escapeDBItem) |
1415 | 1415 | |
@@ -1417,14 +1417,14 @@ discard block |
||
1417 | 1417 | throw new TDBMException("TODO: explainTree not implemented for only one table."); |
1418 | 1418 | } |
1419 | 1419 | else { |
1420 | - if ($hint_path!=null && $mode != 'explainTree') |
|
1420 | + if ($hint_path != null && $mode != 'explainTree') |
|
1421 | 1421 | { |
1422 | 1422 | $path = $hint_path; |
1423 | 1423 | $flat_path = $this->flatten_paths($path); |
1424 | 1424 | } |
1425 | 1425 | else |
1426 | 1426 | { |
1427 | - $full_paths = $this->static_find_paths($table_name,$needed_table_array); |
|
1427 | + $full_paths = $this->static_find_paths($table_name, $needed_table_array); |
|
1428 | 1428 | |
1429 | 1429 | if ($mode == 'explainTree') { |
1430 | 1430 | return $this->getTablePathsTree($full_paths); |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | |
1456 | 1456 | |
1457 | 1457 | //If no $hint_path is provided, check that a path exists |
1458 | - if($hint_path === null){ |
|
1458 | + if ($hint_path === null) { |
|
1459 | 1459 | // 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 |
1460 | 1460 | foreach ($needed_table_array_for_orderby as $target_table_table) { |
1461 | 1461 | // Get the path between the main table and the target group by table |
@@ -1471,7 +1471,7 @@ discard block |
||
1471 | 1471 | */ |
1472 | 1472 | $is_ok = true; |
1473 | 1473 | foreach ($path as $step) { |
1474 | - if ($step["type"]=="1*") { |
|
1474 | + if ($step["type"] == "1*") { |
|
1475 | 1475 | $is_ok = false; |
1476 | 1476 | break; |
1477 | 1477 | } |
@@ -1497,7 +1497,7 @@ discard block |
||
1497 | 1497 | $orderby_columns_array = array_merge($orderby_columns_array, $orderby_object->toSqlStatementsArray()); |
1498 | 1498 | } |
1499 | 1499 | |
1500 | - $orderby_statement = ' ORDER BY '.implode(',',$orderby_columns_array); |
|
1500 | + $orderby_statement = ' ORDER BY '.implode(',', $orderby_columns_array); |
|
1501 | 1501 | $count = 0; |
1502 | 1502 | foreach ($orderby_columns_array as $id=>$orderby_statement_phrase) { |
1503 | 1503 | // Let's remove the trailing ASC or DESC and add AS tdbm_reserved_col_Xxx |
@@ -1515,10 +1515,10 @@ discard block |
||
1515 | 1515 | $orderby_columns_array[$id] = $orderby_statement_phrase.' AS tdbm_reserved_col_'.$count; |
1516 | 1516 | $count++; |
1517 | 1517 | } |
1518 | - $orderby_column_statement = ', '.implode(',',$orderby_columns_array); |
|
1518 | + $orderby_column_statement = ', '.implode(',', $orderby_columns_array); |
|
1519 | 1519 | } |
1520 | 1520 | |
1521 | - if ($mode=="getCount") { |
|
1521 | + if ($mode == "getCount") { |
|
1522 | 1522 | // Let's get the list of primary keys to perform a DISTINCT request. |
1523 | 1523 | $pk_table = $this->getPrimaryKeyStatic($table_name); |
1524 | 1524 | |
@@ -1552,7 +1552,7 @@ discard block |
||
1552 | 1552 | if ($mode == 'explainSQL') { |
1553 | 1553 | return $sql; |
1554 | 1554 | } |
1555 | - return $this->getObjectsFromSQL($table_name, $sql, $from, $limit, $className); |
|
1555 | + return $this->getObjectsFromSQL($table_name, $sql, $from, $limit, $className); |
|
1556 | 1556 | |
1557 | 1557 | } |
1558 | 1558 | |
@@ -1577,17 +1577,17 @@ discard block |
||
1577 | 1577 | // Second, let's take all the objects out of the filter bag, and let's make filters from them |
1578 | 1578 | $filter_bag2 = array(); |
1579 | 1579 | foreach ($filter_bag as $thing) { |
1580 | - if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) { |
|
1580 | + if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) { |
|
1581 | 1581 | $filter_bag2[] = $thing; |
1582 | 1582 | } elseif (is_string($thing)) { |
1583 | 1583 | $filter_bag2[] = new SqlStringFilter($thing); |
1584 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) { |
|
1584 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) { |
|
1585 | 1585 | // Get table_name and column_name |
1586 | 1586 | $filter_table_name = $thing[0]->_getDbTableName(); |
1587 | 1587 | $filter_column_names = $thing[0]->getPrimaryKey(); |
1588 | 1588 | |
1589 | 1589 | // If there is only one primary key, we can use the InFilter |
1590 | - if (count($filter_column_names)==1) { |
|
1590 | + if (count($filter_column_names) == 1) { |
|
1591 | 1591 | $primary_keys_array = array(); |
1592 | 1592 | $filter_column_name = $filter_column_names[0]; |
1593 | 1593 | foreach ($thing as $TDBMObject) { |
@@ -1600,7 +1600,7 @@ discard block |
||
1600 | 1600 | { |
1601 | 1601 | $filter_bag_and = array(); |
1602 | 1602 | foreach ($thing as $TDBMObject) { |
1603 | - $filter_bag_temp_and=array(); |
|
1603 | + $filter_bag_temp_and = array(); |
|
1604 | 1604 | foreach ($filter_column_names as $pk) { |
1605 | 1605 | $filter_bag_temp_and[] = new EqualFilter($TDBMObject->_getDbTableName(), $pk, $TDBMObject->$pk); |
1606 | 1606 | } |
@@ -1610,7 +1610,7 @@ discard block |
||
1610 | 1610 | } |
1611 | 1611 | |
1612 | 1612 | |
1613 | - } elseif (!is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing!==null) { |
|
1613 | + } elseif (!is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing !== null) { |
|
1614 | 1614 | 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."); |
1615 | 1615 | } |
1616 | 1616 | } |
@@ -1638,9 +1638,9 @@ discard block |
||
1638 | 1638 | // 4-2, let's take all the objects out of the orderby bag, and let's make objects from them |
1639 | 1639 | $orderby_bag2 = array(); |
1640 | 1640 | foreach ($orderby_bag as $thing) { |
1641 | - if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
1641 | + if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
1642 | 1642 | $orderby_bag2[] = $thing; |
1643 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
1643 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
1644 | 1644 | $orderby_bag2[] = $thing; |
1645 | 1645 | } elseif (is_string($thing)) { |
1646 | 1646 | $orderby_bag2[] = new OrderBySQLString($thing); |
@@ -1663,10 +1663,10 @@ discard block |
||
1663 | 1663 | $possible_tables = $this->dbConnection->checkTableExist($table); |
1664 | 1664 | if ($possible_tables !== true) |
1665 | 1665 | { |
1666 | - if (count($possible_tables)==1) |
|
1666 | + if (count($possible_tables) == 1) |
|
1667 | 1667 | $str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'"; |
1668 | 1668 | else |
1669 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'"; |
|
1669 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $possible_tables)."'"; |
|
1670 | 1670 | throw new TDBMException($str); |
1671 | 1671 | } |
1672 | 1672 | } |
@@ -1689,16 +1689,16 @@ discard block |
||
1689 | 1689 | $current_node = $tree; |
1690 | 1690 | $found = true; |
1691 | 1691 | foreach ($path as $link) { |
1692 | - if ($found==true) |
|
1692 | + if ($found == true) |
|
1693 | 1693 | { |
1694 | 1694 | if (is_array($current_node->getChildren())) |
1695 | 1695 | { |
1696 | 1696 | foreach ($current_node->getChildren() as $child) |
1697 | 1697 | { |
1698 | - if ($link['table1']==$child->table_name && |
|
1699 | - $link['col1']==$child->keyNode && |
|
1700 | - $link['col2']==$child->keyParent && |
|
1701 | - $link['type']==$child->link_type) { |
|
1698 | + if ($link['table1'] == $child->table_name && |
|
1699 | + $link['col1'] == $child->keyNode && |
|
1700 | + $link['col2'] == $child->keyParent && |
|
1701 | + $link['type'] == $child->link_type) { |
|
1702 | 1702 | $current_node = $child; |
1703 | 1703 | } |
1704 | 1704 | else |
@@ -1713,7 +1713,7 @@ discard block |
||
1713 | 1713 | |
1714 | 1714 | } |
1715 | 1715 | |
1716 | - if ($found==false) |
|
1716 | + if ($found == false) |
|
1717 | 1717 | { |
1718 | 1718 | $current_node = new DisplayNode($link['table1'], $current_node, $link['type'], $link['col2'], $link['col1']); |
1719 | 1719 | } |
@@ -1738,7 +1738,7 @@ discard block |
||
1738 | 1738 | * |
1739 | 1739 | * @return string |
1740 | 1740 | */ |
1741 | - public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) { |
|
1741 | + public function drawTree($tree, $x, $y, &$ret_width = 0, &$ret_height = 0) { |
|
1742 | 1742 | |
1743 | 1743 | // Let's get the background div: |
1744 | 1744 | $treeDepth = $tree->computeDepth(1)-1; |
@@ -1749,7 +1749,7 @@ discard block |
||
1749 | 1749 | |
1750 | 1750 | $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>"; |
1751 | 1751 | |
1752 | - $str .= $tree->draw(0,0, $x, $y); |
|
1752 | + $str .= $tree->draw(0, 0, $x, $y); |
|
1753 | 1753 | |
1754 | 1754 | return $str; |
1755 | 1755 | } |
@@ -1784,10 +1784,10 @@ discard block |
||
1784 | 1784 | if ($tables === true) |
1785 | 1785 | throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table."); |
1786 | 1786 | elseif ($tables !== null) { |
1787 | - if (count($tables)==1) |
|
1787 | + if (count($tables) == 1) |
|
1788 | 1788 | $str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'"; |
1789 | 1789 | else |
1790 | - $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'"; |
|
1790 | + $str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $tables)."'"; |
|
1791 | 1791 | throw new TDBMException($str); |
1792 | 1792 | } |
1793 | 1793 | } |
@@ -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 | } |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | $defaultSort = $data['column_name']; |
427 | 427 | if (count($matches == 3)){ |
428 | 428 | $defaultSortDirection = $matches[2]; |
429 | - }else{ |
|
429 | + } else{ |
|
430 | 430 | $defaultSortDirection = 'ASC'; |
431 | 431 | } |
432 | 432 | } |
@@ -836,8 +836,9 @@ discard block |
||
836 | 836 | public static function toCamelCase($str) { |
837 | 837 | $str = strtoupper(substr($str,0,1)).substr($str,1); |
838 | 838 | while (true) { |
839 | - if (strpos($str, "_") === false && strpos($str, " ") === false) |
|
840 | - break; |
|
839 | + if (strpos($str, "_") === false && strpos($str, " ") === false) { |
|
840 | + break; |
|
841 | + } |
|
841 | 842 | |
842 | 843 | $pos = strpos($str, "_"); |
843 | 844 | if ($pos === false) { |
@@ -91,7 +91,9 @@ discard block |
||
91 | 91 | /** |
92 | 92 | * Generates in one method call the daos and the beans for one table. |
93 | 93 | * |
94 | - * @param $tableName |
|
94 | + * @param string $tableName |
|
95 | + * @param string $daonamespace |
|
96 | + * @param string $beannamespace |
|
95 | 97 | */ |
96 | 98 | public function generateDaoAndBean($tableName, $daonamespace, $beannamespace, ClassNameMapper $classNameMapper) { |
97 | 99 | $daoName = $this->getDaoNameFromTableName($tableName); |
@@ -406,9 +408,10 @@ discard block |
||
406 | 408 | /** |
407 | 409 | * Writes the PHP bean DAO with simple functions to create/get/save objects. |
408 | 410 | * |
409 | - * @param string $fileName The file that will be written (without the directory) |
|
410 | 411 | * @param string $className The name of the class |
411 | 412 | * @param string $tableName The name of the table |
413 | + * @param string $baseClassName |
|
414 | + * @param string $beanClassName |
|
412 | 415 | */ |
413 | 416 | public function generateDao($className, $baseClassName, $beanClassName, $tableName, ClassNameMapper $classNameMapper) { |
414 | 417 | $info = $this->dbConnection->getTableInfo($tableName); |
@@ -696,7 +699,9 @@ discard block |
||
696 | 699 | /** |
697 | 700 | * Generates the factory bean. |
698 | 701 | * |
699 | - * @param $tableList |
|
702 | + * @param string[] $tableList |
|
703 | + * @param string $daoFactoryClassName |
|
704 | + * @param string $daoNamespace |
|
700 | 705 | */ |
701 | 706 | private function generateFactory($tableList, $daoFactoryClassName, $daoNamespace, ClassNameMapper $classNameMapper) { |
702 | 707 | // For each table, let's write a property. |
@@ -768,7 +773,6 @@ discard block |
||
768 | 773 | * Transforms the property name in a setter name. |
769 | 774 | * For instance, phone => getPhone or name => getName |
770 | 775 | * |
771 | - * @param string $methodName |
|
772 | 776 | * @return string |
773 | 777 | */ |
774 | 778 | public static function getSetterNameForPropertyName($propertyName) { |
@@ -848,7 +852,7 @@ discard block |
||
848 | 852 | * Tries to put string to the singular form (if it is plural). |
849 | 853 | * Obviously, this can't be perfect, be we do the best we can. |
850 | 854 | * |
851 | - * @param $str string |
|
855 | + * @param string $str string |
|
852 | 856 | * @return string |
853 | 857 | */ |
854 | 858 | public static function toSingular($str) { |
@@ -869,7 +873,7 @@ discard block |
||
869 | 873 | * Put the first letter of the string in lower case. |
870 | 874 | * Very useful to transform a class name into a variable name. |
871 | 875 | * |
872 | - * @param $str string |
|
876 | + * @param string $str string |
|
873 | 877 | * @return string |
874 | 878 | */ |
875 | 879 | public static function toVariableName($str) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function generateAllDaosAndBeans($daoFactoryClassName, $daonamespace, $beannamespace, $support, $storeInUtc) { |
67 | 67 | // TODO: migrate $this->daoNamespace to $daonamespace that is passed in parameter! |
68 | 68 | |
69 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
69 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
70 | 70 | |
71 | 71 | $this->daoNamespace = $daonamespace; |
72 | 72 | $this->beanNamespace = $beannamespace; |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | $beanName = $this->getBeanNameFromTableName($tableName); |
99 | 99 | $baseBeanName = $this->getBaseBeanNameFromTableName($tableName); |
100 | 100 | |
101 | - $connection = $this->dbConnection; |
|
102 | - if ($connection instanceof CachedConnection){ |
|
103 | - $connection->cacheService->purgeAll(); |
|
104 | - } |
|
101 | + $connection = $this->dbConnection; |
|
102 | + if ($connection instanceof CachedConnection){ |
|
103 | + $connection->cacheService->purgeAll(); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | $this->generateBean($beanName, $baseBeanName, $tableName, $beannamespace, $classNameMapper); |
107 | 107 | $this->generateDao($daoName, $daoName."Base", $beanName, $tableName, $classNameMapper); |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | return TDBMDaoGenerator::toSingular(TDBMDaoGenerator::toCamelCase($tableName))."BaseBean"; |
138 | 138 | } |
139 | 139 | |
140 | - /** |
|
141 | - * Writes the PHP bean file with all getters and setters from the table passed in parameter. |
|
142 | - * |
|
143 | - * @param string $className The name of the class |
|
144 | - * @param string $baseClassName The name of the base class which will be extended (name only, no directory) |
|
145 | - * @param string $tableName The name of the table |
|
146 | - * @param string $beannamespace The namespace of the bean |
|
147 | - * @param ClassNameMapper $classNameMapper |
|
148 | - * @throws TDBMException |
|
149 | - */ |
|
140 | + /** |
|
141 | + * Writes the PHP bean file with all getters and setters from the table passed in parameter. |
|
142 | + * |
|
143 | + * @param string $className The name of the class |
|
144 | + * @param string $baseClassName The name of the base class which will be extended (name only, no directory) |
|
145 | + * @param string $tableName The name of the table |
|
146 | + * @param string $beannamespace The namespace of the bean |
|
147 | + * @param ClassNameMapper $classNameMapper |
|
148 | + * @throws TDBMException |
|
149 | + */ |
|
150 | 150 | public function generateBean($className, $baseClassName, $tableName, $beannamespace, ClassNameMapper $classNameMapper) { |
151 | 151 | $table = $this->dbConnection->getTableFromDbModel($tableName); |
152 | 152 | |
@@ -361,25 +361,25 @@ discard block |
||
361 | 361 | $str .= "} |
362 | 362 | ?>"; |
363 | 363 | |
364 | - $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$baseClassName); |
|
365 | - if (!$possibleBaseFileNames) { |
|
366 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$baseClassName.'" is not autoloadable.'); |
|
367 | - } |
|
368 | - $possibleBaseFileName = __DIR__.'/../../../../../../../../'.$possibleBaseFileNames[0]; |
|
364 | + $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$baseClassName); |
|
365 | + if (!$possibleBaseFileNames) { |
|
366 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$baseClassName.'" is not autoloadable.'); |
|
367 | + } |
|
368 | + $possibleBaseFileName = __DIR__.'/../../../../../../../../'.$possibleBaseFileNames[0]; |
|
369 | 369 | |
370 | - $this->ensureDirectoryExist($possibleBaseFileName); |
|
370 | + $this->ensureDirectoryExist($possibleBaseFileName); |
|
371 | 371 | file_put_contents($possibleBaseFileName, $str); |
372 | 372 | @chmod($possibleBaseFileName, 0664); |
373 | 373 | |
374 | 374 | |
375 | 375 | |
376 | - $possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$className); |
|
377 | - if (!$possibleFileNames) { |
|
378 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$className.'" is not autoloadable.'); |
|
379 | - } |
|
380 | - $possibleFileName = __DIR__.'/../../../../../../../../'.$possibleFileNames[0]; |
|
376 | + $possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$className); |
|
377 | + if (!$possibleFileNames) { |
|
378 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$className.'" is not autoloadable.'); |
|
379 | + } |
|
380 | + $possibleFileName = __DIR__.'/../../../../../../../../'.$possibleFileNames[0]; |
|
381 | 381 | |
382 | - if (!file_exists($possibleFileName)) { |
|
382 | + if (!file_exists($possibleFileName)) { |
|
383 | 383 | $str = "<?php |
384 | 384 | /* |
385 | 385 | * This file has been automatically generated by TDBM. |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | { |
398 | 398 | |
399 | 399 | }"; |
400 | - $this->ensureDirectoryExist($possibleFileName); |
|
400 | + $this->ensureDirectoryExist($possibleFileName); |
|
401 | 401 | file_put_contents($possibleFileName ,$str); |
402 | 402 | @chmod($possibleFileName, 0664); |
403 | 403 | } |
@@ -653,21 +653,21 @@ discard block |
||
653 | 653 | } |
654 | 654 | ?>"; |
655 | 655 | |
656 | - $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$baseClassName); |
|
657 | - if (!$possibleBaseFileNames) { |
|
658 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$baseClassName.'" is not autoloadable.'); |
|
659 | - } |
|
660 | - $possibleBaseFileName = __DIR__.'/../../../../../../../../'.$possibleBaseFileNames[0]; |
|
656 | + $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$baseClassName); |
|
657 | + if (!$possibleBaseFileNames) { |
|
658 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$baseClassName.'" is not autoloadable.'); |
|
659 | + } |
|
660 | + $possibleBaseFileName = __DIR__.'/../../../../../../../../'.$possibleBaseFileNames[0]; |
|
661 | 661 | |
662 | - $this->ensureDirectoryExist($possibleBaseFileName); |
|
662 | + $this->ensureDirectoryExist($possibleBaseFileName); |
|
663 | 663 | file_put_contents($possibleBaseFileName ,$str); |
664 | 664 | @chmod($possibleBaseFileName, 0664); |
665 | 665 | |
666 | - $possibleFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$className); |
|
667 | - if (!$possibleFileNames) { |
|
668 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$className.'" is not autoloadable.'); |
|
669 | - } |
|
670 | - $possibleFileName = __DIR__.'/../../../../../../../../'.$possibleFileNames[0]; |
|
666 | + $possibleFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$className); |
|
667 | + if (!$possibleFileNames) { |
|
668 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$className.'" is not autoloadable.'); |
|
669 | + } |
|
670 | + $possibleFileName = __DIR__.'/../../../../../../../../'.$possibleFileNames[0]; |
|
671 | 671 | |
672 | 672 | // Now, let's generate the "editable" class |
673 | 673 | if (!file_exists($possibleFileName)) { |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | { |
688 | 688 | |
689 | 689 | }"; |
690 | - $this->ensureDirectoryExist($possibleFileName); |
|
690 | + $this->ensureDirectoryExist($possibleFileName); |
|
691 | 691 | file_put_contents($possibleFileName ,$str); |
692 | 692 | @chmod($possibleFileName, 0664); |
693 | 693 | } |
@@ -754,13 +754,13 @@ discard block |
||
754 | 754 | } |
755 | 755 | ?>'; |
756 | 756 | |
757 | - $possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace."\\".$daoFactoryClassName); |
|
758 | - if (!$possibleFileNames) { |
|
759 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace."\\".$daoFactoryClassName.'" is not autoloadable.'); |
|
760 | - } |
|
761 | - $possibleFileName = __DIR__.'/../../../../../../../../'.$possibleFileNames[0]; |
|
757 | + $possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace."\\".$daoFactoryClassName); |
|
758 | + if (!$possibleFileNames) { |
|
759 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace."\\".$daoFactoryClassName.'" is not autoloadable.'); |
|
760 | + } |
|
761 | + $possibleFileName = __DIR__.'/../../../../../../../../'.$possibleFileNames[0]; |
|
762 | 762 | |
763 | - $this->ensureDirectoryExist($possibleFileName); |
|
763 | + $this->ensureDirectoryExist($possibleFileName); |
|
764 | 764 | file_put_contents($possibleFileName ,$str); |
765 | 765 | } |
766 | 766 | |
@@ -876,20 +876,20 @@ discard block |
||
876 | 876 | return strtolower(substr($str, 0, 1)).substr($str, 1); |
877 | 877 | } |
878 | 878 | |
879 | - /** |
|
880 | - * Ensures the file passed in parameter can be written in its directory. |
|
881 | - * @param string $fileName |
|
882 | - */ |
|
883 | - private function ensureDirectoryExist($fileName) { |
|
884 | - $dirName = dirname($fileName); |
|
885 | - if (!file_exists($dirName)) { |
|
886 | - $old = umask(0); |
|
887 | - $result = mkdir($dirName, 0775, true); |
|
888 | - umask($old); |
|
889 | - if ($result == false) { |
|
890 | - echo "Unable to create directory: ".$dirName."."; |
|
891 | - exit; |
|
892 | - } |
|
893 | - } |
|
894 | - } |
|
879 | + /** |
|
880 | + * Ensures the file passed in parameter can be written in its directory. |
|
881 | + * @param string $fileName |
|
882 | + */ |
|
883 | + private function ensureDirectoryExist($fileName) { |
|
884 | + $dirName = dirname($fileName); |
|
885 | + if (!file_exists($dirName)) { |
|
886 | + $old = umask(0); |
|
887 | + $result = mkdir($dirName, 0775, true); |
|
888 | + umask($old); |
|
889 | + if ($result == false) { |
|
890 | + echo "Unable to create directory: ".$dirName."."; |
|
891 | + exit; |
|
892 | + } |
|
893 | + } |
|
894 | + } |
|
895 | 895 | } |
896 | 896 | \ No newline at end of file |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $baseBeanName = $this->getBaseBeanNameFromTableName($tableName); |
100 | 100 | |
101 | 101 | $connection = $this->dbConnection; |
102 | - if ($connection instanceof CachedConnection){ |
|
102 | + if ($connection instanceof CachedConnection) { |
|
103 | 103 | $connection->cacheService->purgeAll(); |
104 | 104 | } |
105 | 105 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | if($date === null) |
198 | 198 | return null; |
199 | 199 | else |
200 | - return strtotime($date'.($this->storeInUtc?'.\' UTC\'':'').'); |
|
200 | + return strtotime($date'.($this->storeInUtc ? '.\' UTC\'' : '').'); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | if ($this->'.$array["col1"].' == null) { |
288 | 288 | return null; |
289 | 289 | } |
290 | - return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\","\\\\",$this->beanNamespace).'\\\\'.$referencedBeanName.'", true); |
|
290 | + return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\", "\\\\", $this->beanNamespace).'\\\\'.$referencedBeanName.'", true); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | |
307 | 307 | // Now, let's implement the shortcuts to the getter of objects. |
308 | 308 | // Shortcuts are used to save typing. They are available only if a referenced table is referenced only once by our tables. |
309 | - foreach($referencedTablesList as $referrencedTable=>$number) { |
|
309 | + foreach ($referencedTablesList as $referrencedTable=>$number) { |
|
310 | 310 | if ($number == 1) { |
311 | 311 | foreach ($constraints as $array) { |
312 | - if ($array['table2'] ==$referrencedTable) { |
|
312 | + if ($array['table2'] == $referrencedTable) { |
|
313 | 313 | $columnName = $array['col1']; |
314 | 314 | $targetColumnName = $array['col2']; |
315 | 315 | break; |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | if ($this->'.$array["col1"].' == null) { |
341 | 341 | return null; |
342 | 342 | } |
343 | - return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\","\\\\",$this->beanNamespace).'\\\\'.$referencedBeanName.'"); |
|
343 | + return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\", "\\\\", $this->beanNamespace).'\\\\'.$referencedBeanName.'"); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | |
399 | 399 | }"; |
400 | 400 | $this->ensureDirectoryExist($possibleFileName); |
401 | - file_put_contents($possibleFileName ,$str); |
|
401 | + file_put_contents($possibleFileName, $str); |
|
402 | 402 | @chmod($possibleFileName, 0664); |
403 | 403 | } |
404 | 404 | } |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | foreach ($info as $index => $data) { |
417 | 417 | $comments = $data['column_comment']; |
418 | 418 | $matches = array(); |
419 | - if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0){ |
|
419 | + if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) { |
|
420 | 420 | $defaultSort = $data['column_name']; |
421 | - if (count($matches == 3)){ |
|
421 | + if (count($matches == 3)) { |
|
422 | 422 | $defaultSortDirection = $matches[2]; |
423 | - }else{ |
|
423 | + } else { |
|
424 | 424 | $defaultSortDirection = 'ASC'; |
425 | 425 | } |
426 | 426 | } |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | $possibleBaseFileName = __DIR__.'/../../../../../../../../'.$possibleBaseFileNames[0]; |
661 | 661 | |
662 | 662 | $this->ensureDirectoryExist($possibleBaseFileName); |
663 | - file_put_contents($possibleBaseFileName ,$str); |
|
663 | + file_put_contents($possibleBaseFileName, $str); |
|
664 | 664 | @chmod($possibleBaseFileName, 0664); |
665 | 665 | |
666 | 666 | $possibleFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$className); |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | |
689 | 689 | }"; |
690 | 690 | $this->ensureDirectoryExist($possibleFileName); |
691 | - file_put_contents($possibleFileName ,$str); |
|
691 | + file_put_contents($possibleFileName, $str); |
|
692 | 692 | @chmod($possibleFileName, 0664); |
693 | 693 | } |
694 | 694 | } |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | $possibleFileName = __DIR__.'/../../../../../../../../'.$possibleFileNames[0]; |
762 | 762 | |
763 | 763 | $this->ensureDirectoryExist($possibleFileName); |
764 | - file_put_contents($possibleFileName ,$str); |
|
764 | + file_put_contents($possibleFileName, $str); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /** |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | * @return string |
829 | 829 | */ |
830 | 830 | public static function toCamelCase($str) { |
831 | - $str = strtoupper(substr($str,0,1)).substr($str,1); |
|
831 | + $str = strtoupper(substr($str, 0, 1)).substr($str, 1); |
|
832 | 832 | while (true) { |
833 | 833 | if (strpos($str, "_") === false && strpos($str, " ") === false) |
834 | 834 | break; |
@@ -837,9 +837,9 @@ discard block |
||
837 | 837 | if ($pos === false) { |
838 | 838 | $pos = strpos($str, " "); |
839 | 839 | } |
840 | - $before = substr($str,0,$pos); |
|
841 | - $after = substr($str,$pos+1); |
|
842 | - $str = $before.strtoupper(substr($after,0,1)).substr($after,1); |
|
840 | + $before = substr($str, 0, $pos); |
|
841 | + $after = substr($str, $pos+1); |
|
842 | + $str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1); |
|
843 | 843 | } |
844 | 844 | return $str; |
845 | 845 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | <div class="control-group"> |
53 | 53 | <label class="control-label">Keep support for previous DAOs:</label> |
54 | 54 | <div class="controls"> |
55 | - <input type="checkbox" name="keepSupport" <?php echo $this->keepSupport?'checked="checked"':"" ?>></input> |
|
55 | + <input type="checkbox" name="keepSupport" <?php echo $this->keepSupport ? 'checked="checked"' : "" ?>></input> |
|
56 | 56 | <span class="help-block">DAOs generated before TDBM 2.3 had a different method signature. This will ensure this signature |
57 | 57 | is respected. Use this only if you are migrating legacy code.</span> |
58 | 58 | </div> |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | <div class="control-group"> |
62 | 62 | <label class="control-label">Store dates / timestamps in UTC:</label> |
63 | 63 | <div class="controls"> |
64 | - <input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc?'checked="checked"':"" ?>></input> |
|
64 | + <input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc ? 'checked="checked"' : "" ?>></input> |
|
65 | 65 | <span class="help-block">Select this option if you want timestamps to be stored in UTC. |
66 | 66 | If your application supports several time zones, you should select this option to store all dates in |
67 | 67 | the same time zone.</span> |
@@ -85,7 +85,7 @@ |
||
85 | 85 | * @param string $columnName |
86 | 86 | * @param string $value |
87 | 87 | */ |
88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
89 | 89 | $this->tableName = $tableName; |
90 | 90 | $this->columnName = $columnName; |
91 | 91 | $this->value = $value; |
@@ -85,7 +85,7 @@ |
||
85 | 85 | * @param string $columnName |
86 | 86 | * @param string $value |
87 | 87 | */ |
88 | - public function __construct($tableName=null, $columnName=null, $value=null) { |
|
88 | + public function __construct($tableName = null, $columnName = null, $value = null) { |
|
89 | 89 | $this->tableName = $tableName; |
90 | 90 | $this->columnName = $columnName; |
91 | 91 | $this->value = $value; |