Searches all children for the best matching active node
@return navigation_node|false
769506
public function search_for_active_node() {
        if ($this->check_if_active(URL_MATCH_BASE)) {
            return $this;
        } else {
            foreach ($this->children as &$child) {
                $outcome = $child->search_for_active_node();
                if ($outcome !== false) {
                    return $outcome;
                }
            }
        }
        return false;
    }
1360461
protected function navigation_node($items, $attrs=array(), $expansionlimit=null, array $options = array(), $depth=1) {
        // Exit if empty, we don't want an empty ul element.
        if (count($items) === 0) {
            return '';
        }

        // Turn our navigation items into list items.
        $lis = array();
        // Set the number to be static for unique id's.
        static $number = 0;
        foreach ($items as $item) {
            $number++;
            if (!$item->display && !$item->contains_active_node()) {
                continue;
            }

            $isexpandable = (empty($expansionlimit) || ($item->type > navigation_node::TYPE_ACTIVITY || $item->type < $expansionlimit) || ($item->contains_active_node() && $item->children->count() > 0));

            // Skip elements which have no content and no action - no point in showing them
            if (!$isexpandable && empty($item->action)) {
                continue;
            }

            $id = $item->id ? $item->id : html_writer::random_id();
            $content = $item->get_content();
            $title = $item->get_title();
            $ulattr = ['id' => $id . '_group', 'role' => 'group'];
            $liattr = ['class' => [$item->get_css_type(), 'depth_'.$depth]];
            $pattr = ['class' => ['tree_item'], 'role' => 'treeitem'];
            $pattr += !empty($item->id) ? ['id' => $item->id] : [];
            $isbranch = $isexpandable && ($item->children->count() > 0 || ($item->has_children() && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY)));
            $hasicon = ((!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY || $item->type == navigation_node::TYPE_RESOURCE) && $item->icon instanceof renderable);
            $icon = '';

            if ($hasicon) {
                $liattr['class'][] = 'item_with_icon';
                $pattr['class'][] = 'hasicon';
                $icon = $this->output->render($item->icon);
                // Because an icon is being used we're going to wrap the actual content in a span.
                // This will allow designers to create columns for the content, as we've done in styles.css.
                $content = $icon . html_writer::span($content, 'item-content-wrap');
            }
            if ($item->helpbutton !== null) {
                $content = trim($item->helpbutton).html_writer::tag('span', $content, array('class'=>'clearhelpbutton'));
            }
            if (empty($content)) {
                continue;
            }

            $nodetextid = 'label_' . $depth . '_' . $number;
            $attributes = array('tabindex' => '-1', 'id' => $nodetextid);
            if ($title !== '') {
                $attributes['title'] = $title;
            }
            if ($item->hidden) {
                $attributes['class'] = 'dimmed_text';
            }
            if (is_string($item->action) || empty($item->action) ||
                    (($item->type === navigation_node::TYPE_CATEGORY || $item->type === navigation_node::TYPE_MY_CATEGORY) &&
                    empty($options['linkcategories']))) {
                $content = html_writer::tag('span', $content, $attributes);
            } else if ($item->action instanceof action_link) {
                //TODO: to be replaced with something else
                $link = $item->action;
                $link->text = $icon.html_writer::span($link->text, 'item-content-wrap');
                $link->attributes = array_merge($link->attributes, $attributes);
                $content = $this->output->render($link);
            } else if ($item->action instanceof moodle_url) {
                $content = html_writer::link($item->action, $content, $attributes);
            }

            if ($isbranch) {
                $pattr['class'][] = 'branch';
                $liattr['class'][] = 'contains_branch';
                $pattr += ['aria-expanded' => ($item->has_children() && (!$item->forceopen || $item->collapse)) ? "false" : "true"];
                if ($item->requiresajaxloading) {
                    $pattr += [
                        'data-requires-ajax' => 'true',
                        'data-loaded' => 'false',
                        'data-node-id' => $item->id,
                        'data-node-key' => $item->key,
                        'data-node-type' => $item->type
                    ];
                } else {
                    $pattr += ['aria-owns' => $id . '_group'];
                }
            }

            if ($item->isactive === true) {
                $liattr['class'][] = 'current_branch';
            }
            if (!empty($item->classes) && count($item->classes)>0) {
                $pattr['class'] = array_merge($pattr['class'], $item->classes);
            }

            $liattr['class'] = join(' ', $liattr['class']);
            $pattr['class'] = join(' ', $pattr['class']);

            $pattr += $depth == 1 ? ['data-collapsible' => 'false'] : [];
            if (isset($pattr['aria-expanded']) && $pattr['aria-expanded'] === 'false') {
                $ulattr += ['aria-hidden' => 'true'];
            }

            // Create the structure.
            $content = html_writer::tag('p', $content, $pattr);
            if ($isexpandable) {
                $content .= $this->navigation_node($item->children, $ulattr, $expansionlimit, $options, $depth + 1);
            }
            if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
                $content = html_writer::empty_tag('hr') . $content;
            }

            $liattr['aria-labelledby'] = $nodetextid;
            $content = html_writer::tag('li', $content, $liattr);
            $lis[] = $content;
        }

        if (count($lis) === 0) {
            // There is still a chance, despite having items, that nothing had content and no list items were created.
            return '';
        }

        // We used to separate using new lines, however we don't do that now, instead we'll save a few chars.
        // The source is complex already anyway.
        return html_writer::tag('ul', implode('', $lis), $attrs);
    }
