NodeSortkeyComparator Class Reference
Detailed Description
NodeSortkeyComparator is used to compare nodes by their sortkey in relation to a given node.
The following example shows the usage:
// sort all child nodes of a node by their sortkey
// regardless of the type
$node = $persistenceFacade->load(ObjectId::parse($oidStr), 1);
$children = $node->getChildren();
$comparator = new NodeSortkeyComparator($node, $children);
usort($children, [$comparator, 'compare']);
Definition at line 32 of file NodeSortkeyComparator.php.
Public Member Functions | |
__construct (Node $referenceNode, array $nodeList) | |
compare (Node $a, Node $b) | |
Protected Member Functions | |
getSortkeyValue (Node $node) | |
Constructor & Destructor Documentation
◆ __construct()
__construct | ( | Node | $referenceNode, |
array | $nodeList | ||
) |
Constructor.
- Parameters
-
$referenceNode Node instance to which the other nodes are related $nodeList Array of Node instances, which should be sorted in relation to the reference node
- Note
- If the role of a node to sort is not be defined, the comparator uses the first relation that has the type of the given node
Definition at line 45 of file NodeSortkeyComparator.php.
Member Function Documentation
◆ compare()
Compare function for sorting Nodes in the given relation.
- Returns
- -1, 0 or 1 whether a is less, equal or greater than b in respect of the criteria
Definition at line 63 of file NodeSortkeyComparator.php.
◆ getSortkeyValue()
|
protected |
Get the sortkey value of a node in the given relation.
- Parameters
-
$node Node
- Returns
- Number
Definition at line 75 of file NodeSortkeyComparator.php.
static parse($oid)
Parse a serialized object id string into an ObjectId instance.
Definition: ObjectId.php:135