API: re factored Hierarchy class to use new ::get() syntax

API: removed broken & unused method Hierarchy->partialTreeAsUL()
This commit is contained in:
Zauberfisch 2013-03-12 10:26:00 +00:00
parent c6eb1924ca
commit 215628a1ea

View File

@ -421,24 +421,6 @@ class Hierarchy extends DataExtension {
return isset(self::$treeOpened[$baseClass][$id]) ? self::$treeOpened[$baseClass][$id] : false; return isset(self::$treeOpened[$baseClass][$id]) ? self::$treeOpened[$baseClass][$id] : false;
} }
/**
* Return a partial tree as an HTML UL.
*/
public function partialTreeAsUL($minCount = 50) {
$children = $this->owner->AllChildren();
if($children) {
if($attributes) $attributes = " $attributes";
$output = "<ul$attributes>\n";
foreach($children as $child) {
$output .= eval("return $titleEval;") . "\n" .
$child->getChildrenAsUL("", $titleEval, $extraArg) . "</li>\n";
}
$output .= "</ul>\n";
}
return $output;
}
/** /**
* Get a list of this DataObject's and all it's descendants IDs. * Get a list of this DataObject's and all it's descendants IDs.
* @return int * @return int
@ -470,19 +452,14 @@ class Hierarchy extends DataExtension {
/** /**
* Get the children for this DataObject. * Get the children for this DataObject.
* @return SS_List * @return ArrayList
*/ */
public function Children() { public function Children() {
if(!(isset($this->_cache_children) && $this->_cache_children)) { if(!(isset($this->_cache_children) && $this->_cache_children)) {
$result = $this->owner->stageChildren(false); $result = $this->owner->stageChildren(false);
if(isset($result)) { $this->_cache_children = $result->filterByCallback(function($item) {
$this->_cache_children = new ArrayList(); return $item->canView();
foreach($result as $child) { });
if($child->canView()) {
$this->_cache_children->push($child);
}
}
}
} }
return $this->_cache_children; return $this->_cache_children;
} }
@ -516,9 +493,6 @@ class Hierarchy extends DataExtension {
public function doAllChildrenIncludingDeleted($context = null) { public function doAllChildrenIncludingDeleted($context = null) {
if(!$this->owner) user_error('Hierarchy::doAllChildrenIncludingDeleted() called without $this->owner'); if(!$this->owner) user_error('Hierarchy::doAllChildrenIncludingDeleted() called without $this->owner');
$idxStageChildren = array();
$idxLiveChildren = array();
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
if($baseClass) { if($baseClass) {
$stageChildren = $this->owner->stageChildren(true); $stageChildren = $this->owner->stageChildren(true);
@ -596,21 +570,16 @@ class Hierarchy extends DataExtension {
* *
* @param showAll Inlcude all of the elements, even those not shown in the menus. * @param showAll Inlcude all of the elements, even those not shown in the menus.
* (only applicable when extension is applied to {@link SiteTree}). * (only applicable when extension is applied to {@link SiteTree}).
* @return SS_List * @return DataList
*/ */
public function stageChildren($showAll = false) { public function stageChildren($showAll = false) {
if($this->owner->db('ShowInMenus')) {
$extraFilter = ($showAll) ? '' : " AND \"ShowInMenus\"=1";
} else {
$extraFilter = '';
}
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
$staged = $baseClass::get()
$staged = DataObject::get($baseClass, "\"{$baseClass}\".\"ParentID\" = " ->filter('ParentID', (int)$this->owner->ID)
. (int)$this->owner->ID . " AND \"{$baseClass}\".\"ID\" != " . (int)$this->owner->ID ->exclude('ID', (int)$this->owner->ID);
. $extraFilter, ""); if (!$showAll && $this->owner->db('ShowInMenus')) {
$staged = $staged->filter('ShowInMenus', 1);
}
$this->owner->extend("augmentStageChildren", $staged, $showAll); $this->owner->extend("augmentStageChildren", $staged, $showAll);
return $staged; return $staged;
} }
@ -629,16 +598,15 @@ class Hierarchy extends DataExtension {
} }
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
$id = $this->owner->ID; $children = $baseClass::get()
->filter('ParentID', (int)$this->owner->ID)
$children = DataObject::get($baseClass) ->exclude('ID', (int)$this->owner->ID)
->where("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id")
->setDataQueryParam(array( ->setDataQueryParam(array(
'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage', 'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage',
'Versioned.stage' => 'Live' 'Versioned.stage' => 'Live'
)); ));
if(!$showAll) $children = $children->where('"ShowInMenus" = 1'); if(!$showAll) $children = $children->filter('ShowInMenus', 1);
return $children; return $children;
} }
@ -717,9 +685,12 @@ class Hierarchy extends DataExtension {
$nextNode = null; $nextNode = null;
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
$children = DataObject::get(ClassInfo::baseDataClass($this->owner->class), $children = $baseClass::get()
"\"$baseClass\".\"ParentID\"={$this->owner->ID}" . ( ( $afterNode ) ? " AND \"Sort\" > " ->filter('ParentID', (int)$this->owner->ID)
. sprintf( '%d', $afterNode->Sort ) : "" ), '"Sort" ASC'); ->sort('Sort', 'ASC');
if ($afterNode) {
$children = $children->filter('Sort:GreaterThan', $afterNode->Sort);
}
// Try all the siblings of this node after the given node // Try all the siblings of this node after the given node
/*if( $siblings = DataObject::get( ClassInfo::baseDataClass($this->owner->class), /*if( $siblings = DataObject::get( ClassInfo::baseDataClass($this->owner->class),