Short description of method buildResponseProcessing

@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param  DOMElement data
@param  Item item
@return oat\taoQtiItem\model\qti\response\ResponseProcessing
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;
    }
487358
@RequestMapping(value = "/item", method = RequestMethod.POST)
    @ResponseBody
    public JsonObjectBase newItem(@Valid ConfNewItemForm confNewForm) {

        // 业务校验
        configValidator.validateNew(confNewForm, DisConfigTypeEnum.ITEM);

        //
        configMgr.newConfig(confNewForm, DisConfigTypeEnum.ITEM);

        return buildSuccess("创建成功");
    }
199746
public function addItem(
        $itemData,
        $locale,
        $userId,
        OrderEntity $order,
        ItemInterface $lastProcessedProductItem = null
    ) {
        $item = $this->itemManager->save(
            $itemData,
            $locale,
            $userId,
            null,
            null,
            $order->getCustomerContact(),
            $lastProcessedProductItem
        );

        $order->addItem($item->getEntity());

        return $item;
    }
1266922
private function processItems($data, Shipping $shipping, $locale, $userId)
    {
        $result = true;
        try {
            if ($this->checkDataSet($data, 'items', false)) {
                // items has to be an array
                if (!is_array($data['items'])) {
                    throw new MissingShippingAttributeException('items array');
                }

                $items = $data['items'];

                $get = function ($item){
                    return $item->getId();
                };

                $delete = function ($item) use ($shipping){
                    $entity = $item->getEntity();
                    // remove from order
                    $shipping->removeShippingItem($entity);
                    // delete item
                    $this->em->remove($entity);
                };

                $update = function ($item, $matchedEntry) use ($locale){
                    $shippingItem = $this->saveShippingItem($matchedEntry, $item->getEntity());

                    return $shippingItem ? true : false;
                };

                $add = function ($itemData) use ($locale, $shipping){
                    $shippingItem = $this->saveShippingItem($itemData);
                    $shippingItem->setShipping($shipping->getEntity());
                    return $shipping->addShippingItem($shippingItem, null, $locale);
                };

                $result = $this->restHelper->processSubEntities($shipping->getItems(), $items, $get, $add, $update, $delete);
            }
        } catch (Exception $e) {
            throw new OrderException('Error while creating items: ' . $e->getMessage());
        }
        return $result;
    }
914842
protected function processItemReferences(\DOMElement $element, ContextInterface $context, ThingInterface $thing)
    {
        // If the element has item references
        if ($element->hasAttribute('itemref')) {
            $itemrefElements = $this->getItemReferenceElements($element);
            if (count($itemrefElements)) {
                $this->processItemReferenceElements($itemrefElements, $context, $thing);
            }
        }

        return $thing;
    }
773121
@Override
	public Response process(Response.ResponseBuilder responseBuilder)
	{
		final String entity = process();

		responseBuilder.entity(entity);

		return responseBuilder.build();
	}
1268382
protected function buildResponse()
    {
        $response = new Response();
        if ($this->viewCache === true) {
            $response->setPublic();

            if ($this->ttlCache === true) {
                $response->setSharedMaxAge(
                    $this->defaultTtl
                );
            }

            // Make the response vary against Cookie header ensures that an HTTP
            // reverse proxy caches the different possible variations of the
            // response as it can depend on user role for instance. X-User-Hash cannot
            // be used since the website toolbar can have Owner( Self ) Policy Limitation.
            $response->setVary('Cookie');
        }

        return $response;
    }
347675
function processItems ( items, values, guid, counter ) {
  	if ( counter === void 0 ) counter = 0;

  	return items.map( function ( item ) {
  		if ( item.type === TEXT ) {
  			return item.template;
  		}

  		if ( item.fragment ) {
  			if ( item.fragment.iterations ) {
  				return item.fragment.iterations.map( function ( fragment ) {
  					return processItems( fragment.items, values, guid, counter );
  				}).join( '' );
  			} else {
  				return processItems( item.fragment.items, values, guid, counter );
  			}
  		}

  		var placeholderId = "" + guid + "-" + (counter++);
  		var model = item.model || item.newModel;

  		values[ placeholderId ] = model ?
  			model.wrapper ?
  				model.wrapper.value :
  				model.get() :
  			undefined;

  		return '${' + placeholderId + '}';
  	}).join( '' );
  }
790600
private function processListResponse()
    {
        /** @var ListDocumentsResponse $obj_list_response */
        $obj_list_response = $this->obj_last_response;
        $obj_response = (object)[
            'status' => $this->describeStatusCode($obj_list_response->getStatus()->getCode()),
            'count' => $obj_list_response->getDocumentSize(),
            'docs' => []
        ];
        $obj_mapper = new Mapper();
        foreach($obj_list_response->getDocumentList() as $obj_document) {
            $obj_doc = $obj_mapper->fromGoogle($obj_document);
            $obj_response->docs[] = $obj_doc;
        }
        return $obj_response;
    }
1046762
protected function createResponse()
	{
		try {
			$body = $this->stream->createStream(fopen('php://temp', 'w+b'));
		}
		catch (InvalidArgumentException $e) {
			throw new RuntimeException('Unable to create stream "php://temp"');
		}

		return new ResponseBuilder(
			$this->message->createResponse(200, null, [], $body)
		);
	}
