Passed
Pull Request — 3.4 (#159)
by David
29:15
created
src/Mouf/Database/TDBM/TDBMObject.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -170,26 +170,26 @@  discard block
 block discarded – undo
170 170
 		$this->TDBMObject_state = $state;	
171 171
 	}
172 172
 
173
-    /**
174
-     * Internal TDBM method, you should not use this.
175
-     * Loads the db_row property of the object from the $row array.
176
-     * Any row having a key starting with 'tdbm_reserved_col_' is ignored.
177
-     *
178
-     * @param array $row
179
-     * @param array|null $colsArray A big optimization to avoid calling strpos to many times. This array should
180
-     *                              contain as keys the list of interesting columns. If null, this list will be initialized.
181
-     */
173
+	/**
174
+	 * Internal TDBM method, you should not use this.
175
+	 * Loads the db_row property of the object from the $row array.
176
+	 * Any row having a key starting with 'tdbm_reserved_col_' is ignored.
177
+	 *
178
+	 * @param array $row
179
+	 * @param array|null $colsArray A big optimization to avoid calling strpos to many times. This array should
180
+	 *                              contain as keys the list of interesting columns. If null, this list will be initialized.
181
+	 */
182 182
 	public function loadFromRow($row, &$colsArray) {
183
-        if ($colsArray === null) {
184
-            foreach ($row as $key=>$value) {
185
-                if (strpos($key, 'tdbm_reserved_col_')!==0) {
186
-                    $colsArray[$key] = true;
187
-                }
188
-            }
189
-        }
190
-
191
-        $this->db_row = array_intersect_key($row, $colsArray);
192
-        $this->TDBMObject_state = "loaded";
183
+		if ($colsArray === null) {
184
+			foreach ($row as $key=>$value) {
185
+				if (strpos($key, 'tdbm_reserved_col_')!==0) {
186
+					$colsArray[$key] = true;
187
+				}
188
+			}
189
+		}
190
+
191
+		$this->db_row = array_intersect_key($row, $colsArray);
192
+		$this->TDBMObject_state = "loaded";
193 193
 	}
194 194
 
195 195
 	/**
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 
326 326
 	/**
327 327
 	 * Saves the current object by INSERTing or UPDAT(E)ing it in the database.
328
-     *
329
-     * This method must be called only from the DAOs.
330
-     * @internal
328
+	 *
329
+	 * This method must be called only from the DAOs.
330
+	 * @internal
331 331
 	 */
