Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
QtiRunnerMessageService
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 5
110
0.00% covered (danger)
0.00%
0 / 1
 getStateMessage
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
42
 getPausedStateMessage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTerminatedStateMessage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInitialStateMessage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRunningStateMessages
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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) 2017 (original work) Open Assessment Technologies SA ;
19 *
20 */
21
22/**
23 * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com>
24 */
25
26namespace oat\taoQtiTest\models\runner;
27
28use oat\oatbox\service\ConfigurableService;
29use qtism\runtime\tests\AssessmentTestSession;
30use qtism\runtime\tests\AssessmentTestSessionState;
31
32/**
33 * Class QtiRunnerMessageService
34 *
35 * Defines a service that will provide messages for the test runner
36 *
37 * @package oat\taoQtiTest\models
38 */
39class QtiRunnerMessageService extends ConfigurableService implements RunnerMessageService
40{
41    public const SERVICE_ID = 'taoQtiTest/QtiRunnerMessageService';
42
43    /**
44     * Gets a message related to the state of the assessment test session
45     * @param mixed $testSession
46     * @return string
47     * @throws \common_exception_InvalidArgumentType
48     */
49    public function getStateMessage($testSession)
50    {
51        if ($testSession instanceof AssessmentTestSession) {
52            switch ($testSession->getState()) {
53                case AssessmentTestSessionState::SUSPENDED:
54                    return $this->getPausedStateMessage($testSession);
55
56                case AssessmentTestSessionState::CLOSED:
57                    return $this->getTerminatedStateMessage($testSession);
58
59                case AssessmentTestSessionState::INITIAL:
60                    return $this->getInitialStateMessage($testSession);
61
62                default:
63                    return $this->getRunningStateMessages($testSession);
64            }
65        } else {
66            throw new \common_exception_InvalidArgumentType(
67                'QtiRunnerMessageService',
68                'getStateMessage',
69                0,
70                'qtism\runtime\tests\AssessmentTestSession',
71                $testSession
72            );
73        }
74    }
75
76    /**
77     * Gets a message about the paused status of the assessment
78     * @param AssessmentTestSession $testSession
79     * @return string
80     */
81    protected function getPausedStateMessage(AssessmentTestSession $testSession)
82    {
83        return __('The assessment has been suspended. To resume your assessment, please relaunch it.');
84    }
85
86    /**
87     * Gets a message about the terminated status of the assessment
88     * @param AssessmentTestSession $testSession
89     * @return string
90     */
91    protected function getTerminatedStateMessage(AssessmentTestSession $testSession)
92    {
93        return __('The assessment has been terminated. You cannot interact with it anymore.');
94    }
95
96    /**
97     * Gets a message about the initial status of the assessment
98     * @param AssessmentTestSession $testSession
99     * @return string
100     */
101    protected function getInitialStateMessage(AssessmentTestSession $testSession)
102    {
103        return __('The assessment has been created but is not already running.');
104    }
105
106    /**
107     * Gets a message about the running status of the assessment
108     * @param AssessmentTestSession $testSession
109     * @return string
110     */
111    protected function getRunningStateMessages(AssessmentTestSession $testSession)
112    {
113        return __('The assessment is still running.');
114    }
115}