protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile)
    {
        $changed = false;
        $responses = $item->getResponses();
        $interactions = $item->getInteractions();
        $usedResponses = [];
        foreach($interactions as $interaction){
            $usedResponses[] = $interaction->attr('responseIdentifier');
        }
        foreach ($responses as $response) {
            $responseIdentifier = $response->attr('identifier');
            if(!in_array($responseIdentifier, $usedResponses)){
                $changed = true;
                $item->removeResponse($response);
            }
        }

        $xml        = simplexml_load_file($itemFile);
        $rpTemplate = (string) $xml->responseProcessing['template'];
        
        //detect wrong usage for standard standard response declaration
        $rp = $item->getResponseProcessing();
        if ($rp instanceof \oat\taoQtiItem\model\qti\response\TemplatesDriven && $rpTemplate) {
            if (count($interactions) > 1) {
                $changed = true;
            } else {
                $interaction = reset($interactions);
                if ($interaction && $interaction->attr('responseIdentifier') != 'RESPONSE') {
                    $changed = true;
                }
            }
        }

        return $changed;
    }
protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile)
    {
        $changed = false;
        $responses = $item->getResponses();
        $interactions = $item->getInteractions();
        $usedResponses = [];
        foreach($interactions as $interaction){
            $usedResponses[] = $interaction->attr('responseIdentifier');
        }
        foreach ($responses as $response) {
            $responseIdentifier = $response->attr('identifier');
            if(!in_array($responseIdentifier, $usedResponses)){
                $changed = true;
                $item->removeResponse($response);
            }
        }

        $xml        = simplexml_load_file($itemFile);
        $rpTemplate = (string) $xml->responseProcessing['template'];
        
        //detect wrong usage for standard standard response declaration
        $rp = $item->getResponseProcessing();
        if ($rp instanceof \oat\taoQtiItem\model\qti\response\TemplatesDriven && $rpTemplate) {
            if (count($interactions) > 1) {
                $changed = true;
            } else {
                $interaction = reset($interactions);
                if ($interaction && $interaction->attr('responseIdentifier') != 'RESPONSE') {
                    $changed = true;
                }
            }
        }

        return $changed;
    }
protected function updateItem ( \ oat \ taoQtiItem \ model \ qti \ Item $ item , $ itemFile ) { $ changed = false ; $ responses = $ item -> getResponses ( ) ; $ interactions = $ item -> getInteractions ( ) ; $ usedResponses = [ ] ; foreach ( $ interactions as $ interaction ) { $ usedResponses [ ] = $ interaction -> attr ( 'responseIdentifier' ) ; } foreach ( $ responses as $ response ) { $ responseIdentifier = $ response -> attr ( 'identifier' ) ; if ( ! in_array ( $ responseIdentifier , $ usedResponses ) ) { $ changed = true ; $ item -> removeResponse ( $ response ) ; } } $ xml = simplexml_load_file ( $ itemFile ) ; $ rpTemplate = ( string ) $ xml -> responseProcessing [ 'template' ] ; //detect wrong usage for standard standard response declaration $ rp = $ item -> getResponseProcessing ( ) ; if ( $ rp instanceof \ oat \ taoQtiItem \ model \ qti \ response \ TemplatesDriven && $ rpTemplate ) { if ( count ( $ interactions ) > 1 ) { $ changed = true ; } else { $ interaction = reset ( $ interactions ) ; if ( $ interaction && $ interaction -> attr ( 'responseIdentifier' ) != 'RESPONSE' ) { $ changed = true ; } } } return $ changed ; }
Remove unused response declaration from the items and rp template misuse

@param oat\taoQtiItem\modal\Item $item
@param string $itemFile
@return boolean
Remove unused response declaration from the items and rp template misuse