1327216
protected static function activeNodes(Request $request, array $nodes = [], $level = 0) {

        $result = false;

        foreach ($nodes as $n) {

            if (false === ($n instanceof AbstractNavigationNode)) {
                continue;
            }

            if (true === self::nodeMatch($n, $request)) {
                $current = true;
            } else {
                $current = self::activeNodes($request, $n->getNodes(), $level + 1);
            }

            if (false === $current) {
                continue;
            }

            $n->setActive(true);

            $result = true;
        }

        return $result;
    }
503944
public function getChildrenByStatus(
        $node = null,
        $direct = false,
        $sortByField = null,
        $direction = 'ASC',
        $includeNode = false,
        $viewStatus = Page::STATUS_PUBLISHED
    ) {
        $qb = $this->childrenQueryBuilder($node, $direct, $sortByField, $direction, $includeNode);
        $aliases = $qb->getRootAliases();
        if ($viewStatus == Page::STATUS_PUBLISHED) {
            $orx = $qb->expr()->orX();
            $conditionA = $qb->expr()->in('ps.id', $this->getLatestSnapshotIds());
            $conditionB = $qb->expr()->isNull('ps.id');
            $orx->addMultiple([$conditionA, $conditionB]);
            $qb->addSelect('ps.id AS ps_id')
                ->addSelect('ps.versionedData AS ps_versionedData')
                ->leftJoin(PageSnapshot::class,
                    'ps',
                    Expr\Join::WITH,
                    sprintf('%s.page = ps.page ', $aliases[0])
                )
                ->andWhere($orx)
                ->leftJoin('ps.contentRoute', 'cr');
        } else {
            $qb->leftJoin(sprintf('%s.page', $aliases[0]), 'p')
                ->leftJoin('p.contentRoute', 'cr')
                ->addSelect('p');
        }
        $qb->addSelect('cr.path AS path');
        $results = $qb->getQuery()->getResult();

        $menuItems = [];
        foreach ($results as $item) {
            $menuItem = $item[0];
            if ($menuItem->getPage()) {
                if ($viewStatus == Page::STATUS_PUBLISHED) {
                    if (!$item['path'] || !$item['ps_id']) {
                        continue;
                    } else {
                        if (!$this->pageHelper->jsonPageIsActive($item['ps_versionedData'])) {
                            continue;
                        }
                        $menuItem->setPath($item['path']);
                    }
                } else {
                    if (!$item['path']) {
                        continue;
                    } else {
                        $menuItem->setPath($item['path']);
                    }
                }
            }
            $menuItems[] = $menuItem;
        }

        return $menuItems;
    }
