getExtensionById("taoLtiBasicOutcome"); } /** * @param $deliveryResultIdentifier lis_result_sourcedid * @param $test ignored * @param taoResultServer_models_classes_Variable $testVariable * @param $callIdTest ignored * @throws \oat\taoLti\models\classes\LtiException * @throws common_exception_Error */ public function storeTestVariable($deliveryResultIdentifier, $test, taoResultServer_models_classes_Variable $testVariable, $callIdTest) { if (get_class($testVariable) == "taoResultServer_models_classes_OutcomeVariable") { common_Logger::d( "Outcome submission VariableId. (" . $testVariable->getIdentifier() . ") Result Identifier (" . $deliveryResultIdentifier . ")Service URL (" . $this->serviceUrl . ")" ); $variableIdentifier = $testVariable->getIdentifier(); if ( ($variableIdentifier == self::VARIABLE_IDENTIFIER) // or true ) { $grade = (string)$testVariable->getValue(); /** @var ResultAliasServiceInterface $resultAliasService */ $resultAliasService = $this->getServiceLocator()->get(ResultAliasServiceInterface::SERVICE_ID); $deliveryResultAlias = $resultAliasService->getResultAlias($deliveryResultIdentifier); $deliveryResultIdentifier = empty($deliveryResultAlias) ? $deliveryResultIdentifier : current($deliveryResultAlias); $ltiOutcomeXmlFactory = $this->getLtiOutcomeXmlFactory(); $message = $ltiOutcomeXmlFactory->buildReplaceResultRequest( $deliveryResultIdentifier, $grade, uniqid('', true) ); $credentialResource = LtiService::singleton()->getCredential($this->consumerKey); $credentials = new tao_models_classes_oauth_Credentials($credentialResource); //Building POX raw http message $unSignedOutComeRequest = new common_http_Request($this->serviceUrl, 'POST', []); $unSignedOutComeRequest->setBody($message); $signingService = new tao_models_classes_oauth_Service(); $signedRequest = $signingService->sign($unSignedOutComeRequest, $credentials, true); common_Logger::d("Request sent (Body)\n" . ($signedRequest->getBody()) . "\n"); common_Logger::d("Request sent (Headers)\n" . (serialize($signedRequest->getHeaders())) . "\n"); common_Logger::d("Request sent (Headers)\n" . (serialize($signedRequest->getParams())) . "\n"); //Hack for moodle comaptibility, the header is ignored for the signature computation $signedRequest->setHeader("Content-Type", "application/xml"); $response = $signedRequest->send(); common_Logger::d("\nHTTP Code received: " . ($response->httpCode) . "\n"); common_Logger::d("\nHTTP From: " . ($response->effectiveUrl) . "\n"); common_Logger::d("\nHTTP Content received: " . ($response->responseData) . "\n"); if ($response->httpCode != "200") { throw new common_exception_Error("An HTTP level proble occured when sending the outcome to the service url"); } } } } public function storeTestVariables($deliveryResultIdentifier, $test, array $testVariables, $callIdTest) { foreach ($testVariables as $testVariable) { $this->storeTestVariable($deliveryResultIdentifier, $test, $testVariable, $callIdTest); } } /* * retrieve specific parameters from the resultserver to configure the storage */ /*sic*/ public function configure($callOptions = []) { /** * Retrieve the lti consumer associated with the result server in the KB , those rpoperties are available within taoLtiBasicComponent only */ if (isset($callOptions["service_url"])) { $this->serviceUrl = $callOptions["service_url"]; } else { throw new common_Exception("LtiBasicOutcome Storage requires a call parameter service_url"); } if (isset($callOptions["consumer_key"])) { $this->consumerKey = $callOptions["consumer_key"]; } else { throw new common_Exception("LtiBasicOutcome Storage requires a call parameter consumerKey"); } common_Logger::d("ResultServer configured with " . $callOptions["service_url"] . " and " . $callOptions["consumer_key"]); } /** * In the case of An LtiBasic OutcomeSubmission, spawnResult has no effect */ public function spawnResult() { } public function storeRelatedTestTaker($deliveryResultIdentifier, $testTakerIdentifier) { } public function storeRelatedDelivery($deliveryResultIdentifier, $deliveryIdentifier) { } public function storeItemVariable($deliveryResultIdentifier, $test, $item, taoResultServer_models_classes_Variable $itemVariable, $callIdItem) { // For testing purpose. common_Logger::d("Item Variable Submission: " . $itemVariable->getIdentifier()); $this->storeTestVariable($deliveryResultIdentifier, $test, $itemVariable, $callIdItem); } public function storeItemVariables($deliveryResultIdentifier, $test, $item, array $itemVariables, $callIdItem) { foreach ($itemVariables as $itemVariable) { $this->storeItemVariable($deliveryResultIdentifier, $test, $item, $itemVariable, $callIdItem); } } private function getLtiOutcomeXmlFactory(): LtiOutcomeXmlFactory { return $this->getServiceLocator()->get(LtiOutcomeXmlFactory::class); } }