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, array($comparator, 'compare'));
Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

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 ( Node  $referenceNode,
array  $nodeList 
)

Constructor.

Parameters
$referenceNodeNode instance to which the other nodes are related
$nodeListArray 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 ( Node  $a,
Node  $b 
)

Compare function for sorting Nodes in the given relation.

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

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

Parameters
$nodeNode
Returns
Number

Definition at line 75 of file NodeSortkeyComparator.php.