508301
public function search()
    {
        $query = static::find()->where(['and',
            ['is not', 'post_id', null],
            ['like', 'word', $this->query]
        ])->joinWith(['posts.author', 'posts.thread']);
        if (Podium::getInstance()->user->isGuest) {
            $query->joinWith(['posts.forum' => function($q) {
                $q->where([Forum::tableName() . '.visible' => 1]);
            }]);
        }
        $query->groupBy(['post_id', 'word_id']);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => ['thread_id' => SORT_DESC],
                'attributes' => [
                    'thread_id' => [
                        'asc' => ['thread_id' => SORT_ASC],
                        'desc' => ['thread_id' => SORT_DESC],
                        'default' => SORT_DESC,
                    ],
                ]
            ],
        ]);

        return $dataProvider;
    }
532335
protected function findCurrentPage()
    {
        $url = $this->getCurrentUrl();
        $sections = $this->getCurrentUrlSections();

        // laravel removes last / get home / dashboard
        if ($url === false) {
            $page = Page::where('slug', '/')->get()->first();
        }
        else {
            // find nav with url - get last (parent can have same url)
            $page = Page::where('url', $url)
                ->orderBy('is_hidden', 'DESC')
                ->orderBy('url_parent_id')
                ->orderBy('header_order')
                ->get()
                ->last();
        }

        // we assume some params / reserved word is at the end
        if (!$page && strlen($url) > 2) {
            // keep cutting off from url until we find him in the db
            foreach ($sections as $key => $slug) {
                $url = substr($url, 0, strripos($url, '/'));

                // find nav with url - get last (parent can have same url)
                $page = Page::whereUrl($url)->get()->last();
                if ($page) {
                    break;
                }
            }
        }

        // when nothing - fall back to home
        if (!$page) {
            $page = Page::find(1);
            if (config('app.env') == 'local' && !$page) {
                dd('Whoops. Page not found - please see if url is in the pages table');
            }
        }

        // set the selected navigation
        $this->page = $page;

        // get all navigations -> ON parent_id
        $this->parentPages = $page->getParentsAndYou();

        // get all navigations -> ON url_parent_id
        $this->urlParentPages = $page->getUrlParentsAndYou();

        $this->page->increment('views');

        return $this->page;
    }
405370
private function findActivePageTiers()
    {
        // if selected page has a parent
        // find all pages with same parent id
        // if more than 1 - valid
        // if less than 1 - return 'about us'

        $name = 'About Us';
        $items = collect();
        if ($this->page->parent_id > 0) {
            $rows = Page::where('parent_id', $this->page->parent_id)
                ->orderBy('header_order')
                ->get();

            if ($items->count() > 1) {
                $items = $rows;
                $name = $this->page->parent->name;
            }
        }

        return (object) [
            'name'  => $name,
            'items' => $items,
        ];
    }
712642
public function getChildEdges()
    {
        $edges        = [];
        $hasChildren = false;

        foreach ($this->fields as $v) {
            if ($v instanceof GraphEdge) {
                $hasChildren = true;

                $children = $v->getChildEdges();
                foreach ($children as $childEdges) {
                    $edges[] = array_merge([$this->name], $childEdges);
                }
            }
        }

        // Means this is the final node (no further sub edges)
        if (!$hasChildren) {
            $edges[] = [$this->name];
        }

        return $edges;
    }
897883
public function getActiveCategory()
    {
        if ($this->_oActCategory === null) {
            $this->_oActCategory = false;
            if (($this->_getVendorId() && $oVendorTree = $this->getVendorTree())) {
                if ($oVendor = $this->getActVendor()) {
                    $this->_oActCategory = $oVendor;
                }
            }
        }

        return $this->_oActCategory;
    }
1102743
public function getNavigation()
    {
        if (self::$_oNaviTree == null) {
            self::$_oNaviTree = oxNew(\OxidEsales\Eshop\Application\Controller\Admin\NavigationTree::class);
        }

        return self::$_oNaviTree;
    }
