ENHANCEMENT: Added Hierachy->getAncestors() to return all the parent objects of the class in a DataObjectSet.

From: Andrew Short <andrewjshort@gmail.com>

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88488 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew Short 2009-10-11 00:07:10 +00:00 committed by Sam Minnee
parent bf50f560df
commit 3defa4931c

18
core/model/Hierarchy.php Normal file → Executable file
View File

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