Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| DiagnosticChecker | |
0.00% |
0 / 30 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 1 |
| getData | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| getParameters | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| workstation | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| getDiagnosticDataTable | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| loadConfig | |
0.00% |
0 / 3 |
|
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-2023 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoClientDiagnostic\controller; |
| 22 | |
| 23 | use common_exception_MissingParameter; |
| 24 | use oat\tao\helpers\UserHelper; |
| 25 | use oat\taoClientDiagnostic\model\diagnostic\DiagnosticDataTable; |
| 26 | use oat\taoClientDiagnostic\model\storage\PaginatedSqlStorage; |
| 27 | use tao_helpers_Display; |
| 28 | |
| 29 | /** |
| 30 | * Class DiagnosticChecker |
| 31 | * |
| 32 | * @package oat\taoClientDiagnostic\controller |
| 33 | */ |
| 34 | class DiagnosticChecker extends CompatibilityChecker |
| 35 | { |
| 36 | /** |
| 37 | * @var DiagnosticDataTable |
| 38 | */ |
| 39 | protected $dataTable; |
| 40 | |
| 41 | /** |
| 42 | * Fetch POST data |
| 43 | * Get login by cookie |
| 44 | * If check parameters is true, check mandatory parameters |
| 45 | * |
| 46 | * @param bool $check |
| 47 | * @return array |
| 48 | * @throws common_exception_MissingParameter |
| 49 | */ |
| 50 | protected function getData($check = false) |
| 51 | { |
| 52 | $data = parent::getData($check); |
| 53 | $data['login'] = UserHelper::getUserLogin(\common_session_SessionManager::getSession()->getUser()); |
| 54 | |
| 55 | if ($this->hasRequestParameter('workstation')) { |
| 56 | $data[PaginatedSqlStorage::DIAGNOSTIC_WORKSTATION] = tao_helpers_Display::sanitizeXssHtml( |
| 57 | trim($this->getRequestParameter('workstation')) |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | return $data; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get current http parameters |
| 66 | * Unset workstation parameters to avoid cast it as type |
| 67 | * |
| 68 | * @return array |
| 69 | */ |
| 70 | protected function getParameters() |
| 71 | { |
| 72 | $data = parent::getParameters(); |
| 73 | if (isset($data['workstation'])) { |
| 74 | unset($data['workstation']); |
| 75 | } |
| 76 | return $data; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Gets the name of the workstation being tested |
| 81 | * If current id is found on database, associated workstation is retrieve |
| 82 | * Else an uniqid is generated |
| 83 | */ |
| 84 | public function workstation() |
| 85 | { |
| 86 | $response = [ |
| 87 | 'success' => false, |
| 88 | 'workstation' => uniqid('workstation-') |
| 89 | ]; |
| 90 | |
| 91 | $diagnostic = $this->getDiagnosticDataTable()->getDiagnostic($this->getId()); |
| 92 | |
| 93 | if (isset($diagnostic)) { |
| 94 | $response['success'] = true; |
| 95 | $workstation = trim($diagnostic[PaginatedSqlStorage::DIAGNOSTIC_WORKSTATION]); |
| 96 | if ($workstation) { |
| 97 | $response['workstation'] = $workstation; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | $this->returnJson($response); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Get the model to access diagnostic storage through dataTable |
| 106 | * |
| 107 | * @return DiagnosticDataTable |
| 108 | */ |
| 109 | protected function getDiagnosticDataTable() |
| 110 | { |
| 111 | if (! $this->dataTable) { |
| 112 | $diagnosticDatatable = new DiagnosticDataTable(); |
| 113 | $diagnosticDatatable->setServiceLocator($this->getServiceManager()); |
| 114 | $this->dataTable = $diagnosticDatatable; |
| 115 | } |
| 116 | return $this->dataTable; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Get config parameters for compatibility check |
| 121 | * |
| 122 | * @return mixed |
| 123 | * @throws \common_ext_ExtensionException |
| 124 | */ |
| 125 | protected function loadConfig() |
| 126 | { |
| 127 | $config = parent::loadConfig(); |
| 128 | $config['controller'] = 'DiagnosticChecker'; |
| 129 | return $config; |
| 130 | } |
| 131 | } |