class MarkedSet (View source)

Contains a set of hierarchical objects generated from a marking compilation run.

A set of nodes can be "marked" for later export, in order to prevent having to export the entire contents of a potentially huge tree.

Traits

A class that can be instantiated or replaced via DI

Properties

protected array $markedNodes

Marked nodes for a given subtree. The first item in this list is the root object of the subtree.

public array $markingFilter

Optional filter callback for filtering nodes to mark

protected DataObject $rootNode
protected string $childrenMethod

Method to use for getting children. Defaults to 'AllChildrenIncludingDeleted'

protected string $numChildrenMethod

Method to use for counting children. Defaults to numChildren

protected int $nodeCountThreshold

Minimum number of nodes to iterate over before stopping recursion

protected int $maxChildNodes

Max number of nodes to return from a single children collection

protected bool $enableLimiting

Enable limiting

protected array $expanded

Cache of DataObjects' expanded statuses: [ClassName][ID] = bool

protected array $treeOpened

Cache of DataObjects' opened statuses: [ID] = bool

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(DataObject $rootNode, string $childrenMethod = null, string $numChildrenMethod = null, int $nodeCountThreshold = null, int $maxChildNodes = null)

Create an empty set with the given class

public
int
getNodeCountThreshold()

Get total number of nodes to get. This acts as a soft lower-bounds for number of nodes to search until found.

public
int
getMaxChildNodes()

Max number of nodes that can be physically rendered at any level.

public
$this
setMaxChildNodes(int $count)

Set hard limit of number of nodes to get for this level

public
$this
setNodeCountThreshold(int $total)

Set max node count

public
string
getChildrenMethod()

Get method to use for getting children

protected
DataObject>
getChildren(DataObject $node)

Get children from this node

public
$this
setChildrenMethod(string $method)

Set method to use for getting children

public
string
getNumChildrenMethod()

Get method name for num children

protected
int
getNumChildren(DataObject $node)

Count children

public
$this
setNumChildrenMethod(string $method)

Set method name to get num children

public
string
renderChildren(string $template = null, array|callable $context = [])

Returns the children of this DataObject as an XHTML UL. This will be called recursively on each child, so if they have children they will be displayed as a UL inside a LI.

public
array
getChildrenAsArray(callable $serialiseEval = null)

Get child data formatted as JSON

protected
renderSubtree(array $data, string|array $template, array|callable $context = [])

Render a node in the tree with the given template

protected
mixed|string
getSubtreeAsArray(array $data, callable $serialiseEval)

Return sub-tree as json array

protected
array|string
getSubtree(DataObject $node, int $depth = 0)

Get tree data for node

public
$this
markPartialTree()

Mark a segment of the tree, by calling mark().

public
$this
setMarkingFilter(string $parameterName, mixed $parameterValue)

Filter the marking to only those object with $node->$parameterName == $parameterValue

public
$this
setMarkingFilterFunction(callable $callback)

Filter the marking to only those where the function returns true. The node in question will be passed to the function.

protected
bool
markingFilterMatches(DataObject $node)

Returns true if the marking filter matches on the given node.

protected
markChildren(DataObject $node)

Mark all children of the given node that match the marking filter.

protected
string
markingClasses(DataObject $node)

Return CSS classes of 'unexpanded', 'closed', both, or neither, as well as a 'jstree-*' state depending on the marking of this DataObject.

public
bool
markById(int $id, bool $open = false)

Mark the children of the DataObject with the given ID.

public
$this
markToExpose(DataObject $childObj)

Expose the given object in the tree, by marking this page and all it ancestors.

public
array
markedNodeIDs()

Return the IDs of all the marked nodes.

public
clearMarks()

Reset marked nodes

public
$this
markExpanded(DataObject $node)

Mark this DataObject as expanded.

public
$this
markUnexpanded(DataObject $node)

Mark this DataObject as unexpanded.

public
$this
markOpened(DataObject $node)

Mark this DataObject's tree as opened.

public
$this
markClosed(DataObject $node)

Mark this DataObject's tree as closed.

public
bool
isMarked(DataObject $node)

Check if this DataObject is marked.

public
bool
isExpanded(DataObject $node)

Check if this DataObject is expanded.

public
bool
isTreeOpened(DataObject $node)

Check if this DataObject's tree is opened.

protected
bool
isNodeLimited(DataObject $node, int $count = null)

Check if this node has too many children

public
$this
setLimitingEnabled(bool $enabled)

Toggle limiting on or off

public
bool
getLimitingEnabled()

Check if limiting is enabled

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(DataObject $rootNode, string $childrenMethod = null, string $numChildrenMethod = null, int $nodeCountThreshold = null, int $maxChildNodes = null)

Create an empty set with the given class

Parameters

DataObject $rootNode

Root node for this set. To collect the entire tree, pass in a singleton object.

string $childrenMethod

Override children method

string $numChildrenMethod

Override children counting method

int $nodeCountThreshold

Minimum threshold for number nodes to mark

int $maxChildNodes

Maximum threshold for number of child nodes to include

int getNodeCountThreshold()

Get total number of nodes to get. This acts as a soft lower-bounds for number of nodes to search until found.

Defaults to value of node_threshold_total of hierarchy class.

Return Value

int

int getMaxChildNodes()

Max number of nodes that can be physically rendered at any level.

Acts as a hard upper bound, after which nodes will be trimmed for performance reasons.

Return Value

int

$this setMaxChildNodes(int $count)

Set hard limit of number of nodes to get for this level

Parameters

int $count

