Back to Nested class

Method isLeaf

public bool
isLeaf
(mixed $pk = null)
Method to determine if a node is a leaf node in the tree (has no children).
Parameters
  • int $pk Primary key of the node to check.
Returns
  • bool True if a leaf node, false if not or null if the node does not exist.
Since
  • 1.7.0
-
  • Since 3.0.0 this method returns null if the node does not exist.
  • \RuntimeException on database error.
Class: Nested
Project: Joomla

Method isLeaf - Source code

/**
 * 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;
}