/**
* Method to determine if a node is a leaf node in the tree (has no children).
*
* @param integer $pk Primary key of the node to check.
*
* @return boolean True if a leaf node, false if not or null if the node does not exist.
*
* @note Since 3.0.0 this method returns null if the node does not exist.
* @since 1.7.0
* @throws \RuntimeException on database error.
*/
public function isLeaf($pk = null)
{
$k = $this->_tbl_key;
$pk = \is_null($pk) ? $this->{$k} : $pk;
$node = $this->_getNode($pk);
// Get the node by primary key.
if (empty($node)) {
// Error message set in getNode method.
return;
}
// The node is a leaf node.
return $node->rgt - $node->lft == 1;
}