Permalink
Browse files

BUGFIX Replaced hardcoded SiteTree dependency in DataObjectSet->group…

…WithParents() with method parameter
  • Loading branch information...
1 parent ecc28cb commit 357ea56c02919c71f76edc50138e68ab53668811 @chillu chillu committed Mar 22, 2011
Showing with 5 additions and 3 deletions.
  1. +5 −3 core/model/DataObjectSet.php
@@ -886,6 +886,8 @@ public function debug() {
* @return DataObjectSet
*/
public function groupWithParents($groupField, $groupClassName, $sortParents = null, $parentField = 'ID', $collapse = false, $requiredParents = null) {
+ $groupTable = ClassInfo::baseDataClass($groupClassName);
+
// Each item in this DataObjectSet is grouped into a multidimensional array
// indexed by it's parent. The parent IDs are later used to find the parents
// that make up the returned set.
@@ -913,7 +915,7 @@ public function groupWithParents($groupField, $groupClassName, $sortParents = nu
$parentSet = array();
// get direct parents
- $parents = DataObject::get( 'SiteTree', "\"SiteTree\".\"$parentField\" IN( " . implode( ",", array_keys( $groupedSet ) ) . ")", $sortParents );
+ $parents = DataObject::get($groupClassName, "\"$groupTable\".\"$parentField\" IN( " . implode( ",", array_keys( $groupedSet ) ) . ")", $sortParents );
// for each of these parents...
foreach($parents as $parent) {
@@ -939,7 +941,7 @@ public function groupWithParents($groupField, $groupClassName, $sortParents = nu
if(empty($parentStack)) {
$newParent = new DataObjectSet();
} else {
- $newParent = DataObject::get_one( $groupClassName, "\"SiteTree\".\"$parentField\" IN( " . implode( ",", $parentStack ) . ")" );
+ $newParent = DataObject::get_one( $groupClassName, "\"$groupTable\".\"$parentField\" IN( " . implode( ",", $parentStack ) . ")" );
}
// change each of the descendant's association from the old parent to
@@ -963,7 +965,7 @@ public function groupWithParents($groupField, $groupClassName, $sortParents = nu
if(empty($requiredIDs)) {
$parentSet = new DataObjectSet();
} else {
- $parentSet = DataObject::get( $groupClassName, "\"$groupClassName\".\"$parentField\" IN( " . implode( ",", $requiredIDs ) . ")", $sortParents );
+ $parentSet = DataObject::get( $groupClassName, "\"$groupTable\".\"$parentField\" IN( " . implode( ",", $requiredIDs ) . ")", $sortParents );
}
$parentSet = $parentSet->toArray();

0 comments on commit 357ea56

Please sign in to comment.