Bläddra i källkod

[Tree] Minor fixes and cosmetic changes.

comfortablynumb 13 år sedan
förälder
incheckning
ba1901475e

+ 73 - 1
lib/Gedmo/Tree/Document/MongoDB/Repository/AbstractTreeRepository.php

@@ -82,7 +82,7 @@ abstract class AbstractTreeRepository extends DocumentRepository implements Repo
     /**
      * {@inheritDoc}
      */
-    public function childrenHierarchy($node = null, $direct = false, array $options = array())
+    public function childrenHierarchy($node = null, $direct = false, array $options = array(), $includeNode = false)
     {
         return $this->repoUtils->childrenHierarchy($node, $direct, $options);
     }
@@ -110,4 +110,76 @@ abstract class AbstractTreeRepository extends DocumentRepository implements Repo
      * @return bool
      */
     abstract protected function validate();
+
+    /**
+     * Get all root nodes query builder
+     *
+     * @param string - Sort by field
+     * @param string - Sort direction ("asc" or "desc")
+     *
+     * @return \Doctrine\MongoDB\Query\Builder - QueryBuilder object
+     */
+    abstract public function getRootNodesQueryBuilder($sortByField = null, $direction = 'asc');
+
+    /**
+     * Get all root nodes query
+     *
+     * @param string - Sort by field
+     * @param string - Sort direction ("asc" or "desc")
+     *
+     * @return \Doctrine\MongoDB\Query\Query - Query object
+     */
+    abstract public function getRootNodesQuery($sortByField = null, $direction = 'asc');
+
+    /**
+     * Returns a QueryBuilder configured to return an array of nodes suitable for buildTree method
+     *
+     * @param object $node - Root node
+     * @param bool $direct - Obtain direct children?
+     * @param array $config - Metadata configuration
+     * @param array $options - Options
+     * @param boolean $includeNode - Include node in results?
+     *
+     * @return \Doctrine\MongoDB\Query\Builder - QueryBuilder object
+     */
+    abstract public function getNodesHierarchyQueryBuilder($node = null, $direct, array $config, array $options = array(), $includeNode = false);
+
+    /**
+     * Returns a Query configured to return an array of nodes suitable for buildTree method
+     *
+     * @param object $node - Root node
+     * @param bool $direct - Obtain direct children?
+     * @param array $config - Metadata configuration
+     * @param array $options - Options
+     * @param boolean $includeNode - Include node in results?
+     *
+     * @return \Doctrine\MongoDB\Query\Query - Query object
+     */
+    abstract public function getNodesHierarchyQuery($node = null, $direct, array $config, array $options = array(), $includeNode = false);
+
+    /**
+     * Get list of children followed by given $node. This returns a QueryBuilder object
+     *
+     * @param object $node - if null, all tree nodes will be taken
+     * @param boolean $direct - true to take only direct children
+     * @param string $sortByField - field name to sort by
+     * @param string $direction - sort direction : "ASC" or "DESC"
+     * @param bool $includeNode - Include the root node in results?
+     *
+     * @return \Doctrine\MongoDB\Query\Builder - QueryBuilder object
+     */
+    abstract public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
+
+    /**
+     * Get list of children followed by given $node. This returns a Query
+     *
+     * @param object $node - if null, all tree nodes will be taken
+     * @param boolean $direct - true to take only direct children
+     * @param string $sortByField - field name to sort by
+     * @param string $direction - sort direction : "ASC" or "DESC"
+     * @param bool $includeNode - Include the root node in results?
+     *
+     * @return \Doctrine\MongoDB\Query\Query - Query object
+     */
+    abstract public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
 }

+ 72 - 0
lib/Gedmo/Tree/Entity/Repository/AbstractTreeRepository.php

@@ -110,4 +110,76 @@ abstract class AbstractTreeRepository extends EntityRepository implements Reposi
      * @return bool
      */
     abstract protected function validate();
+
+    /**
+     * Get all root nodes query builder
+     *
+     * @param string - Sort by field
+     * @param string - Sort direction ("asc" or "desc")
+     *
+     * @return \Doctrine\ORM\QueryBuilder - QueryBuilder object
+     */
+    abstract public function getRootNodesQueryBuilder($sortByField = null, $direction = 'asc');
+
+    /**
+     * Get all root nodes query
+     *
+     * @param string - Sort by field
+     * @param string - Sort direction ("asc" or "desc")
+     *
+     * @return \Doctrine\ORM\Query - Query object
+     */
+    abstract public function getRootNodesQuery($sortByField = null, $direction = 'asc');
+
+    /**
+     * Returns a QueryBuilder configured to return an array of nodes suitable for buildTree method
+     *
+     * @param object $node - Root node
+     * @param bool $direct - Obtain direct children?
+     * @param array $config - Metadata configuration
+     * @param array $options - Options
+     * @param boolean $includeNode - Include node in results?
+     *
+     * @return \Doctrine\ORM\QueryBuilder - QueryBuilder object
+     */
+    abstract public function getNodesHierarchyQueryBuilder($node = null, $direct, array $config, array $options = array(), $includeNode = false);
+
+    /**
+     * Returns a Query configured to return an array of nodes suitable for buildTree method
+     *
+     * @param object $node - Root node
+     * @param bool $direct - Obtain direct children?
+     * @param array $config - Metadata configuration
+     * @param array $options - Options
+     * @param boolean $includeNode - Include node in results?
+     *
+     * @return \Doctrine\ORM\Query - Query object
+     */
+    abstract public function getNodesHierarchyQuery($node = null, $direct, array $config, array $options = array(), $includeNode = false);
+
+    /**
+     * Get list of children followed by given $node. This returns a QueryBuilder object
+     *
+     * @param object $node - if null, all tree nodes will be taken
+     * @param boolean $direct - true to take only direct children
+     * @param string $sortByField - field name to sort by
+     * @param string $direction - sort direction : "ASC" or "DESC"
+     * @param bool $includeNode - Include the root node in results?
+     *
+     * @return \Doctrine\ORM\QueryBuilder - QueryBuilder object
+     */
+    abstract public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
+
+    /**
+     * Get list of children followed by given $node. This returns a Query
+     *
+     * @param object $node - if null, all tree nodes will be taken
+     * @param boolean $direct - true to take only direct children
+     * @param string $sortByField - field name to sort by
+     * @param string $direction - sort direction : "ASC" or "DESC"
+     * @param bool $includeNode - Include the root node in results?
+     *
+     * @return \Doctrine\ORM\Query - Query object
+     */
+    abstract public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
 }

