MarkedSet
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 |
|
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
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
Create an empty set with the given class
Get total number of nodes to get. This acts as a soft lower-bounds for number of nodes to search until found.
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.
Render a node in the tree with the given template
Return sub-tree as json array
Filter the marking to only those object with $node->$parameterName == $parameterValue
Filter the marking to only those where the function returns true. The node in question will be passed to the function.
Returns true if the marking filter matches on the given node.
Return CSS classes of 'unexpanded', 'closed', both, or neither, as well as a 'jstree-*' state depending on the marking of this DataObject.
Mark the children of the DataObject with the given ID.
Expose the given object in the tree, by marking this page and all it ancestors.
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();
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).
__construct(DataObject $rootNode, string $childrenMethod = null, string $numChildrenMethod = null, int $nodeCountThreshold = null, int $maxChildNodes = null)
Create an empty set with the given class
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.
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.
$this
setMaxChildNodes(int $count)
Set hard limit of number of nodes to get for this level
$this
setNodeCountThreshold(int $total)
Set max node count
string
getChildrenMethod()
Get method to use for getting children
protected DataObject>
getChildren(DataObject $node)
Get children from this node
$this
setChildrenMethod(string $method)
Set method to use for getting children
string
getNumChildrenMethod()
Get method name for num children
protected int
getNumChildren(DataObject $node)
Count children
$this
setNumChildrenMethod(string $method)
Set method name to get num children
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.
array
getChildrenAsArray(callable $serialiseEval = null)
Get child data formatted as JSON
protected ArrayData
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
$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.
$this
setMarkingFilter(string $parameterName, mixed $parameterValue)
Filter the marking to only those object with $node->$parameterName == $parameterValue
$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 DataObject[]
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.
bool
markById(int $id, bool $open = false)
Mark the children of the DataObject with the given ID.
$this
markToExpose(DataObject $childObj)
Expose the given object in the tree, by marking this page and all it ancestors.
array
markedNodeIDs()
Return the IDs of all the marked nodes.
clearMarks()
Reset marked nodes
$this
markExpanded(DataObject $node)
Mark this DataObject as expanded.
$this
markUnexpanded(DataObject $node)
Mark this DataObject as unexpanded.
$this
markOpened(DataObject $node)
Mark this DataObject's tree as opened.
$this
markClosed(DataObject $node)
Mark this DataObject's tree as closed.
bool
isMarked(DataObject $node)
Check if this DataObject is marked.
bool
isExpanded(DataObject $node)
Check if this DataObject is expanded.
An expanded object has had it's children iterated through.
bool
isTreeOpened(DataObject $node)
Check if this DataObject's tree is opened.
This is an expanded node which also should have children visually shown.
protected bool
isNodeLimited(DataObject $node, int $count = null)
Check if this node has too many children
$this
setLimitingEnabled(bool $enabled)
Toggle limiting on or off
bool
getLimitingEnabled()
Check if limiting is enabled