332 332
 	public function save() {
333 333
 		if (!is_array($this->db_row)) {
@@ -510,10 +510,10 @@  discard block
 block discarded – undo
510 510
 	 *
511 511
 	 * @param string $func_name
512 512
 	 * @param $values
513
-     * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query.
514
-     * @throws TDBMException
513
+	 * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query.
514
+	 * @throws TDBMException
515 515
 	 */
516
-    public function __call($func_name, $values) {
516
+	public function __call($func_name, $values) {
517 517
 
518 518
 		if (strpos($func_name,"get_") === 0) {
519 519
 			$table = substr($func_name,4);
@@ -548,48 +548,48 @@  discard block
 block discarded – undo
548 548
 	}
549 549
 	
550 550
 		/**
551
-	 * Implements array behaviour for our object.
552
-	 * 
553
-	 * @param string $offset
554
-	 * @param string $value
555
-	 */
551
+		 * Implements array behaviour for our object.
552
+		 * 
553
+		 * @param string $offset
554
+		 * @param string $value
555
+		 */
556 556
 	public function offsetSet($offset, $value) {
557 557
 		$this->__set($offset, $value);
558
-    }
558
+	}
559 559
 	/**
560 560
 	 * Implements array behaviour for our object.
561 561
 	 * 
562 562
 	 * @param string $offset
563
-     * @return bool
563
+	 * @return bool
564 564
 	 */
565
-    public function offsetExists($offset) {
566
-    	$this->_dbLoadIfNotLoaded();
567
-        return isset($this->db_row[$offset]);
568
-    }
565
+	public function offsetExists($offset) {
566
+		$this->_dbLoadIfNotLoaded();
567
+		return isset($this->db_row[$offset]);
568
+	}
569 569
 	/**
570 570
 	 * Implements array behaviour for our object.
571 571
 	 * 
572 572
 	 * @param string $offset
573 573
 	 */
574
-    public function offsetUnset($offset) {
574
+	public function offsetUnset($offset) {
575 575
 		$this->__set($offset, null);
576
-    }
576
+	}
577 577
 	/**
578 578
 	 * Implements array behaviour for our object.
579 579
 	 * 
580 580
 	 * @param string $offset
581
-     * @return mixed|null
581
+	 * @return mixed|null
582 582
 	 */
583
-    public function offsetGet($offset) {
584
-        return $this->__get($offset);
585
-    }
583
+	public function offsetGet($offset) {
584
+		return $this->__get($offset);
585
+	}
586 586
 	
587 587
 	private $_validIterator = false;
588 588
 	/**
589 589
 	 * Implements iterator behaviour for our object (so we can each column).
590 590
 	 */
591 591
 	public function rewind() {
592
-    	$this->_dbLoadIfNotLoaded();
592
+		$this->_dbLoadIfNotLoaded();
593 593
 		if (count($this->db_row)>0) {
594 594
 			$this->_validIterator = true;
595 595
 		} else {
@@ -677,21 +677,21 @@  discard block
 block discarded – undo
677 677
 		return $sql_where;
678 678
 	}
679 679
 
680
-    /**
681
-     * Override the native php clone function for TDBMObjects
682
-     */
683
-    public function __clone(){
684
-        $this->_dbLoadIfNotLoaded();
685
-        //First lets set the status to new (to enter the save function)
686
-        $this->TDBMObject_state = "new";
687
-
688
-        // Add the current TDBMObject to the save object list
689
-        $this->tdbmService->_addToToSaveObjectList($this);
690
-
691
-        //Now unset the PK from the row
692
-        $pk_array = $this->getPrimaryKey();
693
-        foreach ($pk_array as $pk) {
694
-            $this->db_row[$pk] = null;
695
-        }
696
-    }
680
+	/**
681
+	 * Override the native php clone function for TDBMObjects
682
+	 */
683
+	public function __clone(){
684
+		$this->_dbLoadIfNotLoaded();
685
+		//First lets set the status to new (to enter the save function)
686
+		$this->TDBMObject_state = "new";
687
+
688
+		// Add the current TDBMObject to the save object list
689
+		$this->tdbmService->_addToToSaveObjectList($this);
690
+
691
+		//Now unset the PK from the row
692
+		$pk_array = $this->getPrimaryKey();
693
+		foreach ($pk_array as $pk) {
694
+			$this->db_row[$pk] = null;
695
+		}
696
+	}
697 697
 }
698 698
\ No newline at end of file
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/TDBMService.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -545,45 +545,45 @@  discard block
 block discarded – undo
545 545
 		}
546 546
 	}
547 547
 
548
-    /**
549
-     * This function removes the given object from the database. It will also remove all objects relied to the one given
550
-     * by parameter before all.
551
-     *
552
-     * Notice: if the object has a multiple primary key, the function will not work.
553
-     *
554
-     * @param TDBMObject $objToDelete
555
-     */
556
-    public function deleteCascade(TDBMObject $objToDelete) {
557
-        $this->deleteAllConstraintWithThisObject($objToDelete);
558
-        $this->deleteObject($objToDelete);
559
-    }
560
-
561
-    /**
562
-     * This function is used only in TDBMService (private function)
563
-     * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter
564
-     *
565
-     * @param TDBMObject $obj
566
-     * @return TDBMObjectArray
567
-     */
568
-    private function deleteAllConstraintWithThisObject(TDBMObject $obj) {
569
-        $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName());
570
-        $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom);
571
-        foreach ($constraints as $constraint) {
572
-            $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]);
573
-            $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]);
574
-            $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]);
575
-            $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]);
576
-            $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id);
577
-            $sql = "SELECT DISTINCT ".$tableTo.".*"
578
-                    ." FROM ".$tableFrom
579
-                    ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo
580
-                    ." WHERE ".$tableFrom.".".$idVarName."=".$idValue;
581
-            $result = $this->getObjectsFromSQL($constraint["table1"], $sql);
582
-            foreach ($result as $tdbmObj) {
583
-                $this->deleteCascade($tdbmObj);
584
-            }
585
-        }
586
-    }
548
+	/**
549
+	 * This function removes the given object from the database. It will also remove all objects relied to the one given
550
+	 * by parameter before all.
551
+	 *
552
+	 * Notice: if the object has a multiple primary key, the function will not work.
553
+	 *
554
+	 * @param TDBMObject $objToDelete
555
+	 */
556
+	public function deleteCascade(TDBMObject $objToDelete) {
557
+		$this->deleteAllConstraintWithThisObject($objToDelete);
558
+		$this->deleteObject($objToDelete);
559
+	}
560
+
561
+	/**
562
+	 * This function is used only in TDBMService (private function)
563
+	 * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter
564
+	 *
565
+	 * @param TDBMObject $obj
566
+	 * @return TDBMObjectArray
567
+	 */
568
+	private function deleteAllConstraintWithThisObject(TDBMObject $obj) {
569
+		$tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName());
570
+		$constraints = $this->dbConnection->getConstraintsFromTable($tableFrom);
571
+		foreach ($constraints as $constraint) {
572
+			$tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]);
573
+			$colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]);
574
+			$colTo = $this->dbConnection->escapeDBItem($constraint["col1"]);
575
+			$idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]);
576
+			$idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id);
577
+			$sql = "SELECT DISTINCT ".$tableTo.".*"
578
+					." FROM ".$tableFrom
579
+					." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo
580
+					." WHERE ".$tableFrom.".".$idVarName."=".$idValue;
581
+			$result = $this->getObjectsFromSQL($constraint["table1"], $sql);
582
+			foreach ($result as $tdbmObj) {
583
+				$this->deleteCascade($tdbmObj);
584
+			}
585
+		}
586
+	}
587 587
 