670388
public static function takeOverFrom(ResponseProcessing $responseProcessing, Item $item){
        $returnValue = null;

        if($responseProcessing instanceof static){
            // already good
            $returnValue = $responseProcessing;
        }elseif($responseProcessing instanceof Template){
            // IMS Template
            $rp = new Summation($item, 'SCORE');
            foreach($item->getInteractions() as $interaction){
                $response = $interaction->getResponse();
                try{
                    $irp = IrpTemplate::createByTemplate(
                                    $responseProcessing->getUri(), $response, $item);
                }catch(Exception $e){
                    throw new TakeoverFailedException();
                }
                $rp->add($irp, $item);
            }
            $returnValue = $rp;
        }elseif($responseProcessing instanceof TemplatesDriven){
            // TemplateDriven
            $rp = new Summation($item, 'SCORE');
            foreach($item->getInteractions() as $interaction){
                $response = $interaction->getResponse();
                try{
                    $irp = IrpTemplate::createByTemplate(
                                    $responseProcessing->getTemplate($response)
                                    , $response
                                    , $item
                    );
                }catch(Exception $e){
                    throw new TakeoverFailedException();
                }
                $rp->add($irp, $item);
            }
            $returnValue = $rp;
        }else{
            common_Logger::d('Composite ResponseProcessing can not takeover from '.get_class($responseProcessing).' yet');
            throw new TakeoverFailedException();
        }

        common_Logger::i('Converted to Composite', array('TAOITEMS', 'QTI'));

        return $returnValue;
    }
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;
    }
1310185
public static function updateItemAsync($item_id, $item)
    {
        return self::updateItemAsyncWithHttpInfo($item_id, $item)
            ->then(
                function ($response) {
                    return $response[0];
            }
        );
    }
414946
public static function build(
        $data,
        $root = 'xml',
        $item = 'item',
        $attr = '',
        $id = 'id'
    ) {
        if (is_array($attr)) {
            $_attr = array();

            foreach ($attr as $key => $value) {
                $_attr[] = "{$key}=\"{$value}\"";
            }

            $attr = implode(' ', $_attr);
        }

        $attr = trim($attr);
        $attr = empty($attr) ? '' : " {$attr}";
        $xml = "<{$root}{$attr}>";
        $xml  .= self::data2Xml($data, $item, $id);
        $xml  .= "</{$root}>";

        return $xml;
    }
1231022
private function buildResponse(Event $event)
    {
        $request = $event->getData()['request'];
        $response = $event->getData()['response'];

        if ('xml' === Configure::read('ApiRequest.responseType')) {
            $response->withType('xml');
        } else {
            $response->withType('json');
        }

        $response->cors($request)
                ->allowOrigin(Configure::read('ApiRequest.cors.origin'))
                ->allowMethods(Configure::read('ApiRequest.cors.allowedMethods'))
                ->allowHeaders(Configure::read('ApiRequest.cors.allowedHeaders'))
                ->allowCredentials()
                ->maxAge(Configure::read('ApiRequest.cors.maxAge'))
                ->build();

        return true;
    }
296725
function processItemtype(item, processedItems) {
  processedItems.push({
    'id':         md5($(item).html()),
    'name':       $(item).attr('itemtype'),
    'properties': {}
  });

}
391336
protected function unmarshall(DOMElement $element)
    {
        if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {

            if (($autostart = $this->getDOMElementAttributeAs($element, 'autostart', 'boolean')) !== null) {

                $objectElts = $this->getChildElementsByTagName($element, 'object');
                if (count($objectElts) > 0) {
                    $objectElt = $objectElts[0];
                    $object = $this->getMarshallerFactory()->createMarshaller($objectElt)->unmarshall($objectElt);

                    $component = new MediaInteraction($responseIdentifier, $autostart, $object);

                    $promptElts = $this->getChildElementsByTagName($element, 'prompt');
                    if (count($promptElts) > 0) {
                        $promptElt = $promptElts[0];
                        $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt);
                        $component->setPrompt($prompt);
                    }

                    if (($minPlays = $this->getDOMElementAttributeAs($element, 'minPlays', 'integer')) !== null) {
                        $component->setMinPlays($minPlays);
                    }

                    if (($maxPlays = $this->getDOMElementAttributeAs($element, 'maxPlays', 'integer')) !== null) {
                        $component->setMaxPlays($maxPlays);
                    }

                    if (($loop = $this->getDOMElementAttributeAs($element, 'loop', 'boolean')) !== null) {
                        $component->setLoop($loop);
                    }

                    if (($xmlBase = self::getXmlBase($element)) !== false) {
                        $component->setXmlBase($xmlBase);
                    }

                    $this->fillBodyElement($component, $element);

                    return $component;
                } else {
                    $msg = "A 'mediaInteraction' element must contain exactly one 'object' element, none given.";
                    throw new UnmarshallingException($msg, $element);
                }
            } else {
                $msg = "The mandatory 'autostart' attribute is missing from the 'mediaInteraction' element.";
                throw new UnmarshallingException($msg, $element);
            }
        } else {
            $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'mediaInteraction' element.";
            throw new UnmarshallingException($msg, $element);
        }
    }