Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ProctoredSectionPauseService | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
| couldBePaused | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| isPausable | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| canMoveBackward | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| isProctored | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| isItemPausable | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 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 | * @author Alexander Zagovorychev <zagovorichev@1pt.com> |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoProctoring\model\execution; |
| 24 | |
| 25 | use oat\generis\model\OntologyAwareTrait; |
| 26 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 27 | use oat\taoProctoring\model\authorization\TestTakerAuthorizationService; |
| 28 | use oat\taoQtiTest\models\SectionPauseService; |
| 29 | use oat\taoQtiTest\models\runner\session\TestSession; |
| 30 | use qtism\data\AssessmentItemRef; |
| 31 | use qtism\runtime\tests\AssessmentTestSessionState; |
| 32 | |
| 33 | class ProctoredSectionPauseService extends SectionPauseService |
| 34 | { |
| 35 | use OntologyAwareTrait; |
| 36 | |
| 37 | /** |
| 38 | * This category triggers the section pause |
| 39 | */ |
| 40 | public const PAUSE_CATEGORY = 'x-tao-proctored-auto-pause'; |
| 41 | |
| 42 | private $isProctored = null; |
| 43 | |
| 44 | /** |
| 45 | * Checked the given session could be paused at some point |
| 46 | * (in other words : is section pause enabled) |
| 47 | * @param $session |
| 48 | * @return bool |
| 49 | */ |
| 50 | public function couldBePaused(TestSession $session = null) |
| 51 | { |
| 52 | return ($session->getState() === AssessmentTestSessionState::INTERACTING && $this->isProctored($session)); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Checked that section can be paused |
| 57 | * @param TestSession $session |
| 58 | * @return bool |
| 59 | */ |
| 60 | public function isPausable(TestSession $session = null) |
| 61 | { |
| 62 | if ($this->couldBePaused($session)) { |
| 63 | |
| 64 | /** @var AssessmentItemRef $itemRef */ |
| 65 | $itemRef = $session->getCurrentAssessmentItemRef(); |
| 66 | |
| 67 | return $this->isItemPausable($itemRef); |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Check if we can move backward : when leaving a pausable section, |
| 74 | * we can't move backward. |
| 75 | * |
| 76 | * @param TestSession $session |
| 77 | * @return bool |
| 78 | */ |
| 79 | public function canMoveBackward(TestSession $session = null) |
| 80 | { |
| 81 | if ($this->couldBePaused($session)) { |
| 82 | return ! $this->isItemPausable($session->getCurrentAssessmentItemRef()); |
| 83 | } |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Is the given section proctored |
| 89 | * |
| 90 | * @param TestSession $session |
| 91 | * @return bool false by default |
| 92 | */ |
| 93 | private function isProctored(TestSession $session) |
| 94 | { |
| 95 | //check only once |
| 96 | if (is_null($this->isProctored)) { |
| 97 | $this->isProctored = false; |
| 98 | |
| 99 | if (!is_null($session)) { |
| 100 | $user = \common_session_SessionManager::getSession()->getUser(); |
| 101 | $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($session->getSessionId()); |
| 102 | $this->isProctored = $this |
| 103 | ->getServiceManager() |
| 104 | ->get(TestTakerAuthorizationService::SERVICE_ID) |
| 105 | ->isProctored($deliveryExecution->getDelivery(), $user); |
| 106 | } |
| 107 | } |
| 108 | return $this->isProctored; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | /** |
| 113 | * Is the given itemRef pauseable (ie. has the given category) |
| 114 | * |
| 115 | * @param AssessmentItemRef $itemRef |
| 116 | * @return bool false by default |
| 117 | */ |
| 118 | private function isItemPausable(AssessmentItemRef $itemRef) |
| 119 | { |
| 120 | if (!is_null($itemRef)) { |
| 121 | return $itemRef->getCategories()->contains(self::PAUSE_CATEGORY); |
| 122 | } |
| 123 | return false; |
| 124 | } |
| 125 | } |