588 588
 	/**
589 589
 	 * The getObjectsFromSQL is used to retrieve objects from the database using a full SQL query.
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 			}
645 645
 			$keysStandardCased = array();
646 646
 			$firstLine = true;
647
-            $colsArray = null;
647
+			$colsArray = null;
648 648
 			while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC))
649 649
 			{
650 650
 				$row = array();
@@ -676,17 +676,17 @@  discard block
 block discarded – undo
676 676
 					$id = serialize($ids);
677 677
 				}
678 678
 
679
-                $obj = $this->objectStorage->get($table_name,$id);
679
+				$obj = $this->objectStorage->get($table_name,$id);
680 680
 				if ($obj === null)
681 681
 				{
682 682
 					if (!is_a($className, "Mouf\\Database\\TDBM\\TDBMObject", true)) {
683 683
 						throw new TDBMException("Error while calling TDBM: The class ".$className." should extend TDBMObject.");
684 684
 					}
685 685
 					$obj = new $className($this, $table_name, $id);
686
-                    $obj->loadFromRow($row, $colsArray);
687
-                    $this->objectStorage->set($table_name, $id, $obj);
686
+					$obj->loadFromRow($row, $colsArray);
687
+					$this->objectStorage->set($table_name, $id, $obj);
688 688
 				} elseif ($obj->_getStatus() == "not loaded") {
689
-                    $obj->loadFromRow($row, $colsArray);
689
+					$obj->loadFromRow($row, $colsArray);
690 690
 					// Check that the object fetched from cache is from the requested class.
691 691
 					if (!is_a($obj, $className)) {
692 692
 						throw new TDBMException("Error while calling TDBM: An object fetched from database is already present in TDBM cache and they do not share the same class. You requested the object to be of the class ".$className." but the object available locally is of the class ".get_class($obj).".");
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) {
720 720
 		$keysStandardCased = array();
721 721
 		$firstLine = true;
722
-        $colsArray = null;
722
+		$colsArray = null;
723 723
 		while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC))
724 724
 		{
725 725
 			$row = array();
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 				}
751 751
 				$id = serialize($ids);
752 752
 			}
753
-            $obj = $this->objectStorage->get($table_name, $id);
753
+			$obj = $this->objectStorage->get($table_name, $id);
754 754
 			if ($obj === null)
755 755
 			{
756 756
 				if ($className == null) {
@@ -763,10 +763,10 @@  discard block
 block discarded – undo
763 763
 				} else {
764 764
 					throw new TDBMException("Error while casting TDBMObject to class, the parameter passed is not a string. Value passed: ".$className);
765 765
 				}
766
-                $obj->loadFromRow($row, $colsArray);
767
-                $this->objectStorage->set($table_name, $id, $obj);
766
+				$obj->loadFromRow($row, $colsArray);
767
+				$this->objectStorage->set($table_name, $id, $obj);
768 768
 			} elseif ($obj->_getStatus() == "not loaded") {
769
-                $obj->loadFromRow($row, $colsArray);
769
+				$obj->loadFromRow($row, $colsArray);
770 770
 				// Check that the object fetched from cache is from the requested class.
771 771
 				if ($className != null) {
772 772
 					if (!is_subclass_of(get_class($obj), $className) && get_class($obj) != $className) {
@@ -1466,33 +1466,33 @@  discard block
 block discarded – undo
1466 1466
 		}
1467 1467
 
1468 1468
 		//If no $hint_path is provided, check that a path exists
1469
-        if($hint_path === null){
1470
-            // Now, for each needed table to perform the order by, we must verify if the relationship between the order by and the object is indeed a 1* relationship
1471
-            foreach ($needed_table_array_for_orderby as $target_table_table) {
1472
-                // Get the path between the main table and the target group by table
1469
+		if($hint_path === null){
1470
+			// Now, for each needed table to perform the order by, we must verify if the relationship between the order by and the object is indeed a 1* relationship
1471
+			foreach ($needed_table_array_for_orderby as $target_table_table) {
1472
+				// Get the path between the main table and the target group by table
1473 1473
 
1474
-                // TODO! Pas bon!!!! Faut le quérir, hélas!
1475
-                // Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni?????
1474
+				// TODO! Pas bon!!!! Faut le quérir, hélas!
1475
+				// Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni?????
1476 1476
 
1477
-                $path = $this->getPathFromCache($table_name, $target_table_table);
1477
+				$path = $this->getPathFromCache($table_name, $target_table_table);
1478 1478
 
1479
-                /**********************************
1479
+				/**********************************
1480 1480
                  * Modifier par Marc de *1 vers 1*
1481 1481
                  * (sur les conseils de David !)
1482 1482
                  */
