Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 167 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
Monitor | |
0.00% |
0 / 167 |
|
0.00% |
0 / 11 |
1056 | |
0.00% |
0 / 1 |
getCurrentDelivery | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getViewData | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
12 | |||
index | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
monitor | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
deliveryExecutions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
authoriseExecutions | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
30 | |||
terminateExecutions | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
pauseExecutions | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
reportExecutions | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
extraTime | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
adjustTime | |
0.00% |
0 / 18 |
|
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 | |
22 | namespace oat\taoProctoring\controller; |
23 | |
24 | use common_Exception; |
25 | use common_exception_Error; |
26 | use common_exception_NotFound; |
27 | use common_ext_ExtensionException; |
28 | use oat\generis\model\OntologyAwareTrait; |
29 | use oat\oatbox\service\exception\InvalidServiceManagerException; |
30 | use oat\oatbox\service\ServiceNotFoundException; |
31 | use oat\tao\model\accessControl\AclProxy; |
32 | use oat\tao\model\mvc\DefaultUrlService; |
33 | use oat\taoProctoring\helpers\DeliveryHelper; |
34 | use oat\taoProctoring\model\AssessmentResultsService; |
35 | use oat\taoProctoring\model\datatable\DeliveriesMonitorDatatable; |
36 | use oat\taoProctoring\model\execution\DeliveryExecutionManagerService; |
37 | use oat\taoProctoring\model\GuiSettingsService; |
38 | use oat\taoProctoring\model\implementation\DeliveryExecutionStateService; |
39 | use oat\taoProctoring\model\TestSessionConnectivityStatusService; |
40 | use oat\taoProctoring\model\TestSessionHistoryService; |
41 | use oat\taoQtiTest\models\QtiTestExtractionFailedException; |
42 | |
43 | /** |
44 | * Monitoring Delivery controller |
45 | * |
46 | * @author Open Assessment Technologies SA |
47 | * @package taoProctoring |
48 | * @license GPL-2.0 |
49 | * |
50 | */ |
51 | class Monitor extends SimplePageModule |
52 | { |
53 | use OntologyAwareTrait; |
54 | |
55 | public const ERROR_AUTHORIZE_EXECUTIONS = 1; |
56 | public const ERROR_PAUSE_EXECUTIONS = 2; |
57 | public const ERROR_TERMINATE_EXECUTIONS = 3; |
58 | public const ERROR_REPORT_IRREGULARITIES = 4; |
59 | public const ERROR_SET_EXTRA_TIME = 5; |
60 | public const ERROR_ADJUST_TIME = 6; |
61 | |
62 | /** |
63 | * Returns the currently proctored delivery |
64 | * |
65 | * @return \core_kernel_classes_Resource |
66 | */ |
67 | protected function getCurrentDelivery() |
68 | { |
69 | return $this->hasRequestParameter('delivery') |
70 | ? $this->getResource($this->getRequestParameter('delivery')) |
71 | : null; |
72 | } |
73 | |
74 | /** |
75 | * Gets the view parameters and data to display |
76 | * @return array |
77 | * @throws common_exception_Error |
78 | */ |
79 | protected function getViewData() |
80 | { |
81 | $user = \common_session_SessionManager::getSession()->getUser(); |
82 | $hasAccessToReactivate = AclProxy::hasAccess( |
83 | $user, |
84 | MonitorProctorAdministrator::class, |
85 | 'reactivateExecutions', |
86 | [] |
87 | ); |
88 | $delivery = $this->getCurrentDelivery(); |
89 | /** @var GuiSettingsService $guiSettingsService */ |
90 | $guiSettingsService = $this->getServiceLocator()->get(GuiSettingsService::SERVICE_ID); |
91 | $assessmentResultsService = $this->getServiceLocator()->get(AssessmentResultsService::SERVICE_ID); |
92 | $data = [ |
93 | 'ismanageable' => false, |
94 | 'set' => [], |
95 | 'extrafields' => DeliveryHelper::getExtraFields(), |
96 | 'categories' => DeliveryHelper::getAllReasonsCategories($hasAccessToReactivate), |
97 | 'printReportButton' => $assessmentResultsService->getOption( |
98 | AssessmentResultsService::OPTION_PRINT_REPORT_BUTTON |
99 | ), |
100 | 'printReportUrl' => $assessmentResultsService->getScoreReportUrlParts(), |
101 | 'timeHandling' => $this->getServiceLocator() |
102 | ->get(DeliveryExecutionStateService::SERVICE_ID) |
103 | ->getOption(DeliveryExecutionStateService::OPTION_TIME_HANDLING), |
104 | 'historyUrl' => $this |
105 | ->getServiceLocator() |
106 | ->get(TestSessionHistoryService::SERVICE_ID) |
107 | ->getHistoryUrl($delivery), |
108 | 'onlineStatus' => $this |
109 | ->getServiceLocator() |
110 | ->get(TestSessionConnectivityStatusService::SERVICE_ID) |
111 | ->hasOnlineMode(), |
112 | 'hasAccessToReactivate' => $hasAccessToReactivate |
113 | ]; |
114 | |
115 | $data = array_merge($data, $guiSettingsService->asArray()); |
116 | |
117 | if (!is_null($delivery)) { |
118 | $data['delivery'] = $delivery->getUri(); |
119 | } |
120 | if ($this->hasRequestParameter('context')) { |
121 | $data['context'] = $this->getRequestParameter('context'); |
122 | } |
123 | |
124 | return $data; |
125 | } |
126 | |
127 | /** |
128 | * Monitoring view of a selected delivery |
129 | */ |
130 | public function index() |
131 | { |
132 | $this->setData( |
133 | 'homeUrl', |
134 | $this->getServiceManager()->get(DefaultUrlService::SERVICE_ID)->getUrl('ProctoringHome') |
135 | ); |
136 | $this->setData( |
137 | 'logout', |
138 | $this->getServiceManager()->get(DefaultUrlService::SERVICE_ID)->getUrl('ProctoringLogout') |
139 | ); |
140 | $this->composeView('delivery-monitoring', null, 'pages/index.tpl', 'tao'); |
141 | } |
142 | |
143 | /** |
144 | * Lists all available deliveries |
145 | */ |
146 | public function monitor() |
147 | { |
148 | $this->returnJson([ |
149 | 'success' => true, |
150 | 'data' => $this->getViewData(), |
151 | ]); |
152 | } |
153 | |
154 | /** |
155 | * Gets the list of current executions for a delivery |
156 | * |
157 | * @throws common_Exception |
158 | */ |
159 | public function deliveryExecutions() |
160 | { |
161 | $dataTable = new DeliveriesMonitorDatatable($this->getCurrentDelivery(), $this->getRequest()); |
162 | $this->getServiceManager()->propagate($dataTable); |
163 | $this->returnJson($dataTable); |
164 | } |
165 | |
166 | /** |
167 | * Authorises a delivery execution |
168 | * |
169 | * @throws common_Exception |
170 | * @throws \oat\oatbox\service\ServiceNotFoundException |
171 | */ |
172 | public function authoriseExecutions() |
173 | { |
174 | $deliveryExecution = $this->getRequestParameter('execution'); |
175 | $reason = $this->getRequestParameter('reason'); |
176 | $testCenter = $this->getRequestParameter('testCenter'); |
177 | |
178 | if (!is_array($deliveryExecution)) { |
179 | $deliveryExecution = array($deliveryExecution); |
180 | } |
181 | |
182 | try { |
183 | $data = DeliveryHelper::authoriseExecutions($deliveryExecution, $reason, $testCenter); |
184 | |
185 | $response = [ |
186 | 'success' => !count($data['unprocessed']), |
187 | 'data' => $data |
188 | ]; |
189 | |
190 | if (!$response['success']) { |
191 | $response['errorCode'] = self::ERROR_AUTHORIZE_EXECUTIONS; |
192 | $response['errorMsg'] = __('Some delivery executions have not been authorized'); |
193 | } |
194 | |
195 | $this->returnJson($response); |
196 | } catch (QtiTestExtractionFailedException $e) { |
197 | $response = [ |
198 | 'success' => false, |
199 | 'data' => [], |
200 | 'errorCode' => self::ERROR_AUTHORIZE_EXECUTIONS, |
201 | 'errorMsg' => __('Decryption failed because of using the wrong customer app key.'), |
202 | ]; |
203 | |
204 | $this->returnJson($response); |
205 | } catch (ServiceNotFoundException $e) { |
206 | \common_Logger::w('No delivery service defined for proctoring'); |
207 | $this->returnError('Proctoring interface not available'); |
208 | } |
209 | } |
210 | |
211 | |
212 | /** |
213 | * Terminates delivery executions |
214 | * |
215 | * @throws common_Exception |
216 | * @throws \oat\oatbox\service\ServiceNotFoundException |
217 | */ |
218 | public function terminateExecutions() |
219 | { |
220 | $deliveryExecution = $this->getRequestParameter('execution'); |
221 | $reason = $this->getRequestParameter('reason'); |
222 | |
223 | if (!is_array($deliveryExecution)) { |
224 | $deliveryExecution = array($deliveryExecution); |
225 | } |
226 | |
227 | try { |
228 | $data = DeliveryHelper::terminateExecutions($deliveryExecution, $reason); |
229 | |
230 | $response = [ |
231 | 'success' => !count($data['unprocessed']), |
232 | 'data' => $data |
233 | ]; |
234 | |
235 | if (!$response['success']) { |
236 | $response['errorCode'] = self::ERROR_TERMINATE_EXECUTIONS; |
237 | $response['errorMsg'] = __('Some delivery executions have not been terminated'); |
238 | } |
239 | |
240 | $this->returnJson($response); |
241 | } catch (ServiceNotFoundException $e) { |
242 | \common_Logger::w('No delivery service defined for proctoring'); |
243 | $this->returnError('Proctoring interface not available'); |
244 | } |
245 | } |
246 | |
247 | /** |
248 | * Pauses delivery executions |
249 | * |
250 | * @throws common_Exception |
251 | * @throws \oat\oatbox\service\ServiceNotFoundException |
252 | */ |
253 | public function pauseExecutions() |
254 | { |
255 | $deliveryExecution = $this->getRequestParameter('execution'); |
256 | $reason = $this->getRequestParameter('reason'); |
257 | |
258 | if (!is_array($deliveryExecution)) { |
259 | $deliveryExecution = array($deliveryExecution); |
260 | } |
261 | |
262 | try { |
263 | $data = DeliveryHelper::pauseExecutions($deliveryExecution, $reason); |
264 | |
265 | $response = [ |
266 | 'success' => !count($data['unprocessed']), |
267 | 'data' => $data |
268 | ]; |
269 | |
270 | if (!$response['success']) { |
271 | $response['errorCode'] = self::ERROR_PAUSE_EXECUTIONS; |
272 | $response['errorMsg'] = __('Some delivery executions have not been paused'); |
273 | } |
274 | |
275 | $this->returnJson($response); |
276 | } catch (ServiceNotFoundException $e) { |
277 | \common_Logger::w('No delivery service defined for proctoring'); |
278 | $this->returnError('Proctoring interface not available'); |
279 | } |
280 | } |
281 | |
282 | /** |
283 | * Report irregularities in delivery executions |
284 | * |
285 | * @throws common_Exception |
286 | * @throws \oat\oatbox\service\ServiceNotFoundException |
287 | */ |
288 | public function reportExecutions() |
289 | { |
290 | $deliveryExecution = $this->getRequestParameter('execution'); |
291 | $reason = $this->getRequestParameter('reason'); |
292 | |
293 | if (!is_array($deliveryExecution)) { |
294 | $deliveryExecution = array($deliveryExecution); |
295 | } |
296 | |
297 | try { |
298 | $data = DeliveryHelper::reportExecutions($deliveryExecution, $reason); |
299 | |
300 | $response = [ |
301 | 'success' => !count($data['unprocessed']), |
302 | 'data' => $data |
303 | ]; |
304 | |
305 | if (!$response['success']) { |
306 | $response['errorCode'] = self::ERROR_REPORT_IRREGULARITIES; |
307 | $response['errorMsg'] = __('Some delivery executions have not been reported'); |
308 | } |
309 | |
310 | $this->returnJson($response); |
311 | } catch (ServiceNotFoundException $e) { |
312 | \common_Logger::w('No delivery service defined for proctoring'); |
313 | $this->returnError('Proctoring interface not available'); |
314 | } |
315 | } |
316 | |
317 | /** |
318 | * Extra Time handling: add or remove time on delivery executions |
319 | * |
320 | * @throws common_Exception |
321 | */ |
322 | public function extraTime() |
323 | { |
324 | $deliveryExecution = $this->getRequestParameter('execution'); |
325 | $extraTime = floatval($this->getRequestParameter('time')); |
326 | |
327 | if (!is_array($deliveryExecution)) { |
328 | $deliveryExecution = array($deliveryExecution); |
329 | } |
330 | |
331 | try { |
332 | /** @var DeliveryExecutionManagerService $deliveryExecutionManagerService */ |
333 | $deliveryExecutionManagerService = $this->getServiceLocator()->get( |
334 | DeliveryExecutionManagerService::SERVICE_ID |
335 | ); |
336 | $data = $deliveryExecutionManagerService->setExtraTime($deliveryExecution, $extraTime); |
337 | |
338 | $response = [ |
339 | 'success' => !count($data['unprocessed']), |
340 | 'data' => $data |
341 | ]; |
342 | |
343 | if (!$response['success']) { |
344 | $response['errorCode'] = self::ERROR_SET_EXTRA_TIME; |
345 | $response['errorMsg'] = __('Some delivery executions have not been updated'); |
346 | } |
347 | |
348 | $this->returnJson($response); |
349 | } catch (ServiceNotFoundException $e) { |
350 | \common_Logger::w('No delivery service defined for proctoring'); |
351 | $this->returnError('Proctoring interface not available'); |
352 | } |
353 | } |
354 | |
355 | /** |
356 | * @throws QtiTestExtractionFailedException |
357 | * @throws common_Exception |
358 | * @throws common_exception_Error |
359 | * @throws common_exception_NotFound |
360 | * @throws common_ext_ExtensionException |
361 | * @throws InvalidServiceManagerException |
362 | */ |
363 | public function adjustTime(): void |
364 | { |
365 | $deliveryExecutions = $this->getPostParameter('execution'); |
366 | $seconds = $this->getPostParameter('time'); |
367 | $reason = [ |
368 | 'reasons' => $this->getPostParameter('reasons', []), |
369 | 'comment' => $this->getPostParameter('comment', ''), |
370 | ]; |
371 | |
372 | if (!is_array($deliveryExecutions)) { |
373 | $deliveryExecutions = [$deliveryExecutions]; |
374 | } |
375 | |
376 | /** @var DeliveryExecutionManagerService $deliveryExecutionManagerService */ |
377 | $deliveryExecutionManagerService = $this->getServiceLocator()->get(DeliveryExecutionManagerService::SERVICE_ID); |
378 | $data = $deliveryExecutionManagerService->adjustTimers($deliveryExecutions, $seconds, $reason); |
379 | |
380 | $response = [ |
381 | 'success' => !count($data['unprocessed']), |
382 | 'data' => $data |
383 | ]; |
384 | |
385 | if (!$response['success']) { |
386 | $response['errorCode'] = self::ERROR_ADJUST_TIME; |
387 | $response['errorMsg'] = __('Some delivery executions have not been updated'); |
388 | } |
389 | |
390 | $this->returnJson($response); |
391 | } |
392 | } |