Removes any empty group children from a tree structure, returning
the number of non-group entries.

@param MenuPresenceInterface $presence
@return int  the number of non-group children found on the levels below
173181
protected function filterNestedEmptyGroups(MenuPresenceInterface $presence)
    {
        if ($presence->type() !== MenuPresenceType::GROUP) {
            return 1;
        }

        $children = $presence->children();

        if ( ! $children || ! count($children)) {
            return 0;
        }

        $remove        = [];
        $nonGroupCount = 0;

        foreach ($children as $key => $childPresence) {

            if ( ! $this->filterNestedEmptyGroups($childPresence)) {
                $remove[] = $key;
                continue;
            }

            $nonGroupCount++;
        }

        foreach ($remove as $key) {
            unset($children[$key]);
        }

        $presence->setChildren($children);

        return $nonGroupCount;
    }
381243
public function removeChild(Location $location): void
    {
        if (!$this->hasChild($location)) {
            throw new InvalidArgumentException(
                'The Location is not a child and cannot be removed from there');
        }
        $location->setParent(null);
        $this->getChildren()->removeElement($location);
    }
1303832
public function countChildren( $nsPrefix = NULL )
	{
		$i = 0;
		foreach( $this->children( $nsPrefix, TRUE ) as $node )
			$i++;
		return $i;
	}
1219019
public function getNumChildrenDirect()
    {
        // direct children only
        $db = Database::connection();
        $v = [$this->cID];
        $num = $db->fetchColumn('select count(cID) as total from Pages where cParentID = ?', $v);
        if ($num) {
            return $num;
        }

        return 0;
    }
962118
public function count()
    {
        $count = 1;
        foreach ($this->children as $child) {
            $count += count($child);
        }

        return $count;
    }
522535
protected function objectCount()
    {
        $topNodeArray = eZPersistentObject::fetchObjectList(
            eZContentObjectTreeNode::definition(),
            null,
            array( 'parent_node_id' => 1, 'depth' => 1 )
        );
        $subTreeCount = 0;
        foreach ( array_keys ( $topNodeArray ) as $key  )
        {
            $subTreeCount += $topNodeArray[$key]->subTreeCount( array( 'Limitation' => array(), 'MainNodeOnly' => true ) );
        }

        return $subTreeCount;
    }
1319155
protected function transformPresencesForApi($presences)
    {
        $response = [];

        foreach ($presences as $presence) {
            $response[] = $this->transformPresenceForApi($presence);
        }

        return $response;
    }
944965
public function countParts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collPartsPartial && !$this->isNew();
        if (null === $this->collParts || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collParts) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getParts());
            }

            $query = ChildSkillPartQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySkillRelatedByPartId($this)
                ->count($con);
        }

        return count($this->collParts);
    }
1004546
public function countChildren(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collChildrenPartial && !$this->isNew();
        if (null === $this->collChildren || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collChildren) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getChildren());
            }

            $query = ChildSkillDependencyQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySkillRelatedByDependencyId($this)
                ->count($con);
        }

        return count($this->collChildren);
    }
522537
public static function countMinDepth($potentialArray, $depth = 0)
    {
        // validation, must be positive int or 0
        if (!self::isLogicallyCastableToInt($depth)) {
            throw new InvalidArgumentException('Depth parameter must be non-negative integer');
        }
        if ($depth < 0) {
            throw new InvalidArgumentException('Depth parameter must be non-negative integer');
        }

        $return = $depth;
        if (is_array($potentialArray)) {
            $return++;
            $childrenDepths = array();
            foreach ($potentialArray as $element) {
                $childrenDepths[] = self::countMinDepth($element, $return);
            }
            $return = empty($childrenDepths) ? $return : min($childrenDepths);
        }

        return $return;
    }
775096
public function sendPresence(\sb\XMPP\Presence $presence)
    {

        $presence->setFrom($this->jid);
        return $this->write($presence);
    }
1170150
public function remove_child(custom_menu_item $menuitem) {
        $removed = false;
        if (($key = array_search($menuitem, $this->children)) !== false) {
            unset($this->children[$key]);
            $this->children = array_values($this->children);
            $removed = true;
        } else {
            foreach ($this->children as $child) {
                if ($removed = $child->remove_child($menuitem)) {
                    break;
                }
            }
        }
        return $removed;
    }
886992
public function getSumChildCount(): int
    {
        $count = count($this->children);

        foreach ($this->children as $node) {
            $count += $node->getChildCount();
        }

        return $count;
    }
1363670
public function child_count() {

		$count = 0;
		if ( ! empty( $this->child ) ) {
			foreach ( $this->child as $child ) {
				if ( $this->is_section_object( $child ) ) {
					$count ++;
				}
			}
		}

		return $count;
	}
434387
final public function accessLevel(Tree $tree, string $interface): int
    {
        $access_levels = app('cache.array')
            ->rememberForever('module_privacy' . $tree->id(), static function () use ($tree): Collection {
                return DB::table('module_privacy')
                    ->where('gedcom_id', '=', $tree->id())
                    ->get();
            });

        $row = $access_levels->first(function (stdClass $row) use ($interface): bool {
            return $row->interface === $interface && $row->module_name === $this->name();
        });

        return $row ? (int) $row->access_level : $this->access_level;
    }
1058379
public function removeChild(int $id): InnerNode
    {
        if ( ! isset($this->children[$id])) {
            return $this;
        }

        // handle moving next and previous assignments.
        $next = $this->children[$id]['next'];
        $prev = $this->children[$id]['prev'];
        if ( ! is_null($next)) {
            $this->children[$next]['prev'] = $prev;
        }
        if ( ! is_null($prev)) {
            $this->children[$prev]['next'] = $next;
        }

        // remove the child
        unset($this->children[$id]);

        //clear any cache
        $this->clear();

        return $this;
    }
434569
protected function getAllChildrenCount(Location $location): int
    {
        $query = new LocationQuery([
            'filter' => new Criterion\Subtree($location->pathString),
        ]);

        $searchResults = $this->searchService->findLocations($query);

        return $searchResults->totalCount;
    }