Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 121
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Reporting
0.00% covered (danger)
0.00%
0 / 121
0.00% covered (danger)
0.00%
0 / 6
756
0.00% covered (danger)
0.00%
0 / 1
 getViewData
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
110
 index
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 sessionHistory
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 history
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
20
 printReport
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
42
 printRubric
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
30
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
22namespace oat\taoProctoring\controller;
23
24use oat\generis\model\OntologyAwareTrait;
25use oat\oatbox\service\ServiceManager;
26use oat\oatbox\service\ServiceNotFoundException;
27use oat\taoDelivery\model\execution\ServiceProxy;
28use oat\taoProctoring\helpers\DataTableHelper;
29use oat\taoProctoring\model\AssessmentResultsService;
30use oat\taoProctoring\model\deliveryLog\DeliveryLog;
31use oat\taoProctoring\model\ProctorService;
32use oat\taoProctoring\model\TestSessionHistoryService;
33
34/**
35 * Proctoring Reporting controllers for the assessment activity reporting screen.
36 *
37 * @author Open Assessment Technologies SA
38 * @package taoProctoring
39 * @license GPL-2.0
40 *
41 */
42class Reporting extends SimplePageModule
43{
44    use OntologyAwareTrait;
45
46    /**
47     * Gets the view parameters and data to display
48     * @return array
49     */
50    protected function getViewData()
51    {
52        $delivery       = $this->hasRequestParameter('delivery')
53            ? $this->getResource($this->getRequestParameter('delivery'))
54            : null;
55        $testCenter     = $this->hasRequestParameter('context')
56            ? $this->getResource($this->getRequestParameter('context'))
57            : null;
58        $sessions       = $this->getRequestParameter('session');
59        $requestOptions = $this->getRequestOptions([
60            'sortby'      => 'timestamp',
61            'sortorder'   => 'desc',
62            'periodStart' => '',
63            'periodEnd' => '',
64            'detailed' => false
65        ]);
66
67        if (!is_array($sessions)) {
68            $sessions = $sessions ? explode(',', $sessions) : [];
69        }
70
71        // log access to history
72        $deliveryLog = $this->getServiceManager()->get(DeliveryLog::SERVICE_ID);
73        foreach ($sessions as $sessionUri) {
74            $deliveryLog->log($sessionUri, 'HISTORY', []);
75        }
76
77        // retrieve history
78        $historyService = $this->getServiceManager()->get(TestSessionHistoryService::SERVICE_ID);
79        $history = DataTableHelper::paginate(
80            $historyService->getSessionsHistory($sessions, $requestOptions),
81            $requestOptions
82        );
83
84        $viewData = [
85            'set'         => $history,
86            'sessions'    => $sessions,
87            'sortBy'      => $requestOptions['sortBy'],
88            'sortOrder'   => $requestOptions['sortOrder'],
89            'periodStart' => $requestOptions['periodStart'],
90            'periodEnd'   => $requestOptions['periodEnd'],
91            'monitoringUrl' => $historyService->getBackUrl($delivery),
92        ];
93
94        if ($testCenter) {
95            $viewData['monitoringUrl'] .= (strpos($viewData['monitoringUrl'], '?') === false) ? '?' : '&';
96            $viewData['monitoringUrl'] .= 'context=' . urlencode($testCenter->getUri());
97            $viewData['context'] = $testCenter->getUri();
98        }
99
100        if ($delivery) {
101            $viewData['delivery'] = $delivery->getUri();
102        }
103
104        if (count($sessions) > 1) {
105            $viewData['title'] = __('Detailed Session History of a selection');
106        } else {
107            $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($sessions[0]);
108            $viewData['title'] = __('Detailed Session History of %s', $deliveryExecution->getLabel());
109        }
110
111        return $viewData;
112    }
113
114    /**
115     * Display the session history of the current test center
116     */
117    public function index()
118    {
119        $this->composeView('session-history', null, 'pages/index.tpl', 'tao');
120    }
121
122    /**
123     * Display the session history of the current test center
124     */
125    public function sessionHistory()
126    {
127        $this->returnJson([
128            'success' => true,
129            'data' => $this->getViewData(),
130        ]);
131    }
132
133    /**
134     * Display the activity reporting of the current test center
135     */
136    public function history()
137    {
138        try {
139            $sessions = $this->getRequestParameter('session');
140            $requestOptions = $this->getRequestOptions([
141                'sortby' => 'timestamp',
142                'sortorder' => 'desc',
143                'periodStart' => '',
144                'periodEnd' => '',
145            ]);
146
147            if (!is_array($sessions)) {
148                $sessions = $sessions ? explode(',', $sessions) : [];
149            }
150            $historyService = $this->getServiceManager()->get(TestSessionHistoryService::SERVICE_ID);
151            $this->returnJson(
152                DataTableHelper::paginate(
153                    $historyService->getSessionsHistory($sessions, $requestOptions),
154                    $requestOptions
155                )
156            );
157        } catch (ServiceNotFoundException $e) {
158            \common_Logger::w('No history service defined for proctoring');
159            $this->returnError('Proctoring interface not available');
160        }
161    }
162
163    /**
164     * Render page with assessment(s) result.
165     * @throws \common_exception_Error
166     * @throws \common_exception_MissingParameter
167     * @throws \oat\oatbox\service\ServiceNotFoundException
168     */
169    public function printReport()
170    {
171        if (!$this->hasRequestParameter('id')) {
172            throw new \common_exception_MissingParameter('id');
173        }
174        $idList = $this->getRequestParameter('id');
175        $context = $this->getRequestParameter('context');
176        if (!is_array($idList)) {
177            $idList = [$idList];
178        }
179        $result = [];
180
181        /** @var ProctorService $deliveryService */
182        $deliveryService = ServiceManager::getServiceManager()->get(ProctorService::SERVICE_ID);
183        $currentUser = \common_session_SessionManager::getSession()->getUser();
184        $deliveries = $deliveryService->getProctorableDeliveries($currentUser, $context);
185
186        /** @var $assessmentResultsService AssessmentResultsService */
187        $assessmentResultsService = $this->getServiceManager()->get(AssessmentResultsService::SERVICE_ID);
188
189        foreach ($idList as $deliveryExecutionId) {
190            $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($deliveryExecutionId);
191            $delivery = $deliveryExecution->getDelivery();
192            if (!isset($deliveries[$delivery->getUri()])) {
193                \common_Logger::i(
194                    'Attempt to print assessment results for which the proctor '
195                        . $currentUser->getIdentifier() . ' has no access.'
196                );
197
198                continue;
199            }
200            $deliveryData = $assessmentResultsService->getDeliveryData($deliveryExecution);
201            if (!$deliveryData['end']) {
202                continue;
203            }
204            $result[] = [
205                'testTakerData' => $assessmentResultsService->getTestTakerData($deliveryExecution),
206                'testData' => $assessmentResultsService->getTestData($deliveryExecution),
207                'resultsData' => $assessmentResultsService->getResultsData($deliveryExecution),
208                'deliveryData' => $deliveryData,
209            ];
210        }
211
212        $this->setData('reports', $result);
213        $this->setData('content-template', 'Reporting/print_report.tpl');
214        $this->setView('Reporting/layout.tpl');
215    }
216
217    /**
218     * Render printable rubrics
219     *
220     * @throws \common_exception_Error
221     * @throws \common_exception_MissingParameter
222     * @throws \oat\oatbox\service\ServiceNotFoundException
223     */
224    public function printRubric()
225    {
226        if (!$this->hasRequestParameter('id')) {
227            throw new \common_exception_MissingParameter('id');
228        }
229        $idList = $this->getRequestParameter('id');
230        if (!is_array($idList)) {
231            $idList = [$idList];
232        }
233        $result = [];
234
235        /** @var $assessmentResultsService AssessmentResultsService */
236        $assessmentResultsService = $this->getServiceManager()->get(AssessmentResultsService::SERVICE_ID);
237
238        foreach ($idList as $deliveryExecutionId) {
239            $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($deliveryExecutionId);
240            $deliveryData = $assessmentResultsService->getDeliveryData($deliveryExecution);
241
242            if (!$deliveryData['end']) {
243                continue;
244            }
245            $result[] = [
246                'testData' => $assessmentResultsService->getTestData($deliveryExecution),
247                'rubricContent' => $assessmentResultsService->getPrintableRubric($deliveryExecution),
248                'testTakerData' => $assessmentResultsService->getTestTakerData($deliveryExecution),
249                'deliveryData' => $deliveryData,
250            ];
251        }
252
253        $this->setData('rubrics', $result);
254        $this->setData('content-template', 'Reporting/print_rubric.tpl');
255        $this->setView('Reporting/layout.tpl');
256    }
257}