Return Value

$this

$this setNodeCountThreshold(int $total)

Set max node count

Parameters

int $total

Return Value

$this

string getChildrenMethod()

Get method to use for getting children

Return Value

string

protected DataObject> getChildren(DataObject $node)

Get children from this node

Parameters

DataObject $node

Return Value

DataObject>

$this setChildrenMethod(string $method)

Set method to use for getting children

Parameters

string $method

Return Value

$this

Exceptions

InvalidArgumentException

string getNumChildrenMethod()

Get method name for num children

Return Value

string

protected int getNumChildren(DataObject $node)

Count children

Parameters

DataObject $node

Return Value

int

$this setNumChildrenMethod(string $method)

Set method name to get num children

Parameters

string $method

Return Value

$this

string renderChildren(string $template = null, array|callable $context = [])

Returns the children of this DataObject as an XHTML UL. This will be called recursively on each child, so if they have children they will be displayed as a UL inside a LI.

Parameters

string $template

Template for items in the list

array|callable $context

Additional arguments to add to template when rendering due to excessive line length. If callable, this will be executed with the current node dataobject

Return Value

string

array getChildrenAsArray(callable $serialiseEval = null)

Get child data formatted as JSON

Parameters

callable $serialiseEval

A callback that takes a DataObject as a single parameter, and should return an array containing a simple array representation. This result will replace the 'node' property at each point in the tree.

Return Value

array

protected ArrayData renderSubtree(array $data, string|array $template, array|callable $context = [])

Render a node in the tree with the given template

Parameters

array $data

array data for current node

string|array $template

Template to use

array|callable $context

Additional arguments to add to template when rendering due to excessive line length. If callable, this will be executed with the current node dataobject

Return Value

ArrayData

Viewable object representing the root node. use getField('SubTree') to get HTML

protected mixed|string getSubtreeAsArray(array $data, callable $serialiseEval)

Return sub-tree as json array

Parameters

array $data
callable $serialiseEval

A callback that takes a DataObject as a single parameter, and should return an array containing a simple array representation. This result will replace the 'node' property at each point in the tree.

Return Value

mixed|string

protected array|string getSubtree(DataObject $node, int $depth = 0)

Get tree data for node

Parameters

DataObject $node
int $depth

Return Value

array|string

$this markPartialTree()

Mark a segment of the tree, by calling mark().

The method performs a breadth-first traversal until the number of nodes is more than minCount. This is used to get a limited number of tree nodes to show in the CMS initially.

This method returns the number of nodes marked. After this method is called other methods can check isExpanded()} and {@link isMarked() on individual nodes.

Return Value

$this

$this setMarkingFilter(string $parameterName, mixed $parameterValue)

Filter the marking to only those object with $node->$parameterName == $parameterValue

Parameters

string $parameterName

The parameter on each node to check when marking.

mixed $parameterValue

The value the parameter must be to be marked.

Return Value

$this

$this setMarkingFilterFunction(callable $callback)

Filter the marking to only those where the function returns true. The node in question will be passed to the function.

Parameters

callable $callback

Callback to filter

Return Value

$this

protected bool markingFilterMatches(DataObject $node)

Returns true if the marking filter matches on the given node.

Parameters

DataObject $node

Node to check

Return Value

bool

protected DataObject[] markChildren(DataObject $node)

Mark all children of the given node that match the marking filter.

Parameters

DataObject $node

Parent node

Return Value

DataObject[]

List of children marked by this operation

protected string markingClasses(DataObject $node)

Return CSS classes of 'unexpanded', 'closed', both, or neither, as well as a 'jstree-*' state depending on the marking of this DataObject.

Parameters

DataObject $node

Return Value

string

bool markById(int $id, bool $open = false)

Mark the children of the DataObject with the given ID.

Parameters

int $id

ID of parent node

bool $open

If this is true, mark the parent node as opened

Return Value

bool

$this markToExpose(DataObject $childObj)

Expose the given object in the tree, by marking this page and all it ancestors.

Parameters

DataObject $childObj

Return Value

$this

array markedNodeIDs()

Return the IDs of all the marked nodes.

Return Value

array

clearMarks()

Reset marked nodes

$this markExpanded(DataObject $node)

Mark this DataObject as expanded.

Parameters

DataObject $node

Return Value

$this

$this markUnexpanded(DataObject $node)

Mark this DataObject as unexpanded.

Parameters

DataObject $node

Return Value

$this

$this markOpened(DataObject $node)

Mark this DataObject's tree as opened.

Parameters

DataObject $node

Return Value

$this

$this markClosed(DataObject $node)

Mark this DataObject's tree as closed.

Parameters

DataObject $node

Return Value

$this

bool isMarked(DataObject $node)

Check if this DataObject is marked.

Parameters

DataObject $node

Return Value

bool

bool isExpanded(DataObject $node)

Check if this DataObject is expanded.

An expanded object has had it's children iterated through.

Parameters

DataObject $node

Return Value

bool

bool isTreeOpened(DataObject $node)

Check if this DataObject's tree is opened.

This is an expanded node which also should have children visually shown.

Parameters

DataObject $node

Return Value

bool

protected bool isNodeLimited(DataObject $node, int $count = null)

Check if this node has too many children

Parameters

DataObject $node
int $count

Children count (if already calculated)

Return Value

bool

$this setLimitingEnabled(bool $enabled)

Toggle limiting on or off

Parameters

bool $enabled

Return Value

$this

bool getLimitingEnabled()

Check if limiting is enabled

Return Value

bool