1483
-                $is_ok = true;
1484
-                foreach ($path as $step) {
1485
-                    if ($step["type"]=="1*") {
1486
-                        $is_ok = false;
1487
-                        break;
1488
-                    }
1489
-                }
1490
-
1491
-                if (!$is_ok) {
1492
-                    throw new TDBMException("Error in querying database from getObjectsByFilter. You tried to order your data according to a column of the '$target_table_table' table. However, the '$target_table_table' table has a many to 1 relationship with the '$table_name' table. This means that one '$table_name' object can contain many '$target_table_table' objects. Therefore, trying to order '$table_name' objects using '$target_table_table' objects is meaningless and cannot be performed.");
1493
-                }
1494
-            }
1495
-        }
1483
+				$is_ok = true;
1484
+				foreach ($path as $step) {
1485
+					if ($step["type"]=="1*") {
1486
+						$is_ok = false;
1487
+						break;
1488
+					}
1489
+				}
1490
+
1491
+				if (!$is_ok) {
1492
+					throw new TDBMException("Error in querying database from getObjectsByFilter. You tried to order your data according to a column of the '$target_table_table' table. However, the '$target_table_table' table has a many to 1 relationship with the '$table_name' table. This means that one '$table_name' object can contain many '$target_table_table' objects. Therefore, trying to order '$table_name' objects using '$target_table_table' objects is meaningless and cannot be performed.");
1493
+				}
1494
+			}
1495
+		}
1496 1496
 
1497 1497
 		// In a SELECT DISTINCT ... ORDER BY ... clause, the orderbyed columns must appear!
1498 1498
 		// Therefore, we must be able to parse the Orderby columns requested, give them dummy names and remove them afterward!
@@ -1667,9 +1667,9 @@  discard block
 block discarded – undo
1667 1667
 	 * Throws a TDBMException if one of those table does not exist.
1668 1668
 	 *
1669 1669
 	 * @param array $tables
1670
-     * @throws TDBMException
1670
+	 * @throws TDBMException
1671 1671
 	 */
1672
-    private function checkTablesExist($tables) {
1672
+	private function checkTablesExist($tables) {
1673 1673
 		foreach ($tables as $table) {
1674 1674
 			$possible_tables = $this->dbConnection->checkTableExist($table);
1675 1675
 			if ($possible_tables !== true)
@@ -1742,12 +1742,12 @@  discard block
 block discarded – undo
1742 1742
 	 * This function returns the HTML to draw a tree of DisplayNode.
1743 1743
 	 *
1744 1744
 	 * @param DisplayNode $tree
1745
-     * @param int $x
1746
-     * @param int $y
1747
-     * @param int $ret_width
1748
-     * @param int $ret_height
1749
-     *
1750
-     * @return string
1745
+	 * @param int $x
1746
+	 * @param int $y
1747
+	 * @param int $ret_width
1748
+	 * @param int $ret_height
1749
+	 *
1750
+	 * @return string
1751 1751
 	 */
1752 1752
 	public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) {
1753 1753
 
@@ -1861,8 +1861,8 @@  discard block
 block discarded – undo
1861 1861
 	}
1862 1862
 
1863 1863
 	/**
1864
- 	* @param array<string, string> $tableToBeanMap
1865
- 	*/
1864
+	 * @param array<string, string> $tableToBeanMap
1865
+	 */
1866 1866
 	public function setTableToBeanMap(array $tableToBeanMap) {
1867 1867
 		$this->tableToBeanMap = $tableToBeanMap;
1868 1868
 	}
Please login to merge, or discard this patch.