@@ -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 |