1115178
public function isactive() {
        global $PAGE;

        if ($this->is_section()) {
            $active = $PAGE->navigation->find_active_node();
            while ($active = $active->parent) {
                if ($active->key == $this->key && $active->type == $this->type) {
                    return true;
                }
            }
        }
        return $this->isactive;
    }
130429
protected function scan_for_active_node(navigation_node $node) {
        if (!$node->check_if_active() && $node->children->count()>0) {
            foreach ($node->children as &$child) {
                $this->scan_for_active_node($child);
            }
        }
    }
507974
public function has_siblings() {
        if (empty($this->parent) || empty($this->parent->children)) {
            return false;
        }
        if ($this->parent->children instanceof navigation_node_collection) {
            $count = $this->parent->children->count();
        } else {
            $count = count($this->parent->children);
        }
        return ($count > 1);
    }
1268698
public static function GetActiveRootCategory()
    {
        static $oActiveRootCategory = 'x';
        if ('x' === $oActiveRootCategory) {
            $oActiveRootCategory = null;
            $oActiveCategory = self::getShopService()->GetActiveCategory();
            if (null !== $oActiveCategory) {
                $oActiveRootCategory = $oActiveCategory->GetRootCategory();
            }
        }

        return $oActiveRootCategory;
    }
9371
public function findActiveItem()
    {
        foreach ($this->items as $index => $item) {
            $index++;

            if ($item->number == $this->currentPage) {
                $item->active = true;
            }
        }
    }
235446
public function activeChild()
    {
        $uri = Grav::instance()['uri'];
        $pages = Grav::instance()['pages'];
        $uri_path = rtrim(urldecode($uri->path()), '/');
        $routes = Grav::instance()['pages']->routes();

        if (isset($routes[$uri_path])) {
            /** @var PageInterface $child_page */
            $child_page = $pages->dispatch($uri->route())->parent();
            if ($child_page) {
                while (!$child_page->root()) {
                    if ($this->path() === $child_page->path()) {
                        return true;
                    }
                    $child_page = $child_page->parent();
                }
            }
        }

        return false;
    }
572091
protected function setSelectedNavigation()
    {
        $url = $this->getCurrentUrl();
        $sections = $this->getCurrentUrlSections();

        // laravel removes last /
        if ($url === false) {
            // dahboard (substring from the /, laravel removes last /)
            $nav = NavigationAdmin::whereSlug('/')->get()->last();
        }
        else {
            // find nav with url - get last (parent can have same url)
            $nav = NavigationAdmin::where('url', '=', $url)
                ->orderBy('is_hidden', 'DESC')//->orderBy('url_parent_id')
                ->orderBy('list_order')
                ->get()
                ->last();
        }

        // we assume some params / reserved word is at the end
        if (!$nav && strlen($url) > 2) {
            // keep cutting off from url until we find him in the db
            foreach ($sections as $key => $slug) {
                $url = substr($url, 0, strripos($url, '/'));

                // find nav with url - get last (parent can have same url)
                $nav = NavigationAdmin::whereUrl($url)->get()->last();
                if ($nav) {
                    break;
                }
            }
        }

        // development testing
        if (config('app.env') == 'local' && !$nav) {
            //$nav = NavigationAdmin::find(1);
            dump($url);
            dd('Whoops. Navigation not found - please see if url is in database (navigation_admin)');
            //return false;
        }

        $this->selectedNavigation = $nav;

        // get all navigations -> ON parent_id
        $this->parentNavs = $nav->getParentsAndYou();

        // get all navigations -> ON url_parent_id
        $this->urlParentNavs = $nav->getUrlParentsAndYou();

        // name of resource - used on page to, eg, Add new 'resource', enter title of 'resource'
        $this->resource = str_singular($nav->title); // TODO: - maybe add a 'resource' field on the table

        $mode = $this->checkIfReservedWordInUrl();

        $this->selectedNavigation->mode = $mode == false ? 'index' : $mode;

        return $this->selectedNavigation;
    }