Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| taoLtiBasicOutcome_models_classes_LtiBasicOutcome | |
0.00% |
0 / 59 |
|
0.00% |
0 / 10 |
342 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| storeTestVariable | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
30 | |||
| storeTestVariables | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| configure | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| spawnResult | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| storeRelatedTestTaker | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| storeRelatedDelivery | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| storeItemVariable | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| storeItemVariables | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getLtiOutcomeXmlFactory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\taoLti\models\classes\LtiOutcome\LtiOutcomeXmlFactory; |
| 23 | use oat\taoLti\models\classes\LtiService; |
| 24 | use oat\taoResultServer\models\classes\ResultAliasServiceInterface; |
| 25 | |
| 26 | /** |
| 27 | * Implements tao results storage with respect to LTI 1.1.1 specs acting as a Tool provider calling back the consumer |
| 28 | * outcome service |
| 29 | */ |
| 30 | |
| 31 | class taoLtiBasicOutcome_models_classes_LtiBasicOutcome extends tao_models_classes_GenerisService implements |
| 32 | taoResultServer_models_classes_WritableResultStorage |
| 33 | { |
| 34 | public const VARIABLE_IDENTIFIER = 'LtiOutcome'; |
| 35 | |
| 36 | //private $ltiConsumer;//the kb resource modelling the LTI consumer |
| 37 | /** |
| 38 | * @param string deliveryResultIdentifier if no such deliveryResult with this identifier exists a new one gets |
| 39 | * created |
| 40 | */ |
| 41 | public function __construct() |
| 42 | { |
| 43 | parent::__construct(); |
| 44 | common_ext_ExtensionsManager::singleton()->getExtensionById("taoLtiBasicOutcome"); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param $deliveryResultIdentifier lis_result_sourcedid |
| 49 | * @param $test ignored |
| 50 | * @param taoResultServer_models_classes_Variable $testVariable |
| 51 | * @param $callIdTest ignored |
| 52 | * @throws \oat\taoLti\models\classes\LtiException |
| 53 | * @throws common_exception_Error |
| 54 | */ |
| 55 | public function storeTestVariable( |
| 56 | $deliveryResultIdentifier, |
| 57 | $test, |
| 58 | taoResultServer_models_classes_Variable $testVariable, |
| 59 | $callIdTest |
| 60 | ) { |
| 61 | if (get_class($testVariable) == "taoResultServer_models_classes_OutcomeVariable") { |
| 62 | common_Logger::d( |
| 63 | "Outcome submission VariableId. (" . $testVariable->getIdentifier() . ") Result Identifier (" |
| 64 | . $deliveryResultIdentifier . ")Service URL (" . $this->serviceUrl . ")" |
| 65 | ); |
| 66 | $variableIdentifier = $testVariable->getIdentifier(); |
| 67 | if ( |
| 68 | ($variableIdentifier == self::VARIABLE_IDENTIFIER) |
| 69 | // or true |
| 70 | ) { |
| 71 | $grade = (string)$testVariable->getValue(); |
| 72 | |
| 73 | /** @var ResultAliasServiceInterface $resultAliasService */ |
| 74 | $resultAliasService = $this->getServiceLocator()->get(ResultAliasServiceInterface::SERVICE_ID); |
| 75 | $deliveryResultAlias = $resultAliasService->getResultAlias($deliveryResultIdentifier); |
| 76 | $deliveryResultIdentifier = empty($deliveryResultAlias) |
| 77 | ? $deliveryResultIdentifier |
| 78 | : current($deliveryResultAlias); |
| 79 | |
| 80 | $ltiOutcomeXmlFactory = $this->getLtiOutcomeXmlFactory(); |
| 81 | $message = $ltiOutcomeXmlFactory->buildReplaceResultRequest( |
| 82 | $deliveryResultIdentifier, |
| 83 | $grade, |
| 84 | uniqid('', true) |
| 85 | ); |
| 86 | |
| 87 | $credentialResource = LtiService::singleton()->getCredential($this->consumerKey); |
| 88 | $credentials = new tao_models_classes_oauth_Credentials($credentialResource); |
| 89 | //Building POX raw http message |
| 90 | $unSignedOutComeRequest = new common_http_Request($this->serviceUrl, 'POST', []); |
| 91 | $unSignedOutComeRequest->setBody($message); |
| 92 | $signingService = new tao_models_classes_oauth_Service(); |
| 93 | $signedRequest = $signingService->sign($unSignedOutComeRequest, $credentials, true); |
| 94 | common_Logger::d("Request sent (Body)\n" . ($signedRequest->getBody()) . "\n"); |
| 95 | common_Logger::d("Request sent (Headers)\n" . (serialize($signedRequest->getHeaders())) . "\n"); |
| 96 | common_Logger::d("Request sent (Headers)\n" . (serialize($signedRequest->getParams())) . "\n"); |
| 97 | //Hack for moodle comaptibility, the header is ignored for the signature computation |
| 98 | $signedRequest->setHeader("Content-Type", "application/xml"); |
| 99 | |
| 100 | $response = $signedRequest->send(); |
| 101 | common_Logger::d("\nHTTP Code received: " . ($response->httpCode) . "\n"); |
| 102 | common_Logger::d("\nHTTP From: " . ($response->effectiveUrl) . "\n"); |
| 103 | common_Logger::d("\nHTTP Content received: " . ($response->responseData) . "\n"); |
| 104 | if ($response->httpCode != "200") { |
| 105 | throw new common_exception_Error( |
| 106 | "An HTTP level proble occured when sending the outcome to the service url" |
| 107 | ); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | public function storeTestVariables($deliveryResultIdentifier, $test, array $testVariables, $callIdTest) |
| 114 | { |
| 115 | foreach ($testVariables as $testVariable) { |
| 116 | $this->storeTestVariable($deliveryResultIdentifier, $test, $testVariable, $callIdTest); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * retrieve specific parameters from the resultserver to configure the storage |
| 122 | */ |
| 123 | /*sic*/ |
| 124 | public function configure($callOptions = []) |
| 125 | { |
| 126 | /** |
| 127 | * Retrieve the lti consumer associated with the result server in the KB , those rpoperties are available within |
| 128 | * taoLtiBasicComponent only |
| 129 | */ |
| 130 | |
| 131 | if (isset($callOptions["service_url"])) { |
| 132 | $this->serviceUrl = $callOptions["service_url"]; |
| 133 | } else { |
| 134 | throw new common_Exception("LtiBasicOutcome Storage requires a call parameter service_url"); |
| 135 | } |
| 136 | if (isset($callOptions["consumer_key"])) { |
| 137 | $this->consumerKey = $callOptions["consumer_key"]; |
| 138 | } else { |
| 139 | throw new common_Exception("LtiBasicOutcome Storage requires a call parameter consumerKey"); |
| 140 | } |
| 141 | |
| 142 | common_Logger::d( |
| 143 | "ResultServer configured with " . $callOptions["service_url"] . " and " . $callOptions["consumer_key"] |
| 144 | ); |
| 145 | } |
| 146 | /** |
| 147 | * In the case of An LtiBasic OutcomeSubmission, spawnResult has no effect |
| 148 | */ |
| 149 | public function spawnResult() |
| 150 | { |
| 151 | } |
| 152 | public function storeRelatedTestTaker($deliveryResultIdentifier, $testTakerIdentifier) |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | public function storeRelatedDelivery($deliveryResultIdentifier, $deliveryIdentifier) |
| 157 | { |
| 158 | } |
| 159 | |
| 160 | public function storeItemVariable( |
| 161 | $deliveryResultIdentifier, |
| 162 | $test, |
| 163 | $item, |
| 164 | taoResultServer_models_classes_Variable $itemVariable, |
| 165 | $callIdItem |
| 166 | ) { |
| 167 | // For testing purpose. |
| 168 | common_Logger::d("Item Variable Submission: " . $itemVariable->getIdentifier()); |
| 169 | $this->storeTestVariable($deliveryResultIdentifier, $test, $itemVariable, $callIdItem); |
| 170 | } |
| 171 | |
| 172 | public function storeItemVariables($deliveryResultIdentifier, $test, $item, array $itemVariables, $callIdItem) |
| 173 | { |
| 174 | foreach ($itemVariables as $itemVariable) { |
| 175 | $this->storeItemVariable($deliveryResultIdentifier, $test, $item, $itemVariable, $callIdItem); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | private function getLtiOutcomeXmlFactory(): LtiOutcomeXmlFactory |
| 180 | { |
| 181 | return $this->getServiceLocator()->get(LtiOutcomeXmlFactory::class); |
| 182 | } |
| 183 | } |