Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TestSessionConnectivityStatusService | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| isOnline | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| getLastOnline | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| hasOnlineMode | |
0.00% |
0 / 1 |
|
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) 2016 (original work) Open Assessment Technologies SA ; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoProctoring\model\implementation; |
| 22 | |
| 23 | use oat\oatbox\service\ConfigurableService; |
| 24 | use oat\taoDelivery\model\execution\DeliveryExecution; |
| 25 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 26 | use oat\taoProctoring\model\TestSessionConnectivityStatusService as TestSessionConnectivityStatusServiceInterface; |
| 27 | |
| 28 | /** |
| 29 | * Service to check whether test session is online. |
| 30 | * |
| 31 | * @author Aleh Hutnikau <hutnikau@1pt.com> |
| 32 | * @package oat\taoProctoring |
| 33 | */ |
| 34 | class TestSessionConnectivityStatusService extends ConfigurableService implements |
| 35 | TestSessionConnectivityStatusServiceInterface |
| 36 | { |
| 37 | public const HAS_ONLINE_MODE = 'onlineMode'; |
| 38 | |
| 39 | /** |
| 40 | * Whether test session is online |
| 41 | * @param string $sessionId test session identifier |
| 42 | * @return bool |
| 43 | */ |
| 44 | public function isOnline($sessionId) |
| 45 | { |
| 46 | if (!$this->hasOnlineMode()) { |
| 47 | \common_Logger::w( |
| 48 | 'Using of ' |
| 49 | . '`oat\taoProctoring\model\implementation\TestSessionConnectivityStatusService::isOnline()` ' |
| 50 | . 'method which may give inaccurate result.' |
| 51 | ); |
| 52 | } |
| 53 | $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($sessionId); |
| 54 | return $deliveryExecution->getState()->getUri() === DeliveryExecution::STATE_ACTIVE; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @param $sessionId |
| 59 | * @return int|null |
| 60 | */ |
| 61 | public function getLastOnline($sessionId) |
| 62 | { |
| 63 | if ($this->isOnline($sessionId)) { |
| 64 | return microtime(true); |
| 65 | } |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | public function hasOnlineMode() |
| 70 | { |
| 71 | return ($this->hasOption(self::HAS_ONLINE_MODE)) ? $this->getOption(self::HAS_ONLINE_MODE) : false; |
| 72 | } |
| 73 | } |