Attempts to find all children that match the rule
given.

@param array $nodes
@param array $rule
@param array $options
@return array
@recursive
767958
protected function seek(array $nodes, array $rule, array $options): array
    {
        // XPath index
        if (array_key_exists('tag', $rule) &&
            array_key_exists('key', $rule) &&
            is_numeric($rule['key'])
        ) {
            $count = 0;
            /** @var AbstractNode $node */
            foreach ($nodes as $node) {
                if ($rule['tag'] == '*' ||
                    $rule['tag'] == $node->getTag()->name()
                ) {
                    ++$count;
                    if ($count == $rule['key']) {
                        // found the node we wanted
                        return [$node];
                    }
                }
            }

            return [];
        }

        $options = $this->flattenOptions($options);

        $return = [];
        /** @var InnerNode $node */
        foreach ($nodes as $node) {
            // check if we are a leaf
            if ($node instanceof LeafNode ||
                ! $node->hasChildren()
            ) {
                continue;
            }

            $children = [];
            $child    = $node->firstChild();
            while ( ! is_null($child)) {
                // wild card, grab all
                if ($rule['tag'] == '*' && is_null($rule['key'])) {
                    $return[] = $child;
                    $child = $this->getNextChild($node, $child);
                    continue;
                }

                $pass = $this->checkTag($rule, $child);
                if ($pass && ! is_null($rule['key'])) {
                    $pass = $this->checkKey($rule, $child);
                }
                if ($pass && ! is_null($rule['key']) &&
                    ! is_null($rule['value']) && $rule['value'] != '*'
                ) {
                    $pass = $this->checkComparison($rule, $child);
                }

                if ($pass) {
                    // it passed all checks
                    $return[] = $child;
                } else {
                    // this child failed to be matched
                    if ($child instanceof InnerNode &&
                        $child->hasChildren()
                    ) {
                        // we still want to check its children
                        $children[] = $child;
                    }
                }

                $child = $this->getNextChild($node, $child);
            }

            if (( ! isset($options['checkGrandChildren']) ||
                    $options['checkGrandChildren'])
                && count($children) > 0
            ) {
                // we have children that failed but are not leaves.
                $matches = $this->seek($children, $rule, $options);
                foreach ($matches as $match) {
                    $return[] = $match;
                }
            }
        }

        return $return;
    }
113913
public function childCount($id, array $options = [])
	{
		$options['for'] = $id;

		$query = $this->findChildren($this->_table->find(), $options);

		return $query->count();
	}
1277322
public function applyRule($ruleName, $options = '')
    {
        $item = $this->items[$this->currentKey];
        $this->processRule($item, $ruleName, $options);

        return $this;
    }
1059029
public function processNode(Parser $parser, $variable, $data, array $options)
    {
        $this->processAction($parser, $variable, $data, $options);

        return null;
    }
768047
public function validateRule(Rule $rule, array $restrictions = array())
    {
        /** @var \Claroline\CoreBundle\Rule\Constraints\AbstractConstraint[] $usedConstraints */
        $usedConstraints = array();
        $existedConstraints = $this->getConstraints();

        foreach ($existedConstraints as $existedConstraint) {
            if ($existedConstraint->isApplicableTo($rule)) {
                $usedConstraints[] = $existedConstraint->setRule($rule);
            }
        }

        $validatedConstraints = 0;
        $nbConstraints = count($usedConstraints);

        $associatedLogs = $this->getAssociatedLogs($usedConstraints, $restrictions);

        foreach ($usedConstraints as $usedConstraint) {
            $usedConstraint->setAssociatedLogs($associatedLogs);

            if ($usedConstraint->validate()) {
                ++$validatedConstraints;
            }
        }

        return ($validatedConstraints === $nbConstraints) ? $associatedLogs : false;
    }
395796
private static function traverseTree(
        Criterion $node,
        array $children,
        $level
    ) {
        $type = 'n/a';
        $value = 'n/a';

        if ($node->getCaseValue() !== null) {
            $type =
                (new ReflectionClass($node->getCaseValue()))->getShortName();
            if ($node->getCaseValue() instanceof ProductCanonicalCondition) {
                $value = $node->getCaseValue()->getCondition();
            } elseif ($node->getCaseValue() instanceof
                ProductBiddingCategory) {
                $value = sprintf(
                    '%s (%s)',
                    $node->getCaseValue()->getType(),
                    $node->getCaseValue()->getValue()
                );
            } else {
                $value = $node->getCaseValue()->getValue();
            }
        }

        $result = sprintf(
            "%sID: %d, type: %s, value: %s\n",
            str_repeat("  ", $level),
            $node->getId(),
            $type,
            $value
        );
        foreach ($children[$node->getId()] as $childNode) {
            $result .= self::traverseTree($childNode, $children, $level + 1);
        }

        return $result;
    }
370942
public static Collection<ParserRuleContext> getAllDescendantNodes(final ParserRuleContext node, final RuleName ruleName) {
        Collection<ParserRuleContext> result = new LinkedList<>();
        if (isMatchedNode(node, ruleName)) {
            result.add(node);
        }
        for (ParserRuleContext each : getChildrenNodes(node)) {
            result.addAll(getAllDescendantNodes(each, ruleName));
        }
        return result;
    }