+ 1 - 80
lib/Gedmo/Tree/RepositoryInterface.php

@@ -12,22 +12,8 @@ namespace Gedmo\Tree;
  * @link http://www.gediminasm.org
  * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
-interface RepositoryInterface
+interface RepositoryInterface extends RepositoryUtilsInterface
 {
-    /**
-     * Get all root nodes query builder
-     *
-     * @return object - QueryBuilder object
-     */
-    public function getRootNodesQueryBuilder($sortByField = null, $direction = 'asc');
-
-    /**
-     * Get all root nodes query
-     *
-     * @return object - Query object
-     */
-    public function getRootNodesQuery($sortByField = null, $direction = 'asc');
-
     /**
      * Get all root nodes
      *
@@ -35,32 +21,6 @@ interface RepositoryInterface
      */
     public function getRootNodes($sortByField = null, $direction = 'asc');
 
-    /**
-     * Returns a QueryBuilder configured to return an array of nodes suitable for buildTree method
-     *
-     * @param object $node - Root node
-     * @param bool $direct - Obtain direct children?
-     * @param array $config - Metadata configuration
-     * @param array $options - Options
-     * @param boolean $includeNode - Include node in results?
-     *
-     * @return object - QueryBuilder object
-     */
-    public function getNodesHierarchyQueryBuilder($node = null, $direct, array $config, array $options = array(), $includeNode = false);
-
-    /**
-     * Returns a Query configured to return an array of nodes suitable for buildTree method
-     *
-     * @param object $node - Root node
-     * @param bool $direct - Obtain direct children?
-     * @param array $config - Metadata configuration
-     * @param array $options - Options
-     * @param boolean $includeNode - Include node in results?
-     *
-     * @return object - Query object
-     */
-    public function getNodesHierarchyQuery($node = null, $direct, array $config, array $options = array(), $includeNode = false);
-
     /**
      * Returns an array of nodes suitable for method buildTree
      *
@@ -74,30 +34,6 @@ interface RepositoryInterface
      */
     public function getNodesHierarchy($node = null, $direct, array $config, array $options = array(), $includeNode = false);
 
-    /**
-     * Get list of children followed by given $node. This returns a QueryBuilder object
-     *
-     * @param object $node - if null, all tree nodes will be taken
-     * @param boolean $direct - true to take only direct children
-     * @param string $sortByField - field name to sort by
-     * @param string $direction - sort direction : "ASC" or "DESC"
-     * @param bool $includeNode - Include the root node in results?
-     * @return object - QueryBuilder object
-     */
-    public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
-
-    /**
-     * Get list of children followed by given $node. This returns a Query
-     *
-     * @param object $node - if null, all tree nodes will be taken
-     * @param boolean $direct - true to take only direct children
-     * @param string $sortByField - field name to sort by
-     * @param string $direction - sort direction : "ASC" or "DESC"
-     * @param bool $includeNode - Include the root node in results?
-     * @return object - Query object
-     */
-    public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
-
     /**
      * Get list of children followed by given $node
      *
@@ -109,19 +45,4 @@ interface RepositoryInterface
      * @return array - list of given $node children, null on failure
      */
     public function getChildren($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
-
-    /**
-     * @see \Gedmo\Tree\RepositoryUtilsInterface::childrenHierarchy
-     */
-    public function childrenHierarchy($node = null, $direct = false, array $options = array());
-
-    /**
-     * @see \Gedmo\Tree\RepositoryUtilsInterface::buildTree
-     */
-    public function buildTree(array $nodes, array $options = array());
-
-    /**
-     * @see \Gedmo\Tree\RepositoryUtilsInterface::buildTreeArray
-     */
-    public function buildTreeArray(array $nodes);
 }

+ 3 - 1
lib/Gedmo/Tree/RepositoryUtils.php

@@ -90,7 +90,9 @@ class RepositoryUtils implements RepositoryUtilsInterface
         // If you don't want any html output it will return the nested array
         if (!$options['decorate']) {
             return $nestedTree;
-        } elseif (!count($nestedTree)) {
+        }
+
+        if (!count($nestedTree)) {
             return '';
         }
 

+ 0 - 3
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -12,7 +12,6 @@ use Doctrine\ORM\Version;
 use Gedmo\Tool\Wrapper\AbstractWrapper;
 use Gedmo\Mapping\Event\AdapterInterface;
 use Doctrine\Common\Persistence\ObjectManager;
-use Doctrine\ORM\Mapping\ClassMetadata;
 
 /**
  * This strategy makes tree act like
@@ -308,8 +307,6 @@ class Closure implements Strategy
      * Process pending entities to set their "level" value
      *
      * @param \Doctrine\Common\Persistence\ObjectManager $em
-     * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
-     * @param array $config
      */
     protected function setLevelFieldOnPendingNodes(ObjectManager $em)
     {