/**
* Method to get nested set properties for a node in the tree.
*
* @param integer $id Value to look up the node by.
* @param string $key An optional key to look up the node by (parent | left | right).
* If omitted, the primary key of the table is used.
*
* @return mixed Boolean false on failure or node object on success.
*
* @since 1.7.0
* @throws \RuntimeException on database error.
*/
protected function _getNode($id, $key = null)
{
// Determine which key to get the node base on.
switch ($key) {
case 'parent':
$k = 'parent_id';
break;
case 'left':
$k = 'lft';
break;
case 'right':
$k = 'rgt';
break;
default:
$k = $this->_tbl_key;
break;
}
// Get the node data.
$query = $this->_db->getQuery(true)->select($this->_tbl_key . ', parent_id, level, lft, rgt')->from($this->_tbl)->where($k . ' = ' . (int) $id);
$query->setLimit(1);
$row = $this->_db->setQuery($query)->loadObject();
// Check for no $row returned
if (empty($row)) {
$e = new \UnexpectedValueException(sprintf('%s::_getNode(%d, %s) failed.', \get_class($this), $id, $k));
$this->setError($e);
return false;
}
// Do some simple calculations.
$row->numChildren = (int) ($row->rgt - $row->lft - 1) / 2;
$row->width = (int) $row->rgt - $row->lft + 1;
return $row;
}