Shuffle the elements related to $shufflables components within a given $node.

@param \DOMNode $node The DOM Node where corresponding $shufflables must be shuffled.
@param \qtism\data\ShufflableCollection $shufflables A collection of Shufflable objects.
190599
static public function shuffle(DOMNode $node, ShufflableCollection $shufflables)
    {
        $shufflableIndexes = array();
        $elements = array();

        // 1. Detect what are the components that must
        // be shuffles within the fragment ($shufflableIndexes).
        //
        // 2. Store the related DOMElements into a
        // more suitable way ($elements).

        foreach ($shufflables as $k => $s) {
            $i = 0;

            while ($i < $node->childNodes->length) {
                $n = $node->childNodes->item($i);
                $i++;
                if ($n->nodeType === XML_ELEMENT_NODE && self::hasClass($n, 'qti-' . $s->getQtiClassName()) === true && !in_array($n, $elements, true)) {
                    $elements[] = $n;

                    if ($s->isFixed() === false) {
                        $shufflableIndexes[] = $k;
                    }

                    break;
                }
            }
        }

        // Swap two elements together N times where N is the number of shufflable components.
        $count = count($shufflableIndexes);
        $max = $count - 1;
        for ($i = 0; $i < $count; $i++) {
            $r1 = mt_rand(0, $max);
            $r2 = mt_rand(0, $max);

            if ($r1 !== $r2) {
                // Do only if swapping is 'useful'...
                $placeholder1 = $node->ownerDocument->createElement('placeholder1');
                $placeholder2 = $node->ownerDocument->createElement('placeholder2');
                
                $statements1 = self::extractStatements($elements[$shufflableIndexes[$r1]]);
                $statements2 = self::extractStatements($elements[$shufflableIndexes[$r2]]);
                
                $node->replaceChild($placeholder1, $elements[$shufflableIndexes[$r1]]);
                $node->replaceChild($placeholder2, $elements[$shufflableIndexes[$r2]]);

                $placeholder1 = $node->replaceChild($elements[$shufflableIndexes[$r2]], $placeholder1);
                $placeholder2 = $node->replaceChild($elements[$shufflableIndexes[$r1]], $placeholder2);
                
                if (empty($statements1) === false && empty($statements2) === false) {
                    for ($i = 0; $i < 2; $i++) {
                        $node->removeChild($statements1[$i]);
                        $node->replaceChild($statements1[$i], $statements2[$i]);
                    }
                    
                    $node->insertBefore($statements2[0], $elements[$shufflableIndexes[$r2]]);
                    $elements[$shufflableIndexes[$r2]]->parentNode->insertBefore($statements2[1], $elements[$shufflableIndexes[$r2]]->nextSibling);
                } else if (empty($statements1) === false && empty($statements2) === true) {
                    $node->removeChild($statements1[0]);
                    $node->removeChild($statements1[1]);
                    
                    $node->insertBefore($statements1[0], $elements[$shufflableIndexes[$r1]]);
                    $elements[$shufflableIndexes[$r1]]->parentNode->insertBefore($statements1[1], $elements[$shufflableIndexes[$r1]]->nextSibling);
                } else if (empty($statements2) === false && empty($statements1) === true) {
                    $node->removeChild($statements2[0]);
                    $node->removeChild($statements2[1]);
                    
                    $node->insertBefore($statements2[0], $elements[$shufflableIndexes[$r2]]);
                    $elements[$shufflableIndexes[$r2]]->parentNode->insertBefore($statements2[1], $elements[$shufflableIndexes[$r2]]->nextSibling);
                }

                unset($placeholder1);
                unset($placeholder2);
            }
        }
    }
603965
public function addChildAsLast(Node $node)
    {
        if(null === $this->children)
        {
            $this->children = array();
        }

        $this->children[] = $node;
    }
944763
function(node) { 
        var p = node.parent;

        // Update the parent's collection of children
        var a = [];

        for (var i=0, len=p.children.length;i<len;++i) {
            if (p.children[i] != node) {
                a[a.length] = p.children[i];
            }
        }

        p.children = a;

        // reset the childrenRendered flag for the parent
        p.childrenRendered = false;

         // Update the sibling relationship
        if (node.previousSibling) {
            node.previousSibling.nextSibling = node.nextSibling;
        }

        if (node.nextSibling) {
            node.nextSibling.previousSibling = node.previousSibling;
        }

		if (this.currentFocus == node) {
			this.currentFocus = null;
		}
		if (this._currentlyHighlighted == node) {
			this._currentlyHighlighted = null;
		}

        node.parent = null;
        node.previousSibling = null;
        node.nextSibling = null;
        node.tree = null;

        // Update the tree's node collection 
        delete this._nodes[node.index];
    }
924065
public function getSiblings(Node $node, $includeHiddenFromNav = true)
    {
        $this->init();
        $siblings = array();

        if (false !== $parent = $this->getParent($node)) {
            $siblings = $this->getChildren($parent, $includeHiddenFromNav);

            foreach ($siblings as $index => $child) {
                if ($child === $node) {
                    unset($siblings[$index]);
                }
            }
        }

        return $siblings;
    }
