Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
taoQtiTest_models_classes_CrudQtiTestsService | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
getClassService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
delete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
importQtiTest | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
72 | |||
logException | |
0.00% |
0 / 9 |
|
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-2014 (original work) Open Assessment Technologies SA |
19 | * |
20 | */ |
21 | |
22 | use oat\oatbox\log\LoggerAwareTrait; |
23 | use oat\tao\model\TaoOntology; |
24 | |
25 | /** |
26 | * Crud services implements basic CRUD services, orginally intended for |
27 | * REST controllers/ HTTP exception handlers . |
28 | * |
29 | * Consequently the signatures and behaviors is closer to REST and throwing HTTP like exceptions |
30 | * |
31 | * @author Absar Gilani, absar.gilani@gmail.com |
32 | * |
33 | */ |
34 | class taoQtiTest_models_classes_CrudQtiTestsService extends tao_models_classes_CrudService |
35 | { |
36 | use LoggerAwareTrait; |
37 | |
38 | /** (non-PHPdoc) |
39 | * @see tao_models_classes_CrudSservice::getClassService() |
40 | */ |
41 | protected function getClassService() |
42 | { |
43 | return taoQtiTest_models_classes_QtiTestService::singleton(); |
44 | } |
45 | |
46 | /** |
47 | * (non-PHPdoc) |
48 | * @see tao_models_classes_CrudService::delete() |
49 | */ |
50 | public function delete($uri) |
51 | { |
52 | $success = $this->getClassService()->deleteTest(new core_kernel_classes_Resource($uri)); |
53 | } |
54 | |
55 | /** |
56 | * @author Rashid Mumtaz & Absar - PCG Team - {absar.gilani6@gmail.com & rashid.mumtaz372@gmail.com} |
57 | * @param string $uploadedFile |
58 | * @param \core_kernel_classes_Class $class |
59 | * @param bool $enableMetadataGuardians |
60 | * @param bool $enableMetadataValidators |
61 | * @param bool $itemMustExist |
62 | * @param bool $itemMustBeOverwritten |
63 | * @return common_report_Report |
64 | */ |
65 | public function importQtiTest( |
66 | $uploadedFile, |
67 | $class = null, |
68 | $enableMetadataGuardians = true, |
69 | $enableMetadataValidators = true, |
70 | $itemMustExist = false, |
71 | $itemMustBeOverwritten = false, |
72 | bool $overwriteTest = false, |
73 | ?string $itemClassUri = null, |
74 | ?string $overwriteTestUri = null, |
75 | ?string $packageLabel = null |
76 | ) { |
77 | try { |
78 | //The zip extraction is a long process that can exceed the 30s timeout |
79 | helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG); |
80 | $class = is_null($class) ? new core_kernel_classes_Class(TaoOntology::TEST_CLASS_URI) : $class; |
81 | $importer = taoQtiTest_models_classes_QtiTestService::singleton(); |
82 | |
83 | if ($enableMetadataGuardians === false) { |
84 | $importer->disableMetadataGuardians(); |
85 | } |
86 | |
87 | if ($enableMetadataValidators === false) { |
88 | $importer->disableMetadataValidators(); |
89 | } |
90 | |
91 | if ($itemMustExist === true) { |
92 | $importer->enableItemMustExist(); |
93 | } |
94 | |
95 | if ($itemMustBeOverwritten === true) { |
96 | $importer->enableItemMustBeOverwritten(); |
97 | } |
98 | |
99 | $report = $importer->importMultipleTests( |
100 | $class, |
101 | $uploadedFile, |
102 | $overwriteTest, |
103 | $itemClassUri, |
104 | [], |
105 | $overwriteTestUri, |
106 | $packageLabel |
107 | ); |
108 | helpers_TimeOutHelper::reset(); |
109 | |
110 | return $report; |
111 | } catch (common_exception_UserReadableException $e) { |
112 | $this->logException($e); |
113 | |
114 | return new common_report_Report(common_report_Report::TYPE_ERROR, __($e->getUserMessage())); |
115 | } catch (Throwable $exception) { |
116 | $this->logException($exception); |
117 | |
118 | return new common_report_Report(common_report_Report::TYPE_ERROR, __('QTI test import failed')); |
119 | } |
120 | } |
121 | |
122 | private function logException(Throwable $exception): void |
123 | { |
124 | $this->logError( |
125 | sprintf( |
126 | 'QTI test import failed: %s. File: %s, Line: %s. Stack trace: %s', |
127 | $exception->getMessage(), |
128 | $exception->getFile(), |
129 | $exception->getLine(), |
130 | $exception->getTraceAsString() |
131 | ) |
132 | ); |
133 | } |
134 | } |