From 3defa4931c43e2c90bf887793ed0d12da177a011 Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Sun, 11 Oct 2009 00:07:10 +0000 Subject: [PATCH] ENHANCEMENT: Added Hierachy->getAncestors() to return all the parent objects of the class in a DataObjectSet. From: Andrew Short git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88488 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Hierarchy.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) mode change 100644 => 100755 core/model/Hierarchy.php diff --git a/core/model/Hierarchy.php b/core/model/Hierarchy.php old mode 100644 new mode 100755 index dc4292037..f01eb1d03 --- a/core/model/Hierarchy.php +++ b/core/model/Hierarchy.php @@ -559,7 +559,23 @@ class Hierarchy extends DataObjectDecorator { return DataObject::get_one($this->owner->class, $filter); } } - + + /** + * Return all the parents of this class in a set ordered from the lowest to highest parent. + * + * @return DataObjectSet + */ + public function getAncestors() { + $ancestors = new DataObjectSet(); + $object = $this->owner; + + while($object = $object->getParent()) { + $ancestors->push($object); + } + + return $ancestors; + } + /** * Get the next node in the tree of the type. If there is no instance of the className descended from this node, * then search the parents.