2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\ORM\Hierarchy;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Admin\LeftAndMain;
|
|
|
|
use SilverStripe\Control\Controller;
|
2016-08-11 01:40:23 +02:00
|
|
|
use SilverStripe\ORM\DataList;
|
2017-03-29 06:23:49 +02:00
|
|
|
use SilverStripe\ORM\SS_List;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\ValidationResult;
|
|
|
|
use SilverStripe\ORM\ArrayList;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\ORM\DataExtension;
|
2017-03-21 04:22:23 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-08-19 00:51:35 +02:00
|
|
|
use Exception;
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2014-12-01 13:20:09 +01:00
|
|
|
* DataObjects that use the Hierarchy extension can be be organised as a hierarchy, with children and parents. The most
|
|
|
|
* obvious example of this is SiteTree.
|
|
|
|
*
|
2016-08-19 00:51:35 +02:00
|
|
|
* @property int $ParentID
|
2017-03-29 06:23:49 +02:00
|
|
|
* @property DataObject|Hierarchy $owner
|
2016-08-19 00:51:35 +02:00
|
|
|
* @method DataObject Parent()
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2017-03-29 06:23:49 +02:00
|
|
|
class Hierarchy extends DataExtension
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
/**
|
|
|
|
* The lower bounds for the amount of nodes to mark. If set, the logic will expand nodes until it reaches at least
|
|
|
|
* this number, and then stops. Root nodes will always show regardless of this settting. Further nodes can be
|
|
|
|
* lazy-loaded via ajax. This isn't a hard limit. Example: On a value of 10, with 20 root nodes, each having 30
|
|
|
|
* children, the actual node count will be 50 (all root nodes plus first expanded child).
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private static $node_threshold_total = 50;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit on the maximum children a specific node can display. Serves as a hard limit to avoid exceeding available
|
|
|
|
* server resources in generating the tree, and browser resources in rendering it. Nodes with children exceeding
|
|
|
|
* this value typically won't display any children, although this is configurable through the $nodeCountCallback
|
|
|
|
* parameter in {@link getChildrenAsUL()}. "Root" nodes will always show all children, regardless of this setting.
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private static $node_threshold_leaf = 250;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of classnames to exclude from display in both the CMS and front end
|
|
|
|
* displays. ->Children() and ->AllChildren affected.
|
|
|
|
* Especially useful for big sets of pages like listings
|
|
|
|
* If you use this, and still need the classes to be editable
|
|
|
|
* then add a model admin for the class
|
|
|
|
* Note: Does not filter subclasses (non-inheriting)
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @config
|
|
|
|
*/
|
|
|
|
private static $hide_from_hierarchy = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of classnames to exclude from display in the page tree views of the CMS,
|
|
|
|
* unlike $hide_from_hierarchy above which effects both CMS and front end.
|
|
|
|
* Especially useful for big sets of pages like listings
|
|
|
|
* If you use this, and still need the classes to be editable
|
|
|
|
* then add a model admin for the class
|
|
|
|
* Note: Does not filter subclasses (non-inheriting)
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @config
|
|
|
|
*/
|
|
|
|
private static $hide_from_cms_tree = array();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-10-05 06:23:02 +02:00
|
|
|
/**
|
|
|
|
* Prevent virtual page virtualising these fields
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $non_virtual_fields = [
|
|
|
|
'_cache_children',
|
|
|
|
'_cache_numChildren',
|
|
|
|
];
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
public static function get_extra_config($class, $extension, $args)
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
return array(
|
|
|
|
'has_one' => array('Parent' => $class)
|
|
|
|
);
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
/**
|
|
|
|
* Validate the owner object - check for existence of infinite loops.
|
|
|
|
*
|
|
|
|
* @param ValidationResult $validationResult
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function validate(ValidationResult $validationResult)
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
// The object is new, won't be looping.
|
2017-03-29 06:23:49 +02:00
|
|
|
/** @var DataObject|Hierarchy $owner */
|
|
|
|
$owner = $this->owner;
|
|
|
|
if (!$owner->ID) {
|
2016-11-29 00:31:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-11-23 06:09:10 +01:00
|
|
|
// The object has no parent, won't be looping.
|
2017-03-29 06:23:49 +02:00
|
|
|
if (!$owner->ParentID) {
|
2016-11-29 00:31:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-11-23 06:09:10 +01:00
|
|
|
// The parent has not changed, skip the check for performance reasons.
|
2017-03-29 06:23:49 +02:00
|
|
|
if (!$owner->isChanged('ParentID')) {
|
2016-11-29 00:31:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
// Walk the hierarchy upwards until we reach the top, or until we reach the originating node again.
|
2017-03-29 06:23:49 +02:00
|
|
|
$node = $owner;
|
|
|
|
while ($node && $node->ParentID) {
|
|
|
|
if ((int)$node->ParentID === (int)$owner->ID) {
|
2016-11-23 06:09:10 +01:00
|
|
|
// Hierarchy is looping.
|
|
|
|
$validationResult->addError(
|
|
|
|
_t(
|
2017-05-17 07:40:13 +02:00
|
|
|
__CLASS__ . '.InfiniteLoopNotAllowed',
|
2016-11-23 06:09:10 +01:00
|
|
|
'Infinite loop found within the "{type}" hierarchy. Please change the parent to resolve this',
|
|
|
|
'First argument is the class that makes up the hierarchy.',
|
2017-05-17 07:40:13 +02:00
|
|
|
array('type' => get_class($owner))
|
2016-11-23 06:09:10 +01:00
|
|
|
),
|
|
|
|
'bad',
|
|
|
|
'INFINITE_LOOP'
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2017-03-29 06:23:49 +02:00
|
|
|
$node = $node->Parent();
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
/**
|
|
|
|
* Get a list of this DataObject's and all it's descendants IDs.
|
|
|
|
*
|
|
|
|
* @return int[]
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function getDescendantIDList()
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
$idList = array();
|
|
|
|
$this->loadDescendantIDListInto($idList);
|
|
|
|
return $idList;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
/**
|
|
|
|
* Get a list of this DataObject's and all it's descendants ID, and put them in $idList.
|
|
|
|
*
|
|
|
|
* @param array $idList Array to put results in.
|
2017-03-29 06:23:49 +02:00
|
|
|
* @param DataObject|Hierarchy $node
|
2016-11-23 06:09:10 +01:00
|
|
|
*/
|
2017-03-29 06:23:49 +02:00
|
|
|
protected function loadDescendantIDListInto(&$idList, $node = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-03-29 06:23:49 +02:00
|
|
|
if (!$node) {
|
|
|
|
$node = $this->owner;
|
|
|
|
}
|
|
|
|
$children = $node->AllChildren();
|
|
|
|
foreach ($children as $child) {
|
|
|
|
if (!in_array($child->ID, $idList)) {
|
2016-11-23 06:09:10 +01:00
|
|
|
$idList[] = $child->ID;
|
2017-03-29 06:23:49 +02:00
|
|
|
$this->loadDescendantIDListInto($idList, $child);
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-29 06:23:49 +02:00
|
|
|
* Get the children for this DataObject filtered by canView()
|
2016-11-23 06:09:10 +01:00
|
|
|
*
|
2017-03-29 06:23:49 +02:00
|
|
|
* @return SS_List
|
2016-11-23 06:09:10 +01:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function Children()
|
|
|
|
{
|
2017-10-05 06:23:02 +02:00
|
|
|
$children = $this->owner->_cache_children;
|
|
|
|
if ($children) {
|
|
|
|
return $children;
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
2017-03-29 06:23:49 +02:00
|
|
|
|
2017-10-05 06:23:02 +02:00
|
|
|
$children = $this
|
2017-03-29 06:23:49 +02:00
|
|
|
->owner
|
|
|
|
->stageChildren(false)
|
|
|
|
->filterByCallback(function (DataObject $record) {
|
|
|
|
return $record->canView();
|
|
|
|
});
|
2017-10-05 06:23:02 +02:00
|
|
|
$this->owner->_cache_children = $children;
|
|
|
|
return $children;
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all children, including those 'not in menus'.
|
|
|
|
*
|
|
|
|
* @return DataList
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function AllChildren()
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
return $this->owner->stageChildren(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all children, including those that have been deleted but are still in live.
|
|
|
|
* - Deleted children will be marked as "DeletedFromStage"
|
|
|
|
* - Added children will be marked as "AddedToStage"
|
|
|
|
* - Modified children will be marked as "ModifiedOnStage"
|
|
|
|
* - Everything else has "SameOnStage" set, as an indicator that this information has been looked up.
|
|
|
|
*
|
|
|
|
* @return ArrayList
|
|
|
|
*/
|
2017-03-29 06:23:49 +02:00
|
|
|
public function AllChildrenIncludingDeleted()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-03-29 06:23:49 +02:00
|
|
|
$stageChildren = $this->owner->stageChildren(true);
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-03-29 06:23:49 +02:00
|
|
|
// Add live site content that doesn't exist on the stage site, if required.
|
|
|
|
if ($this->owner->hasExtension(Versioned::class)) {
|
|
|
|
// Next, go through the live children. Only some of these will be listed
|
|
|
|
$liveChildren = $this->owner->liveChildren(true, true);
|
|
|
|
if ($liveChildren) {
|
|
|
|
$merged = new ArrayList();
|
|
|
|
$merged->merge($stageChildren);
|
|
|
|
$merged->merge($liveChildren);
|
|
|
|
$stageChildren = $merged;
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 06:23:49 +02:00
|
|
|
$this->owner->extend("augmentAllChildrenIncludingDeleted", $stageChildren);
|
2016-11-23 06:09:10 +01:00
|
|
|
return $stageChildren;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
/**
|
|
|
|
* Return all the children that this page had, including pages that were deleted from both stage & live.
|
|
|
|
*
|
|
|
|
* @return DataList
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function AllHistoricalChildren()
|
|
|
|
{
|
2017-03-21 04:22:23 +01:00
|
|
|
if (!$this->owner->hasExtension(Versioned::class)) {
|
2016-11-23 06:09:10 +01:00
|
|
|
throw new Exception('Hierarchy->AllHistoricalChildren() only works with Versioned extension applied');
|
|
|
|
}
|
|
|
|
|
|
|
|
$baseTable = $this->owner->baseTable();
|
|
|
|
$parentIDColumn = $this->owner->getSchema()->sqlColumnForField($this->owner, 'ParentID');
|
|
|
|
return Versioned::get_including_deleted(
|
|
|
|
$this->owner->baseClass(),
|
|
|
|
[ $parentIDColumn => $this->owner->ID ],
|
|
|
|
"\"{$baseTable}\".\"ID\" ASC"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of children that this page ever had, including pages that were deleted.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function numHistoricalChildren()
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
return $this->AllHistoricalChildren()->count();
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
/**
|
|
|
|
* Return the number of direct children. By default, values are cached after the first invocation. Can be
|
|
|
|
* augumented by {@link augmentNumChildrenCountQuery()}.
|
|
|
|
*
|
|
|
|
* @param bool $cache Whether to retrieve values from cache
|
|
|
|
* @return int
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function numChildren($cache = true)
|
|
|
|
{
|
2017-03-29 06:23:49 +02:00
|
|
|
// Load if caching
|
2017-10-05 06:23:02 +02:00
|
|
|
if ($cache) {
|
|
|
|
$numChildren = $this->owner->_cache_numChildren;
|
|
|
|
if (isset($numChildren)) {
|
|
|
|
return $numChildren;
|
|
|
|
}
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 06:23:49 +02:00
|
|
|
// We call stageChildren(), because Children() has canView() filtering
|
2017-10-05 06:23:02 +02:00
|
|
|
$numChildren = (int)$this->owner->stageChildren(true)->Count();
|
2017-03-29 06:23:49 +02:00
|
|
|
|
|
|
|
// Save if caching
|
|
|
|
if ($cache) {
|
2017-10-05 06:23:02 +02:00
|
|
|
$this->owner->_cache_numChildren = $numChildren;
|
2017-03-29 06:23:49 +02:00
|
|
|
}
|
2017-10-05 06:23:02 +02:00
|
|
|
return $numChildren;
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function showingCMSTree()
|
|
|
|
{
|
2017-03-10 04:43:10 +01:00
|
|
|
if (!Controller::has_curr() || !class_exists(LeftAndMain::class)) {
|
2016-11-29 00:31:16 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-11-23 06:09:10 +01:00
|
|
|
$controller = Controller::curr();
|
|
|
|
return $controller instanceof LeftAndMain
|
|
|
|
&& in_array($controller->getAction(), array("treeview", "listview", "getsubtree"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return children in the stage site.
|
|
|
|
*
|
|
|
|
* @param bool $showAll Include all of the elements, even those not shown in the menus. Only applicable when
|
|
|
|
* extension is applied to {@link SiteTree}.
|
|
|
|
* @return DataList
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function stageChildren($showAll = false)
|
|
|
|
{
|
2017-03-29 06:23:49 +02:00
|
|
|
$hideFromHierarchy = $this->owner->config()->hide_from_hierarchy;
|
|
|
|
$hideFromCMSTree = $this->owner->config()->hide_from_cms_tree;
|
2017-10-05 06:23:02 +02:00
|
|
|
$baseClass = $this->owner->baseClass();
|
|
|
|
$staged = DataObject::get($baseClass)
|
2016-11-23 06:09:10 +01:00
|
|
|
->filter('ParentID', (int)$this->owner->ID)
|
|
|
|
->exclude('ID', (int)$this->owner->ID);
|
2017-03-29 06:23:49 +02:00
|
|
|
if ($hideFromHierarchy) {
|
|
|
|
$staged = $staged->exclude('ClassName', $hideFromHierarchy);
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
2017-03-29 06:23:49 +02:00
|
|
|
if ($hideFromCMSTree && $this->showingCMSTree()) {
|
|
|
|
$staged = $staged->exclude('ClassName', $hideFromCMSTree);
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
if (!$showAll && DataObject::getSchema()->fieldSpec($this->owner, 'ShowInMenus')) {
|
|
|
|
$staged = $staged->filter('ShowInMenus', 1);
|
|
|
|
}
|
|
|
|
$this->owner->extend("augmentStageChildren", $staged, $showAll);
|
|
|
|
return $staged;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return children in the live site, if it exists.
|
|
|
|
*
|
|
|
|
* @param bool $showAll Include all of the elements, even those not shown in the menus. Only
|
|
|
|
* applicable when extension is applied to {@link SiteTree}.
|
|
|
|
* @param bool $onlyDeletedFromStage Only return items that have been deleted from stage
|
|
|
|
* @return DataList
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function liveChildren($showAll = false, $onlyDeletedFromStage = false)
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
if (!$this->owner->hasExtension(Versioned::class)) {
|
|
|
|
throw new Exception('Hierarchy->liveChildren() only works with Versioned extension applied');
|
|
|
|
}
|
|
|
|
|
2017-03-29 06:23:49 +02:00
|
|
|
$hideFromHierarchy = $this->owner->config()->hide_from_hierarchy;
|
|
|
|
$hideFromCMSTree = $this->owner->config()->hide_from_cms_tree;
|
|
|
|
$children = DataObject::get($this->owner->baseClass())
|
2016-11-23 06:09:10 +01:00
|
|
|
->filter('ParentID', (int)$this->owner->ID)
|
|
|
|
->exclude('ID', (int)$this->owner->ID)
|
|
|
|
->setDataQueryParam(array(
|
|
|
|
'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage',
|
|
|
|
'Versioned.stage' => 'Live'
|
|
|
|
));
|
2017-03-29 06:23:49 +02:00
|
|
|
if ($hideFromHierarchy) {
|
|
|
|
$children = $children->exclude('ClassName', $hideFromHierarchy);
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
2017-03-29 06:23:49 +02:00
|
|
|
if ($hideFromCMSTree && $this->showingCMSTree()) {
|
|
|
|
$children = $children->exclude('ClassName', $hideFromCMSTree);
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
if (!$showAll && DataObject::getSchema()->fieldSpec($this->owner, 'ShowInMenus')) {
|
|
|
|
$children = $children->filter('ShowInMenus', 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $children;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get this object's parent, optionally filtered by an SQL clause. If the clause doesn't match the parent, nothing
|
|
|
|
* is returned.
|
|
|
|
*
|
|
|
|
* @param string $filter
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function getParent($filter = null)
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
$parentID = $this->owner->ParentID;
|
|
|
|
if (empty($parentID)) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-05 06:23:02 +02:00
|
|
|
$baseClass = $this->owner->baseClass();
|
|
|
|
$idSQL = $this->owner->getSchema()->sqlColumnForField($baseClass, 'ID');
|
|
|
|
return DataObject::get_one($baseClass, [
|
|
|
|
[$idSQL => $parentID],
|
2016-11-23 06:09:10 +01:00
|
|
|
$filter
|
2017-10-05 06:23:02 +02:00
|
|
|
]);
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-29 06:23:49 +02:00
|
|
|
* Return all the parents of this class in a set ordered from the closest to furtherest parent.
|
2016-11-23 06:09:10 +01:00
|
|
|
*
|
2017-03-29 06:23:49 +02:00
|
|
|
* @param bool $includeSelf
|
2016-11-23 06:09:10 +01:00
|
|
|
* @return ArrayList
|
|
|
|
*/
|
2017-03-29 06:23:49 +02:00
|
|
|
public function getAncestors($includeSelf = false)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
$ancestors = new ArrayList();
|
2017-03-29 06:23:49 +02:00
|
|
|
$object = $this->owner;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-03-29 06:23:49 +02:00
|
|
|
if ($includeSelf) {
|
|
|
|
$ancestors->push($object);
|
|
|
|
}
|
2016-11-23 06:09:10 +01:00
|
|
|
while ($object = $object->getParent()) {
|
|
|
|
$ancestors->push($object);
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
return $ancestors;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
/**
|
|
|
|
* Returns a human-readable, flattened representation of the path to the object, using its {@link Title} attribute.
|
|
|
|
*
|
|
|
|
* @param string $separator
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function getBreadcrumbs($separator = ' » ')
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
$crumbs = array();
|
|
|
|
$ancestors = array_reverse($this->owner->getAncestors()->toArray());
|
2017-03-29 06:23:49 +02:00
|
|
|
/** @var DataObject $ancestor */
|
2016-11-29 00:31:16 +01:00
|
|
|
foreach ($ancestors as $ancestor) {
|
2017-03-29 06:23:49 +02:00
|
|
|
$crumbs[] = $ancestor->getTitle();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-03-29 06:23:49 +02:00
|
|
|
$crumbs[] = $this->owner->getTitle();
|
2016-11-23 06:09:10 +01:00
|
|
|
return implode($separator, $crumbs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush all Hierarchy caches:
|
|
|
|
* - Children (instance)
|
|
|
|
* - NumChildren (instance)
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
public function flushCache()
|
|
|
|
{
|
2017-10-05 06:23:02 +02:00
|
|
|
$this->owner->_cache_children = null;
|
|
|
|
$this->owner->_cache_numChildren = null;
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
2012-03-27 06:04:11 +02:00
|
|
|
}
|