Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ItemSessionService | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| getItemSession | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| getItemSessionSubject | |
0.00% |
0 / 4 |
|
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) 2019 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoQtiTestPreviewer\models; |
| 22 | |
| 23 | use oat\oatbox\service\ConfigurableService; |
| 24 | use qtism\data\storage\xml\XmlDocument; |
| 25 | use qtism\runtime\common\State; |
| 26 | use qtism\runtime\common\Variable; |
| 27 | use qtism\runtime\tests\AssessmentItemSession; |
| 28 | use qtism\runtime\tests\AssessmentItemSessionException; |
| 29 | use qtism\runtime\tests\SessionManager; |
| 30 | use RuntimeException; |
| 31 | use taoQtiCommon_helpers_ResultTransmissionException; |
| 32 | |
| 33 | /** |
| 34 | * Class ItemSessionService |
| 35 | * Manage item session, validate response |
| 36 | */ |
| 37 | class ItemSessionService extends ConfigurableService |
| 38 | { |
| 39 | /** |
| 40 | * @param XmlDocument $qtiXmlDoc |
| 41 | * @param Variable[] $variables |
| 42 | * @return AssessmentItemSession |
| 43 | */ |
| 44 | public function getItemSession($qtiXmlDoc, $variables) |
| 45 | { |
| 46 | $itemSession = $this->getItemSessionSubject($qtiXmlDoc); |
| 47 | |
| 48 | try { |
| 49 | $itemSession->beginAttempt(); |
| 50 | $itemSession->endAttempt(new State($variables)); |
| 51 | } catch (AssessmentItemSessionException $e) { |
| 52 | $msg = 'An error occurred while processing the responses.'; |
| 53 | throw new RuntimeException($msg, 0, $e); |
| 54 | } catch (taoQtiCommon_helpers_ResultTransmissionException $e) { |
| 55 | $msg = 'An error occurred while transmitting a result to the target Result Server.'; |
| 56 | throw new RuntimeException($msg, 0, $e); |
| 57 | } |
| 58 | |
| 59 | return $itemSession; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @param XmlDocument $qtiXmlDoc |
| 64 | * @return AssessmentItemSession |
| 65 | */ |
| 66 | private function getItemSessionSubject($qtiXmlDoc) |
| 67 | { |
| 68 | $sessionManager = new SessionManager(); |
| 69 | $itemSession = new AssessmentItemSession($qtiXmlDoc->getDocumentComponent(), $sessionManager); |
| 70 | $itemSession->beginItemSession(); |
| 71 | |
| 72 | return $itemSession; |
| 73 | } |
| 74 | } |