Process item reference elements

@param \DOMElement[] $itemrefElements Item reference DOM elements
@param ContextInterface $context Context
@param ThingInterface $thing Thing
@return void
359279
protected function processItemReferenceElements(
        array $itemrefElements,
        ContextInterface $context,
        ThingInterface $thing
    ) {
        $iterator = new DOMIterator(
            $itemrefElements,
            $context->setParentThing($thing),
            new MicrodataElementProcessor()
        );

        // Iterate through all $node
        foreach ($iterator->getRecursiveIterator() as $node) {
            $node || true;
        }
    }
540839
public function setItems(iterable $items): void
    {
        if ($items instanceof ItemList) {
            $this->items = clone $items;
        } else {
            $this->items = new ItemList();
            foreach ($items as $item) {
                $this->items->insert($item);
            }
        }
    }
1145819
@Override
    public Item process(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException {
        for (String xpathQuery : metaDataNodesXPathQueries) {
            List<String> metaDataValues = item.queryDescriptorValues(xpathQuery);
            if (CollectionUtils.isNotEmpty(metaDataValues)) {
                item.setProperty(xpathQuery, metaDataValues);
            }
        }

        return item;
    }
77695
protected function mapModelDataToElement(ElementInterface $child)
    {
        $this->setDefaultElementValue($child);
        
        $children = $child->getChildren();
        
        if ($children->count()) {
            $this->mapModelDataToElementCollection($children);
        }
    }
431365
protected function buildResponseProcessing(DOMElement $data, Item $item){
        $returnValue = null;

        // try template
        try{
            $returnValue = $this->buildTemplateResponseProcessing($data);

            try{
                //warning: require to add interactions to the item to make it work
                $returnValue = TemplatesDriven::takeOverFrom($returnValue, $item);
            }catch(TakeoverFailedException $e){}
        }catch(UnexpectedResponseProcessing $e){

        }

        //try templatedriven
        if(is_null($returnValue)){
            try{
                $returnValue = $this->buildTemplatedrivenResponse($data, $item->getInteractions());
            }catch(UnexpectedResponseProcessing $e){}
        }

        // build custom
        if(is_null($returnValue)){
            try{
                $returnValue = $this->buildCustomResponseProcessing($data);
            }catch(UnexpectedResponseProcessing $e){
                // not a Template
                common_Logger::e('custom response processing failed', array('TAOITEMS', 'QTI'));
            }
        }

        if(is_null($returnValue)){
            common_Logger::w('failed to determine ResponseProcessing');
        }

        return $returnValue;
    }
303982
private function _renderItemsTogether ($actualGroupName = '', $items = [], $indent = 0, $minify = FALSE) {
		// some configurations is not possible to render together and minimized
		list($itemsToRenderMinimized, $itemsToRenderSeparately) = $this->filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems($items);

		$indentStr = $this->getIndentString($indent);
		$resultItems = [];
		if (self::$fileRendering) $resultItems[] = '<!-- css group begin: ' . $actualGroupName . ' -->';

		// process array with groups, which are not possible to minimize
		foreach ($itemsToRenderSeparately as & $itemsToRender) {
			$resultItems[] = $this->_renderItemsTogetherAsGroup($itemsToRender, $minify);
		}

		// process array with groups to minimize
		foreach ($itemsToRenderMinimized as & $itemsToRender) {
			$resultItems[] = $this->_renderItemsTogetherAsGroup($itemsToRender, $minify);
		}

		if (self::$fileRendering) $resultItems[] = '<!-- css group end: ' . $actualGroupName . ' -->';

		return $indentStr . implode(PHP_EOL . $indentStr, $resultItems);
	}
516145
protected function buildCompositeResponseProcessing(DOMElement $data, Item $item){
        $returnValue = null;

        // STRONGLY simplified summation detection
        $patternCorrectTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]';
        $patternMapTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponse"]';
        $patternMapPointTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponsePoint"]';
        $patternNoneTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "isNull" ] [count(./responseIf/isNull/*) = 1 ] [name(./responseIf/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]';
        $possibleSummation = '/setOutcomeValue [count(./*) = 1 ] [name(./*[1]) = "sum" ]';

        $irps = array();
        $composition = null;
        $data = simplexml_import_dom($data);
        foreach($data as $responseRule){

            if(!is_null($composition)){
                throw new UnexpectedResponseProcessing('Not composite, rules after composition');
            }

            $subtree = new SimpleXMLElement($responseRule->asXML());

            if(count($subtree->xpath($patternCorrectTAO)) > 0){
                $responseIdentifier = (string) $subtree->responseIf->match->variable[0]['identifier'];
                $irps[$responseIdentifier] = array(
                    'class' => 'MatchCorrectTemplate',
                    'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
                );
            }elseif(count($subtree->xpath($patternMapTAO)) > 0){
                $responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier'];
                $irps[$responseIdentifier] = array(
                    'class' => 'MapResponseTemplate',
                    'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
                );
            }elseif(count($subtree->xpath($patternMapPointTAO)) > 0){
                $responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier'];
                $irps[$responseIdentifier] = array(
                    'class' => 'MapResponsePointTemplate',
                    'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
                );
            }elseif(count($subtree->xpath($patternNoneTAO)) > 0){
                $responseIdentifier = (string) $subtree->responseIf->isNull->variable[0]['identifier'];
                $irps[$responseIdentifier] = array(
                    'class' => 'None',
                    'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier'],
                    'default' => (string) $subtree->responseIf->setOutcomeValue[0]->baseValue[0]
                );
            }elseif(count($subtree->xpath($possibleSummation)) > 0){
                $composition = 'Summation';
                $outcomesUsed = array();
                foreach($subtree->xpath('/setOutcomeValue/sum/variable') as $var){
                    $outcomesUsed[] = (string) $var[0]['identifier'];
                }
            }else{
                throw new UnexpectedResponseProcessing('Not composite, unknown rule');
            }
        }

        if(is_null($composition)){
            throw new UnexpectedResponseProcessing('Not composit, Composition rule missing');
        }

        $responses = array();
        foreach($item->getInteractions() as $interaction){
            $responses[$interaction->getResponse()->getIdentifier()] = $interaction->getResponse();
        }

        if(count(array_diff(array_keys($irps), array_keys($responses))) > 0){
            throw new UnexpectedResponseProcessing('Not composite, no responses for rules: '.implode(',', array_diff(array_keys($irps), array_keys($responses))));
        }
        if(count(array_diff(array_keys($responses), array_keys($irps))) > 0){
            throw new UnexpectedResponseProcessing('Not composite, no support for unmatched variables yet');
        }

        //assuming sum is correct

        $compositonRP = new Summation($item);
        foreach($responses as $id => $response){
            $outcome = null;
            foreach($item->getOutcomes() as $possibleOutcome){
                if($possibleOutcome->getIdentifier() == $irps[$id]['outcome']){
                    $outcome = $possibleOutcome;
                    break;
                }
            }
            if(is_null($outcome)){
                throw new ParsingException('Undeclared Outcome in ResponseProcessing');
            }
            $classname = '\\oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\'.$irps[$id]['class'];
            $irp = new $classname($response, $outcome);
            if($irp instanceof \oat\taoQtiItem\model\qti\response\interactionResponseProcessing\None && isset($irps[$id]['default'])){
                $irp->setDefaultValue($irps[$id]['default']);
            }
            $compositonRP->add($irp);
        }
        $returnValue = $compositonRP;

        return $returnValue;
    }
1063184
protected function getPropertyChildValue(\DOMElement $element, ContextInterface $context)
    {
        // If the property creates a new type: Return the element itself
        if ($element->hasAttribute('itemscope')) {
            $thing = $this->getThing($element->getAttribute('itemtype'), null, $context);
            return $this->processItemReferences($element, $context, $thing);
        }

        return null;
    }
1360416
private void handleDocument(EntityDocument document) {
		if (document instanceof ItemDocument) {
			this.entityDocumentProcessor
					.processItemDocument((ItemDocument) document);
		} else if (document instanceof PropertyDocument) {
			this.entityDocumentProcessor
					.processPropertyDocument((PropertyDocument) document);
		} else if(document instanceof LexemeDocument) {
			this.entityDocumentProcessor
					.processLexemeDocument((LexemeDocument) document);
		}
	}
188701
public function addItem(Item $item)
    {
        $itemUUID = $item->composeUUID();

        $this->elementsToUpdate[$itemUUID] = $item;
        unset($this->elementsToDelete[$itemUUID]);
    }
715614
protected function processProperty(\DOMElement $element, ContextInterface $context)
    {
        if ($element->hasAttribute('itemprop') && !($context->getParentThing() instanceof RootThing)) {
            $itemprops = trim($element->getAttribute('itemprop'));
            $itemprops = strlen($itemprops) ? preg_split('/\s+/', $itemprops) : [];
            $context = $this->processProperties($itemprops, $element, $context);
        }

        return $context;
    }
625173
protected function getItemReferenceElements(\DOMElement $element)
    {
        $itemrefElements = [];
        $itemrefs = trim($element->getAttribute('itemref'));
        $itemrefs = strlen($itemrefs) ? preg_split('/\s+/', $itemrefs) : [];
        foreach ($itemrefs as $itemref) {
            $itemrefElement = $element->ownerDocument->getElementById($itemref);
            if ($itemrefElement instanceof \DOMElement) {
                $itemrefElements[] = $itemrefElement;
            }
        }
        return $itemrefElements;
    }
678068
public function process(DOMElement $node, Item $item)
    {
        foreach ($this->keys as $key) {
            $item->setExtra($key, $this->getValue($node, $key));
        }
    }
614151
protected function resolveItems(Collection &$items): void
    {
        $resolver = function ($property) {
            return $this->resolve($property) ?: $property;
        };

        $items->each(function (MenuItem $item) use ($resolver) {
            $item->fill(array_map($resolver, $item->properties));
        });
    }
471282
protected function reparentElement(DOMElement $element)
	{
		$parentNode = $element->parentNode;
		do
		{
			$lastChild = $parentNode->lastChild;
			$parentNode->parentNode->insertBefore($lastChild, $parentNode->nextSibling);
		}
		while (!$lastChild->isSameNode($element));
	}
539615
protected function processProperties(array $itemprops, \DOMElement $element, ContextInterface $context)
    {
        foreach ($itemprops as $index => $itemprop) {
            $context = $this->processPropertyPrefixName(
                null,
                $itemprop,
                $element,
                $context,
                $index == (count($itemprops) - 1)
            );
        }

        return $context;
    }
933408
private function processCategory(array $element, $parent = null)
    {
        if ($this->isMasterCategory($element)) {
            $this->createCategory($element, MasterCategoryElement::class, $this->parseResult);
        }

        if ($this->isResourceGroup($element)) {
            $this->createCategory($element, ResourceGroupElement::class, $parent);
        }

        if ($this->isDataStructureCategory($element)) {
            $this->createCategory($element, DataStructureCategoryElement::class, $parent);
        }
    }