Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| QtiTestPacker | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| packTest | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2015 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoQtiTest\models\pack; |
| 22 | |
| 23 | use oat\oatbox\service\ServiceManager; |
| 24 | use oat\taoItems\model\pack\Packer; |
| 25 | use oat\taoTests\models\pack\Packable; |
| 26 | use oat\taoTests\models\pack\TestPack; |
| 27 | use taoQtiTest_models_classes_QtiTestService; |
| 28 | use core_kernel_classes_Resource; |
| 29 | use InvalidArgumentException; |
| 30 | use common_Exception; |
| 31 | use Exception; |
| 32 | |
| 33 | /** |
| 34 | * This class pack a QTI Test. Packing instead of compiling, aims |
| 35 | * to extract the only data of an test. Those data are used by the |
| 36 | * test runner to render the test. |
| 37 | * |
| 38 | * @package taoQtiTest |
| 39 | * @author Bertrand Chevrier <bertrand@taotesting.com> |
| 40 | */ |
| 41 | class QtiTestPacker implements Packable |
| 42 | { |
| 43 | /** |
| 44 | * The test type identifier |
| 45 | * @var string |
| 46 | */ |
| 47 | private static $testType = 'qti'; |
| 48 | |
| 49 | /** |
| 50 | * packTest implementation for QTI |
| 51 | * @see {@link Packable} |
| 52 | * @throws InvalidArgumentException |
| 53 | * @throws common_Exception |
| 54 | */ |
| 55 | public function packTest(core_kernel_classes_Resource $test) |
| 56 | { |
| 57 | $testPack = null; |
| 58 | |
| 59 | try { |
| 60 | $qtiTestService = taoQtiTest_models_classes_QtiTestService::singleton(); |
| 61 | |
| 62 | $doc = $qtiTestService->getDoc($test); |
| 63 | $converter = new \taoQtiTest_models_classes_QtiTestConverter($doc); |
| 64 | $items = []; |
| 65 | foreach ($qtiTestService->getItems($test) as $item) { |
| 66 | $items[$item->getUri()] = (new Packer($item, '')) |
| 67 | ->setServiceLocator(ServiceManager::getServiceManager()) |
| 68 | ->pack(); |
| 69 | } |
| 70 | $testPack = new TestPack(self::$testType, $converter->toArray(), $items); |
| 71 | } catch (Exception $e) { |
| 72 | throw new common_Exception('Unable to pack test ' . $test->getUri() . ' : ' . $e->getMessage()); |
| 73 | } |
| 74 | |
| 75 | return $testPack; |
| 76 | } |
| 77 | } |