Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
9 / 10 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LtiOutcomeXmlFactory | |
90.00% |
9 / 10 |
|
50.00% |
1 / 2 |
3.01 | |
0.00% |
0 / 1 |
| buildReplaceResultRequest | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| getDefaultLang | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2020 (original work) Open Assessment Technologies SA |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoLti\models\classes\LtiOutcome; |
| 22 | |
| 23 | use oat\oatbox\service\ConfigurableService; |
| 24 | |
| 25 | class LtiOutcomeXmlFactory extends ConfigurableService |
| 26 | { |
| 27 | private const REPLACE_RESULT_REQUEST = 'replaceResultRequest'; |
| 28 | private const OUTCOME_DEFAULT_LANG = 'en-us'; |
| 29 | |
| 30 | public function buildReplaceResultRequest( |
| 31 | string $sourcedId, |
| 32 | string $grade, |
| 33 | string $messageIdentifier, |
| 34 | string $language = self::OUTCOME_DEFAULT_LANG |
| 35 | ): string { |
| 36 | $language = $language ?? $this->getDefaultLang(); |
| 37 | return '<?xml version = "1.0" encoding = "UTF-8"?> |
| 38 | <imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"> |
| 39 | <imsx_POXHeader> |
| 40 | <imsx_POXRequestHeaderInfo> |
| 41 | <imsx_version>V1.0</imsx_version> |
| 42 | <imsx_messageIdentifier>' . $messageIdentifier . '</imsx_messageIdentifier> |
| 43 | </imsx_POXRequestHeaderInfo> |
| 44 | </imsx_POXHeader> |
| 45 | <imsx_POXBody> |
| 46 | <' . self::REPLACE_RESULT_REQUEST . '> |
| 47 | <resultRecord> |
| 48 | <sourcedGUID> |
| 49 | <sourcedId>' . $sourcedId . '</sourcedId> |
| 50 | </sourcedGUID> |
| 51 | <result> |
| 52 | <resultScore> |
| 53 | <language>' . $language . '</language> |
| 54 | <textString>' . $grade . '</textString> |
| 55 | </resultScore> |
| 56 | </result> |
| 57 | </resultRecord> |
| 58 | </' . self::REPLACE_RESULT_REQUEST . '> |
| 59 | </imsx_POXBody> |
| 60 | </imsx_POXEnvelopeRequest>'; |
| 61 | } |
| 62 | |
| 63 | private function getDefaultLang(): string |
| 64 | { |
| 65 | return defined(DEFAULT_LANG) ? DEFAULT_LANG : self::OUTCOME_DEFAULT_LANG; |
| 66 | } |
| 67 | } |