528987
public function validate(array $options = [])
    {
        $options = array_replace(
            [
                'validateMinChildren'               => true,
                'validateMaxChildren'               => true,
                'validateParentMandatory'           => true,
                'validateParentMustNotBeSet'        => true
            ],
            $options
        );

        $countChildren = $this->countChildren();

        if ($options['validateMinChildren']
            && ($min = $this->getValidationConfig('minChildren')) !== null
            && $min > $countChildren
        ) {
            throw ValidationException::create(
                'Children must be, at least, ' . $min . '. Currently, node "' . $this->getId() . '" has ' .
                $countChildren . ' children.'
            );
        }

        if ($options['validateMaxChildren']
            && ($max = $this->getValidationConfig('maxChildren')) !== null
            && $max < $countChildren
        ) {
            throw ValidationException::create(
                'Children cannot exceed a maximum of ' . $max . '. Currently, node "' . $this->getId() . '" has ' .
                $countChildren . ' children.'
            );
        }

        if ($options['validateParentMandatory']
            && $this->getValidationConfig('parentMandatory')
            && $this->getParent() === null
        ) {
            throw ValidationException::create(
                'Node "' . $this->getId() . '" must have a Parent!'
            );
        }

        if ($options['validateParentMustNotBeSet']
            && $this->getValidationConfig('parentMustNotBeSet')
            && $this->getParent() !== null
        ) {
            throw ValidationException::create(
                'Node "' . $this->getId() . '" must NOT have a Parent!'
            );
        }
    }
12151
protected function getChildren(NodeBuilder $node)
    {
        $node = $this->getOptionsNodes($node);
        $node = $this->getConnectionsNodes($node);
        $node = $this->getOverridesNodes($node);

        return $node;
    }
1222429
protected function optimizeNodes(ChildrenNodeCollection $nodes)
    {
        $optimizedNodes = [];

        foreach ($nodes->getChildren() as $key => $node) {
            $optimizedNodes[$key] = $this->optimizeNode($node);
        }

        $optimizedNodes = new ChildrenNodeCollection($optimizedNodes);

        $optimizedNodes = $this->moveCommonMatchersToParentNode($optimizedNodes);

        return $optimizedNodes;
    }
469356
public function match($node, $position, $items)
    {
        return $this->_isClassInList(
            $this->_className,
            $node->getAttribute("class")
        );
    }
483
public function addChild($child, array $options = array())
    {
        $child->setParent($this);

        $this->children[$child->getName()] = $child;

        return $child;
    }
447512
public function filterNodeDepth($nodes, $depth)
    {
        if(empty($nodes) || $depth === 0)
        {
            return array();
        }

        $newNodes = array();
        $stack = array();
        $level = 0;

        foreach($nodes as $node)
        {
            $parent = end($stack);
            while($parent && $node->getLeftValue() > $parent->getRightValue())
            {
                array_pop($stack);
                $parent = end($stack);
                $level--;
            }

            if($level < $depth)
            {
                $newNodes[] = $node;
            }

            if(($node->getRightValue() - $node->getLeftValue()) > 1)
            {
                array_push($stack, $node);
                $level++;
            }
        }

        return $newNodes;
    }
1246706
public function getChildren( $nodeName = NULL )
	{
		if( !$nodeName )
			return $this->children;
		$list	= array();
		for( $i=0; $i<count( $this->children ); $i++ )
			if( $this->children[$i]->getNodeName() == $nodeName )
				$list[]	= $this->children[$i];
		return $list;
	}
442213
function( node, options ) {
			var items,
				i;

			if(!node){
				return false;
			}

			// if browser based documemt get topmost node
			node = modules.domUtils.getTopMostNode( node );

			// returns all microformat roots
			items = this.findRootNodes( node, true );
			if(options && options.filters && modules.utils.isArray(options.filters)){
				i = items.length;
				while(i--) {
					if( this.isMicroformat( items[i], options ) ){
						return true;
					}
				}
				return false;
			}else{
				return (items.length > 0);
			}
		}
1060612
public function parseNodeChildren(\DOMNode $node, NodeInterface $target)
    {
        $rules = $this->getStandard()->getRules();
        foreach ($node->childNodes as $childNode) {
            /** @var RuleInterface $rule */
            foreach ($rules as $rule) {
                if ($rule->canHandle($childNode, $target)) {
                    $rule->handle($this, $childNode, $target);
                    break;
                }
            }
        }
    }
1341888
public function getNodesTree($nodes, $parentId)
    {
        return collect($nodes)->filter(function ($value) use ($parentId) {
            if (isset($value['parent_id'])) {
                if ($value['parent_id'] == $parentId) {
                    return true;
                }

                return false;
            }

            return true;
        })->mapWithKeys(function ($value, $key) use ($nodes) {
            $data = [
                'id'    => (string) $value['id'],
                'label' => $value['label'],
            ];

            if (isset($value['parent_id'])) {
                $children = $this->getNodesTree($nodes, $value['id']);
                if ($children->isNotEmpty()) {
                    $data['children'] = $children;
                }
            }

            return [
                $key => $data,
            ];
        })->values();
    }