Преглед на файлове

[Tree - Closure Table] Fixed some more problems with indentation

Gustavo Adrian преди 14 години
родител
ревизия
9985c4525a
променени са 3 файла, в които са добавени 40 реда и са изтрити 43 реда
  1. 7 7
      lib/Gedmo/Tree/Entity/AbstractClosure.php
  2. 14 14
      lib/Gedmo/Tree/Entity/Repository/ClosureTreeRepository.php
  3. 19 22
      lib/Gedmo/Tree/Strategy/ORM/Closure.php

+ 7 - 7
lib/Gedmo/Tree/Entity/AbstractClosure.php

@@ -8,13 +8,13 @@ namespace Gedmo\Tree\Entity;
 abstract class AbstractClosure
 {
     /**
-	 * @Id
-	 * @Column(type="integer")
-	 * @GeneratedValue(strategy="IDENTITY")
-	 */
-	private $id;
-	
-	/**
+     * @Id
+     * @Column(type="integer")
+     * @GeneratedValue(strategy="IDENTITY")
+     */
+    private $id;
+    
+    /**
      * @Column(type="integer")
      */
     private $ancestor;

+ 14 - 14
lib/Gedmo/Tree/Entity/Repository/ClosureTreeRepository.php

@@ -39,34 +39,34 @@ class ClosureTreeRepository extends AbstractTreeRepository
             ->where('c.ancestor = :node_id')
             ->andWhere('c.ancestor != c.descendant');
         
-		if ($direct === true) {
-			$qb->andWhere('c.depth = 1');
+        if ($direct === true) {
+            $qb->andWhere('c.depth = 1');
         }
         
         $qb->setParameter('node_id', $id);
-		
+        
         return $qb->getQuery()->getSingleScalarResult();
     }
-	
-	
-	protected function getQueryBuilder()
-	{
+
+
+    protected function getQueryBuilder()
+    {
         $qb = $this->_em->createQueryBuilder();
         
         return $qb;
-	}
-	
-	protected function getIdFromEntity( $node )
-	{
+    }
+    
+    protected function getIdFromEntity( $node )
+    {
         $meta = $this->_em->getClassMetadata(get_class($node));
         $nodeID = $meta->getSingleIdentifierFieldName();
         $refProp = $meta->getReflectionProperty($nodeID);
         $id = $refProp->getValue($node);
         
         return $id;
-	}
-	
-	/**
+    }
+    
+    /**
      * {@inheritdoc}
      */
     protected function validates()

+ 19 - 22
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -38,8 +38,8 @@ class Closure implements Strategy
      * @var array
      */
     protected $pendingChildNodeInserts = array();
-	
-	/**
+    
+    /**
      * List of pending Nodes to remove
      * 
      * @var array
@@ -61,8 +61,8 @@ class Closure implements Strategy
     {
         return Strategy::CLOSURE;
     }
-	
-	/**
+    
+    /**
      * {@inheritdoc}
      */
     public function processPrePersist($em, $entity)
@@ -108,20 +108,20 @@ class Closure implements Strategy
         $entityTable = $meta->getTableName();
         $closureTable = $closureMeta->getTableName();
         $entries = array();
-		$childrenIDs = array();
+        $childrenIDs = array();
         $ancestorsIDs = array();
         
-		// If node has children it means it already has a self referencing row, so we skip its insertion
-		if ($addNodeChildrenToAncestors === false) {
+        // If node has children it means it already has a self referencing row, so we skip its insertion
+        if ($addNodeChildrenToAncestors === false) {
             $entries[] = array(
                 'ancestor' => $id,
                 'descendant' => $id,
                 'depth' => 0
             );
         }
-		
+        
         $parent = $meta->getReflectionProperty($config['parent'])->getValue($entity);
-		
+        
         if ( $parent ) {
             $parentId = $meta->getReflectionProperty($identifier)->getValue($parent);
             $dql = "SELECT c.ancestor, c.depth FROM {$closureMeta->name} c";
@@ -135,7 +135,7 @@ class Closure implements Strategy
                     'depth' => $ancestor['depth'] + 1
                 );
                 $ancestorsIDs[] = $ancestor['ancestor'];
-				
+                
                 if ($addNodeChildrenToAncestors === true) {
                     $dql = "SELECT c.descendant, c.depth FROM {$closureMeta->name} c";
                     $dql .= " WHERE c.ancestor = {$id} AND c.ancestor != c.descendant";
@@ -190,18 +190,15 @@ class Closure implements Strategy
         $oldParent = $change[0];
         $nodeId = $this->extractIdentifier($em, $entity);
         $table = $closureMeta->getTableName();
-		
+        
         if ($oldParent) {
             $this->removeClosurePathsOfNodeID($em, $table, $nodeId);
             
             $this->insertNode($em, $entity, true);
         }
-        
-        //\Doctrine\Common\Util\Debug::dump($oldParent);
-        //die();
     }
-	
-	/**
+    
+    /**
      * {@inheritdoc}
      */
     public function processScheduledDelete($em, $entity)
@@ -218,7 +215,7 @@ class Closure implements Strategy
     }
 	
     public function removeNode(EntityManager $em, $entity, $maintainSelfReferencingRow = false, $maintainSelfReferencingRowOfChildren = false)
-	{
+    {
         $meta = $em->getClassMetadata(get_class($entity));
         $config = $this->listener->getConfiguration($em, $meta->name);
         $closureMeta = $em->getClassMetadata($config['closure']);
@@ -227,13 +224,13 @@ class Closure implements Strategy
         $this->removeClosurePathsOfNodeID($em, $closureMeta->getTableName(), $id, $maintainSelfReferencingRow, $maintainSelfReferencingRowOfChildren);
 	}
     
-	public function removeClosurePathsOfNodeID(EntityManager $em, $table, $nodeId, $maintainSelfReferencingRow = true, $maintainSelfReferencingRowOfChildren = true)
-	{
+    public function removeClosurePathsOfNodeID(EntityManager $em, $table, $nodeId, $maintainSelfReferencingRow = true, $maintainSelfReferencingRowOfChildren = true)
+    {
         $subquery = "SELECT c1.id FROM {$table} c1 ";
         $subquery .= "WHERE c1.descendant IN ( SELECT c2.descendant FROM {$table} c2 WHERE c2.ancestor = :id ) ";
         $subquery .= "AND ( c1.ancestor IN ( SELECT c3.ancestor FROM {$table} c3 WHERE c3.descendant = :id ";
         
-		if ($maintainSelfReferencingRow === true)
+        if ($maintainSelfReferencingRow === true)
         {
             $subquery .= "AND c3.descendant != c3.ancestor ";
         }
@@ -244,9 +241,9 @@ class Closure implements Strategy
         }
         
         $subquery .= " ) ) ";
-		
+        
         $subquery = "DELETE FROM {$table} WHERE {$table}.id IN ( SELECT temp_table.id FROM ( {$subquery} ) temp_table )";
-		
+        
         if (!$em->getConnection()->executeQuery($subquery, array('id' => $nodeId))) {
             throw new \Gedmo\Exception\RuntimeException('Failed to delete old Closure records');
         }