1142343
protected static function getNextElement(\DOMNode $node)
    {
        while ($node && ($node = $node->nextSibling)) {
            if ($node instanceof \DOMElement) {
                break;
            }
        }

        return $node;
    }
991903
public function addNodeList(\DOMNodeList $nodes)
    {
        foreach ($nodes as $node) {
            if ($node instanceof \DOMNode) {
                $this->addNode($node);
            }
        }
    }
903994
protected function collateNamespaces(\DOMNode $node)
    {
        if ($this->config['useNamespaces'] && $node->namespaceURI 
            && ! array_key_exists($node->namespaceURI, $this->namespaces)) {
            $this->namespaces[$node->namespaceURI] = $node->lookupPrefix($node->namespaceURI);
        }
    }
945632
private function addSerializerFormats(ArrayNodeDefinition $node)
    {
        // NEXT_MAJOR : do not execute this if jms/serializer is missing
        $node
            ->children()
                ->arrayNode('serializer')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('formats')
                            ->prototype('scalar')->end()
                            ->defaultValue(['json', 'xml', 'yml'])
                            ->info('Default serializer formats, will be used while getting subscribing methods.')
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;
    }
554849
public function theJsonNodeShouldBeNull($node)
    {
        $actual = $this->getJsonNodeValue($node);
        PHPUnit::assertNull($actual, sprintf('The node value is `%s`', json_encode($actual)));
    }
662846
public function add_class( \DOMElement &$node, $classes){
		$classes = (array)$classes;
		if( $node->hasAttribute('class') ){
			$classes = array_merge($classes, explode(' ', $node->getAttribute('classs')));
		}
		$node->setAttribute('class', implode(' ', $classes));
	}
1115002
public function registerNodeChange(NodeInterface $node)
    {
        if (in_array($node->getIdentifier(), $this->tagsToFlush)) {
            return;
        }
        if (!$node->getNodeType()->isOfType('Neos.Neos:Document')) {
            return;
        }
        $this->tagsToFlush[] = $node->getIdentifier();
    }
1101500
public function assignFilteredChildNodes(NodeInterface $node, array $matchedNodes, $outputStyle = self::STYLE_LIST)
    {
        $this->outputStyle = $outputStyle;
        $nodes = $this->collectParentNodeData($node, $matchedNodes);
        $this->setConfiguration(['value' => ['data' => ['_descendAll' => []]]]);

        $this->assign('value', ['data' => $nodes, 'success' => true]);
    }
477869
public function rebaseDiff(Node $node)
    {
        $changes = array_merge(
            $node->getDiffAdditions(),
            $node->getDiffDeletions(),
            $node->getDiffReplacements()
        );
        if (count($changes) > 0) {
            throw new RebaseException(
                sprintf(
                    '%s has some uncommitted changes - Cannot rebase %s on %s',
                    $node->getDn(),
                    $this->getDn(),
                    $node->getDn()
                )
            );
        }
        $additions = $this->getDiffAdditions();
        $deletions = $this->getDiffDeletions();
        $replacements = $this->getDiffReplacements();
        $this->snapshot();
        $this->attributes = $node->getAttributes();
        foreach ($additions as $attribute => $values) {
            $this->get($attribute, true)->add($values);
        }
        foreach ($deletions as $attribute => $values) {
            if (count($values) == 0) {
                $this->removeAttribute($attribute);
            } else {
                if ($this->has($attribute)) {
                    $this->get($attribute)->remove($values);
                }
            }
        }
        foreach ($replacements as $attribute => $values) {
            $this->get($attribute, true)->set($values);
        }
    }
40267
public function replaceWith($nodes) {
    $first = TRUE;
    foreach ($this->nodes as $node) {
      if (!$first) {
        if (is_array($nodes)) {
          $nodes = new NodeCollection($nodes, FALSE);
        }
        $nodes = clone $nodes;
      }
      $node->replaceWith($nodes);
      $first = FALSE;
    }
    return $this;
  }
1189217
private function copyInlineableCssToStyleAttribute(\DOMElement $node, array $cssRule)
    {
        // if it has a style attribute, get it, process it, and append (overwrite) new stuff
        if ($node->hasAttribute('style')) {
            // break it up into an associative array
            $oldStyleDeclarations = $this->parseCssDeclarationsBlock($node->getAttribute('style'));
        } else {
            $oldStyleDeclarations = [];
        }
        $newStyleDeclarations = $this->parseCssDeclarationsBlock($cssRule['declarationsBlock']);
        $node->setAttribute(
            'style',
            $this->generateStyleStringFromDeclarationsArrays($oldStyleDeclarations, $newStyleDeclarations)
        );
    }
231507
protected function flipColors(RedBlackNode $node): void
    {
        $node->setColor(!($node->color()));
        $node->left()->setColor(!($node->left()->color()));
        $node->right()->setColor(!($node->right()->color()));
    }
1211401
public function addNode(Node $node)
    {
        foreach ($this->nodes as $n) {
            if ($n->getIdentifier() === $node->getIdentifier()) {
                throw new SchemaDefinitionException(sprintf('The node with Identifier "%s" has already been declared', $node->getIdentifier()));
            }
        }

        return $this->nodes->add($node);
    }