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']);
ingo herwig

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 


$referenceNodeNode instance to which the other nodes are related
$nodeListArray of Node instances, which should be sorted in relation to the reference node
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 ( Node  $a,
Node  $b 

Compare function for sorting Nodes in the given relation.

$aFirst Node instance
$bFirst Node instance
-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()

getSortkeyValue ( Node  $node)

Get the sortkey value of a node in the given relation.


Definition at line 75 of file NodeSortkeyComparator.php.

static parse($oid)
Parse a serialized object id string into an ObjectId instance.
Definition: ObjectId.php:134