public function getSibling($dir, $loop = true) { if ($dir == 'next') { $filter = Ajde_Filter::FILTER_GREATER; $order = Ajde_Query::ORDER_ASC; } else { $filter = Ajde_Filter::FILTER_LESS; $order = Ajde_Query::ORDER_DESC; } if ($this->has('parent')) { $siblings = new NodeCollection(); $siblings->addFilter(new Ajde_Filter_Where('sort', $filter, $this->sort)); $siblings->addFilter(new Ajde_Filter_Where('parent', Ajde_Filter::FILTER_EQUALS, (string) $this->get('parent'))); $siblings->orderBy('sort', $order); $siblings->limit(1); if ($siblings->count()) { return $siblings->current(); } } // Not found, loop? if ($loop === true) { $siblings->reset(); $siblings->addFilter(new Ajde_Filter_Where('parent', Ajde_Filter::FILTER_EQUALS, (string) $this->get('parent'))); $siblings->orderBy('sort', $order); $siblings->limit(1); if ($siblings->count()) { return $siblings->current(); } } // No sibling return false; }
/** * Returns true/false as to whether this node * has any child nodes or not. * * @return bool Any child nodes or not */ public function hasChildren() { return $this->nodes->count() > 0; }